Pycharm Anaconda导入张量流库问题 [英] Pycharm anaconda import tensor flow library issue

查看:128
本文介绍了Pycharm Anaconda导入张量流库问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下程序在命令行界面的anaconda下运行良好(我使用的是Mac OS),但存在无法从PyCharm导入/查找tensorflow模块(使用Python 2.7)的错误.我已经在PyCharm中将Python解释器设置为anaconda,仍然收到此错误.如果有人有什么想法,那就太好了.

The following program works well under anaconda from command line interface (I am using Mac OS), but it has errors about cannot import/find tensorflow module from PyCharm (using Python 2.7). I already set Python interpreter to be anaconda in PyCharm, still got this error. If anyone have any ideas, it will be great.

这是我正在使用的简单程序,也是PyCharm的屏幕快照.

Here is the simple program I am using and also the screen snapshot of PyCharm.

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
a = tf.constant(10)
b = tf.constant(32)
print(sess.run(a + b))

更新1 ,如何在PyCharm中设置Python解释器,

Update 1, how I setup Python interpreter in PyCharm,

更新2 ,发布python -c 'import sys; print(sys.path)'

['','/Users/admin/miniconda2/lib/python2.7/site-packages/six-1.10.0-py2.7.egg','/Users/admin/miniconda2/lib/python27. zip','/Users/admin/miniconda2/lib/python2.7','/Users/admin/miniconda2/lib/python2.7/plat-darwin','/Users/admin/miniconda2/lib/python2.7/plat-mac'、'/Users/admin/miniconda2/lib/python2.7/plat-mac/lib-scriptpackages'、'/Users/admin/miniconda2/lib/python2.7/lib-tk'、'/Users/admin/miniconda2/lib/python2.7/lib-old','/Users/admin/miniconda2/lib/python2.7/lib-dynload','/Users/admin/miniconda2/lib/python2.7/网站包"]

['', '/Users/admin/miniconda2/lib/python2.7/site-packages/six-1.10.0-py2.7.egg', '/Users/admin/miniconda2/lib/python27.zip', '/Users/admin/miniconda2/lib/python2.7', '/Users/admin/miniconda2/lib/python2.7/plat-darwin', '/Users/admin/miniconda2/lib/python2.7/plat-mac', '/Users/admin/miniconda2/lib/python2.7/plat-mac/lib-scriptpackages', '/Users/admin/miniconda2/lib/python2.7/lib-tk', '/Users/admin/miniconda2/lib/python2.7/lib-old', '/Users/admin/miniconda2/lib/python2.7/lib-dynload', '/Users/admin/miniconda2/lib/python2.7/site-packages']

更新3

发布文件菜单和PyCharm版本,

Post File menu and PyCharm version,

更新4 ,首选项=>项目解释器设置,

Update 4, Preferences => Project Interpreter setting,

更新5 ,软件包列表屏幕快照

Update 5, package list screen snapshot,

更新6 ,使用conda以外的miniconda似乎没有问题,发布了屏幕快照,

Update 6, using miniconda other than conda seems no issues, post screen snapshots,

推荐答案

Preferences => Project Interpreter设置下,tensorflow是否在软件包中列出?

Under Preferences => Project Interpreter setting, is tensorflow listed among the packages?

显然没有(来自您的屏幕截图).

Apparently No (from your screenshots).

当您使用项目解释器上的下拉菜单时,是否还有其他的python conda安装?如果有,请尝试这些,然后看看会发生什么. tensorflow软件包肯定在另一个conda安装中.

Are there any other python conda installations when you use the drop down on project interpreter? If there are, try those and see what happens. The tensorflow package is definitely in another conda installation.

摘自SO上的帖子:

conda是程序包管理器.水蟒是一套约一百 软件包,包括conda,numpy,scipy,ipython notebook等.

conda is the package manager. Anaconda is a set of about a hundred packages including conda, numpy, scipy, ipython notebook, and so on.

您安装了Miniconda,它是Anaconda的较小替代品 那只是conda及其依赖项(与Anaconda相对, 是conda和一堆其他软件包,例如numpy,scipy,ipython 笔记本等).拥有Miniconda之后,您就可以轻松安装 通过conda安装anaconda将Anaconda插入其中.

You installed Miniconda, which is a smaller alternative to Anaconda that is just conda and its dependencies (as opposed to Anaconda, which is conda and a bunch of other packages like numpy, scipy, ipython notebook, etc.). Once you have Miniconda, you can easily install Anaconda into it with conda install anaconda.

因此,conda是包装经理,Anaconda是包装的集合,而 mini conda(重点是我的)是Anaconda的轻巧替代品.

So conda is a package manager, Anaconda is a collection of packages and miniconda (emphasis mine) is a light weight alternative to Anaconda.

您应该设置 virtualenv ,以避免将来出现此类问题.

You should into setting up a virtualenv to avoid such problems in the future.

这篇关于Pycharm Anaconda导入张量流库问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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