问题
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]:
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'
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)
So the 2nd example, which fails, appears to be 32 bit (as a side note, why would it have installed a 32 bit version?)
My /anaconda3/envs folder is empty.
As far as I know, I only have one Python environment installed in Conda.
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?
回答1:
This guide should help you configuring everything including custom paths to your libraries.
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.
回答2:
Just in case someone else comes across a similar problem like I did... I had to install pygraphviz from the bin directory of the virtual environment, specifying the pip3 file I wanted to use. Nothing I tried could get it to work from through the PyCharm Project Interpreter window. But this worked from a terminal (MacOS), having installed graphviz with homebrew.
./pip3 install --install-option="--include-
path=/usr/local/include/graphviz/" \
--install-option="--library-path=/usr/local/lib/graphviz" \
pygraphviz
来源:https://stackoverflow.com/questions/38037013/pygraphviz-import-error-with-pycharm