简体   繁体   English

Jupyter笔记本,ImportError:没有名为pylab的模块

[英]Jupyter notebook, ImportError: No module named pylab

I am a ubuntu user, and I have install python 2.7.9 on my computer. 我是一个ubuntu用户,我在我的电脑上安装了python 2.7.9。 In order to use jupyter notebook, I down load anaconda2. 为了使用jupyter笔记本,我下载了anaconda2。 After my installation, I find after entering the command 'jupyter notebook', my browser will open jupyter notebook, but I can't find new python2, so I went to the https://ipython.readthedocs.org/en/latest/install/kernel_install.html Use the following commands: 安装完成后,我发现输入命令'jupyter notebook'后,我的浏览器将打开jupyter笔记本,但我找不到新的python2,所以我去了https://ipython.readthedocs.org/en/latest/ install / kernel_install.html使用以下命令:

conda create -n ipykernel_py2 python=2 ipykernel
source activate ipykernel_py2    
python -m ipykernel install --user

Now I do can new python2 on the jupyter notebook, but when I enter the command 'from pylab import *' it will show the error as ImportError: No module named pylab but if I open a terminal and enter 'python' and then enter 'from pylab import *', it works all ok. 现在我在jupyter笔记本上可以使用新的python2,但是当我输入命令'from pylab import *'时它将显示错误为ImportError:没有名为pylab的模块但是如果我打开一个终端并输入'python'然后输入'来自pylab import *',一切正常。

So, what is the problem? 那么,问题是什么? I am new to python and jupyter notebook. 我是python和jupyter笔记本的新手。 Thank you very much. 非常感谢你。

I find the problem. 我发现了问题。

In terminal: 在终端:

ipython
In [1]: import sys

In [2]: sys.path
Out[2]: 
['',
 '/home/hust/anaconda2/bin',
 '/home/hust/anaconda2/lib/python27.zip',
 '/home/hust/anaconda2/lib/python2.7',
 '/home/hust/anaconda2/lib/python2.7/plat-linux2',
 '/home/hust/anaconda2/lib/python2.7/lib-tk',
 '/home/hust/anaconda2/lib/python2.7/lib-old',
 '/home/hust/anaconda2/lib/python2.7/lib-dynload',
 '/home/hust/.local/lib/python2.7/site-packages',
 '/home/hust/anaconda2/lib/python2.7/site-packages',
 '/home/hust/anaconda2/lib/python2.7/site-packages/Sphinx-1.3.5-py2.7.egg',
 '/home/hust/anaconda2/lib/python2.7/site-packages/setuptools-20.3-py2.7.egg',
 '/home/hust/.local/lib/python2.7/site-packages/IPython/extensions',
 '/home/hust/.ipython']

But in jupyter notebook, the sys.path is: 但是在jupyter笔记本中,sys.path是:

 ['',
  '/home/hust/anaconda2/envs/ipykernel_py2/lib/python27.zip',
  '/home/hust/anaconda2/envs/ipykernel_py2/lib/python2.7',
  '/home/hust/anaconda2/envs/ipykernel_py2/lib/python2.7/plat-linux2',
  '/home/hust/anaconda2/envs/ipykernel_py2/lib/python2.7/lib-tk',
  '/home/hust/anaconda2/envs/ipykernel_py2/lib/python2.7/lib-old',
  '/home/hust/anaconda2/envs/ipykernel_py2/lib/python2.7/lib-dynload',
  '/home/hust/.local/lib/python2.7/site-packages',
  '/home/hust/anaconda2/envs/ipykernel_py2/lib/python2.7/site-packages/setuptools-20.7.0-py2.7.egg',
  '/home/hust/anaconda2/envs/ipykernel_py2/lib/python2.7/site-packages',
  '/home/hust/.local/lib/python2.7/site-packages/IPython/extensions',
  '/home/hust/.ipython']

Then I remember I have used the following codes to create a python2 kernel. 然后我记得我使用以下代码创建了一个python2内核。

conda create -n ipykernel_py2 python=2 ipykernel
source activate ipykernel_py2    
python -m ipykernel install --user

In the website 's description, if you're running Jupyter on Python 3, you can set up a Python 2 kernel like this. 网站的描述中,如果你在Python 3上运行Jupyter,你可以设置这样的Python 2内核。 But actually I am running Jupyter on Python 2, the reason why I could not new a python2 script in jupyter notebook should be something else. 但实际上我在Python 2上运行Jupyter,之所以我不能在jupyter笔记本中新建一个python2脚本应该是别的东西。

Finally, I realize that it is better to master all the pythons' environment via pyenv . 最后,我意识到通过pyenv掌握所有蟒蛇的环境会更好 I should firstly install pyenv and then I only need use these commands, pyenv install anaconda-2.4.0 , pyenv global anaconda-2.4.0 and jupyter notebook . 我应该先安装pyenv然后我只需要使用这些命令, pyenv install anaconda-2.4.0pyenv global anaconda-2.4.0jupyter notebook

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

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