问题描述
我相信我已经在我的Debian版本上安装了pygraphviz.如果我从命令行运行Python,则可以导入它:
I believe I have installed pygraphviz on my Debian build. I can import it if I run Python from the command line:
jon@debian:~/anaconda3/bin$ ipython
Python 3.5.1 |Continuum Analytics, Inc.| (default, Dec 7 2015, 11:17:45)
Type "copyright", "credits" or "license" for more information.
IPython 4.1.2 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import pygraphviz
In [2]:
但是,如果我在PyCharm中从Python控制台尝试相同的操作,则会收到此错误:
However, if I try the same from a Python console from within PyCharm, I get this error:
/home/jon/anaconda3/bin/python /home/jon/apps/pycharm-community-5.0.4/helpers/pydev/pydevconsole.py 59089 41751
Python 3.5.1 |Anaconda 2.5.0 (32-bit)| (default, Dec 7 2015, 11:17:45)
Type "copyright", "credits" or "license" for more information.
IPython 4.0.3 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
PyDev console: using IPython 4.0.3
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['/home/jon/PycharmProjects/StateMachine'])
Python 3.5.1 |Anaconda 2.5.0 (32-bit)| (default, Dec 7 2015, 11:17:45)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
In[2]: import pygraphviz
Traceback (most recent call last):
File "/home/jon/anaconda3/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 3066, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-99ed911275c0>", line 1, in <module>
import pygraphviz
File "/home/jon/apps/pycharm-community-5.0.4/helpers/pydev/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ImportError: No module named 'pygraphviz'
我注意到在第一个示例中,Python版本是
I notice that in the first example, the Python version is
Python 3.5.1 |Continuum Analytics, Inc.| (default, Dec 7 2015, 11:17:45)
而在第二个示例中,版本为:
whereas in the 2nd example the version is:
Python 3.5.1 |Anaconda 2.5.0 (32-bit)| (default, Dec 7 2015, 11:17:45)
第二个失败的例子似乎是32位的(请注意,为什么要安装32位版本?)
So the 2nd example, which fails, appears to be 32 bit (as a side note, why would it have installed a 32 bit version?)
我的/anaconda3/envs文件夹为空.
My /anaconda3/envs folder is empty.
据我所知,我在Conda中仅安装了一个Python环境.
As far as I know, I only have one Python environment installed in Conda.
所以我的问题是...为什么从PyCharm内部导入失败,为什么当我只安装一个版本时却似乎运行32位版本的Python?
So my question is... Why does the import fail from within PyCharm, and why does it appear to be running a 32 bit version of Python when I only have one version installed?
推荐答案
本指南应可帮助您配置所有内容,包括指向库的自定义路径.
This guide should help you configuring everything including custom paths to your libraries.
解释器还可以,它已经指向Anaconda的发行版.但是在默认项目"设置下,控制台有一个选项:构建,执行,部署"->控制台"->"Python控制台".看看在那里您可以摆弄些什么.如果您无法使其正常运行,则可以发布您的配置.
The interpreter is ok, it is already pointing to Anaconda's distribution. But under "Default Project" settings there is an option for the console: "Build, Execution,Deployment" -> "Console" -> "Python Console". See what you can fiddle with there. If you can't make it work maybe post your config.
此外,您应该在虚拟环境中工作.有关更多信息,请参见本文.
Also, you should be working with virtual environments. See this article for more info.
这篇关于PyCharm的PygraphViz导入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!