迅速的操场错误:模块"Python"没有名为“导入"的成员 [英] swift playground error: module 'Python' has no member named 'import'

查看:56
本文介绍了迅速的操场错误:模块"Python"没有名为“导入"的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Swift的新手,正在研究它的数据科学功能.

I'm new to Swift and looking into it's data science capabilities.

我创建了一个简单的.playground文件,并决定从python导入numpy模块:

I've created a simple .playground file and decided to import a numpy module from python:

import Python
let np = Python.import("numpy")

但是,我不断收到以下错误消息:

However, I keep getting the following error:

Playground execution failed:

error: hellow_world.playground:5:10: error: module 'Python' has no member named 'import'

如果我在命令行中运行它,也会发生同样的情况.我的系统(OS X)中都安装了带有numpy的python 2和python 3.我在做什么错了?

The same happens if I run it in the command line. Both python 2 and python 3 with numpy are installed in my system (OS X). What am I doing wrong?

  • Mac OS X版本:10.13.6
  • 快速工具链版本:4.1.3

推荐答案

要检查的几件事.

  1. 大概您在这里使用的是最新下载链接中的swift/tensorflow工具链(并且您已经配置了Xcode来使用它). 查看Xcode的(首选项",组件">工具链",然后选择已安装的Swift for TensorFlow工具链.) https://github.com/tensorflow/swift/blob/master/Installation. md

  1. Presumably you're using the swift / tensorflow toolchain from latest download link here (and you've configured Xcode to use it. View Xcode’s (Preferences, Components > Toolchains, and select the installed Swift for TensorFlow toolchain.) https://github.com/tensorflow/swift/blob/master/Installation.md

确保将Xcode构建系统更改为旧版(文件">项目设置">构建系统").

Make sure you change the Xcode build system to legacy (File > Project Settings > Build System).

检查运行时搜索路径 /Library/Developer/Toolchains/swift-latest/usr/lib/swift/macosx

Check the runtime search path /Library/Developer/Toolchains/swift-latest/usr/lib/swift/macosx

更新: 看看XcodeGen可以自动创建具有相关设置的xcode项目,以便快速进行tensorflow. 我在这里制作了 project.yml 文件

UPDATE: Have a look at XcodeGen which can automagically create an xcode project with relevant settings for swift for tensorflow. I crafted a project.yml file here

请勿在链接的框架中包含libppython2.7.tbd. tensorflow将自动找到相关的python版本3或2.

DO NOT include libppython2.7.tbd in the linked frameworks. tensorflow will automagically find relevant python version 3 or 2.

这篇关于迅速的操场错误:模块"Python"没有名为“导入"的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆