简体   繁体   English

该模块已成功安装,但导入时未找到? - Python

[英]The module has been successfully installed but then it's not found when imported? - Python

I'm trying to use the graphviz Python module and I've run into this problem: I pip installed it in my command prompt, but it's not showing up in IPython.我正在尝试使用 graphviz Python 模块,但遇到了这个问题:我在命令提示符中安装了它,但它没有出现在 IPython 中。 I have additionally a Python 3.5 (32-bit) interpreter where it IS showing up, but I'm trying to figure out how to have it installed so it works in IPython.我还有一个 Python 3.5(32 位)解释器,它显示在那里,但我试图弄清楚如何安装它以便它在 IPython 中工作。

I've been recommended to include the sys.path for each of the interpreters.我被建议为每个解释器包含 sys.path。

Anyone have any ideas as to how I'd change it?有人对我如何改变它有任何想法吗?

在此处输入图片说明

Try using virtual environments.尝试使用虚拟环境。

   $ virtualenv -p python3 `/path/to/venv/dir`
   $ . `/path/to/venv/dir/bin/activate`
   (venv) $ # indicates virtual env is configured
   (venv) $ which pip python3
   (venv) $ pip install whatever
   (venv) $ python3 script.py

Your system python is 3.5.2 While IPython appears to be using 3.6 based on the sys.path output.您的系统 python 是3.5.2而 IPython 似乎使用基于sys.path输出的3.6

Try pip3.6 install graphviz试试pip3.6 install graphviz

It is quite common to have such cases when there are multiple installations of python.当有多个 python 安装时,这种情况很常见。

From the snapshot, we can infer that python 3.5 is default for the system and python 3.6 is installed for the specific user (Oliver Jr).从快照中,我们可以推断系统默认安装了python 3.5,并且为特定用户(Oliver Jr)安装了python 3.6。

Installing any module without setting path variable will result in installing the module in default python (python 3.5)在不设置路径变量的情况下安装任何模块将导致在默认 python (python 3.5) 中安装模块

Inorder to use the module in python 3.6, set the path variable as为了使用python 3.6中的模块,将路径变量设置为

SET PATH=C:\\Users\\Oliver Jr\\Anaconda>;%PATH%;

Check if default python version is changed to python 3.6 by using检查默认 python 版本是否更改为 python 3.6 使用

python --version

Then install the module using然后使用安装模块

pip install graphviz

You can also install using C:\\UsersOliver Jr\\Anaconda\\bin\\pip install graphviz您也可以使用C:\\UsersOliver Jr\\Anaconda\\bin\\pip install graphviz

Try to list out installed packages in your python:尝试列出 Python 中已安装的软件包:

$pip freeze

Usually it happened because of PYTHONPATH problem.通常它是因为 PYTHONPATH 问题而发生的。 Did you try to reinstall your iPython?您是否尝试重新安装 iPython? Maybe it was installed using different version of python.也许它是使用不同版本的python安装的。

$pip uninstall ipython
$pip install ipython

I tried using Python 3.6.3, it works well.我尝试使用 Python 3.6.3,效果很好。 Or you can try;或者你可以试试;

$pip3.6 install graphviz

You have 2 Python installations - one ordinary, as downloadable from https://www.python.org , installed in C:\\Python ;您有2 个Python 安装 - 一个普通的,可从https://www.python.org下载,安装在C:\\Python and another one, the self-contained Anaconda installation C:\\Users\\Oliver Jr\\Anaconda .另一个是独立的Anaconda安装C:\\Users\\Oliver Jr\\Anaconda

You have installed Graphviz in the former - the standard Python distribution that resides in C:\\Python , but you've installed IPython in Anaconda!您已经在前者中安装了 Graphviz - 位于C:\\Python的标准 Python 发行版,但是您已经在 Anaconda 中安装了 IPython!

Since I suspect that you'd much prefer Anaconda over the standard Python as it makes installing scientific and mathematical packages on Windows much easier, you'd probably want to install it in your Anaconda distribution :由于我怀疑您更喜欢 Anaconda 而不是标准 Python,因为它使在 Windows 上安装科学和数学包更容易,您可能希望将它安装在您的 Anaconda 发行版中

conda install -c anaconda graphviz 

Can't test it now, but what if install graphviz from IPython with "!":现在无法测试,但是如果使用“!”从 IPython 安装 graphviz 会怎样:

! pip install graphviz

And restart IPython.并重新启动 IPython。

Try this:试试这个:

conda install -c conda-forge python-graphviz

Or this: Conda comes with its own pip.或者这个:Conda 自带 pip。 Do

conda install pip

Then find the pip executable and run that directly (ie /path/to/anacondapip install graphviz )然后找到 pip 可执行文件并直接运行(即/path/to/anacondapip install graphviz

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM