简体   繁体   English

导入错误:virtualenv 中没有名为 matplotlib 的模块

[英]ImportError: No module named matplotlib in virtualenv

I am trying to import matplotlib while working in my virtualenv for cv.我正在尝试在我的 virtualenv 中为 cv 导入matplotlib

I can import it just fine in the shell when I import it outside virtualenv but importing it while working on cv, causes this error:当我将它导入到 virtualenv 之外时,我可以在 shell 中很好地导入它,但是在处理 cv 时导入它会导致此错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named matplotlib

Please help!请帮忙!

I had the same problem and I solved it in this way.我有同样的问题,我以这种方式解决了它。

I am using virtualenvironment with virtualenvwrapper and running the import matplotlib in a Jupyter notebook我正在使用带有 virtualenvwrapper 的 virtualenvironment 并在 Jupyter notebook 中运行import matplotlib

I create a virtualenvironment called test1 with我创建了一个名为test1的虚拟环境

virtualenv -p python3 test1

or, if you also use virtualenvwrapper you can do或者,如果你也使用 virtualenvwrapper 你可以做

mkvirtualenv -p python3 test1

Now, activate your virtualenvironment.现在,激活您的虚拟环境。 Once activated you can (from inside the virtualenvironment) install ipykernel using pip:激活后,您可以(从虚拟环境内部)使用 pip 安装 ipykernel:

pip install ipykernel (equivalent to python -m pip install ipykernel ) pip install ipykernel (相当于python -m pip install ipykernel

EDIT (it does not seem you need the following between parenthesis) {}编辑(似乎不需要括号之间的以下内容){}

{ {

And now install a new kernel:现在安装一个新内核:

ipython kernel install --user --name=test1

} }

At this point, you can install Jupiter by doing:此时,您可以通过执行以下操作来安装 Jupiter:

pip install jupyter (equivalent to python -m pip install jupyter ) pip install jupyter (相当于python -m pip install jupyter

Now start Jupiter with现在启动木星

jupyter notebook

Make sure that the kernel used is the new one.确保使用的内核是新内核。 Create a new notebook.创建一个新笔记本。

Then if I try to run this file:然后,如果我尝试运行此文件:

import matplotlib

You should still have the error你应该仍然有错误

Go back to the terminal and do返回终端并执行

python -m pip install matplotlib

And you should be good to go.你应该很高兴去。 I hope this will help someone else.我希望这会帮助别人。

BONUS: some commands that helped me in the Jupyter notebook in understanding the situation were these:奖励:在 Jupyter 笔记本中帮助我了解情况的一些命令是:

import sys
print (sys.path)
! which python
! python --version
! python3 --version
! pip show matplotlib

如果在 jupyter 中运行,请不要忘记pip install jupyter

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

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