2016-04-26 90 views
1

我是一個ubuntu用戶,我在我的電腦上安裝了Python 2.7.9。 爲了使用jupyter筆記本,我下載了anaconda2。 我安裝完畢後,我輸入命令「jupyter筆記本」,我的瀏覽器將打開jupyter筆記本後發現,但我不能找到新的python2,所以我去了https://ipython.readthedocs.org/en/latest/install/kernel_install.html 使用以下命令:Jupyter筆記本,ImportError:沒有名爲pylab的模塊

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

現在我可以在jupyter筆記本上新建python2,但是當我輸入命令'from pylab import *' 它將顯示錯誤爲ImportError:沒有名爲pylab的模塊 但是如果我打開終端並輸入'python'並然後輸入'from pylab import *',它可以正常工作。

那麼,這是什麼問題?我是新的python和jupyter筆記本。 非常感謝。

+0

如果我在jupyter上運行'import sys',它也可以。我完全不知道如果我在Ubuntu上安裝python 2.7.9和anaconda2會發生什麼。當我在Windows上執行它時,它就可以正常工作,並且我只需要單擊jupyter筆記本或ipython而不設置任何環境。但在Ubuntu上,一切似乎都不一樣而且很難。 –

+0

jupyter notebook [W 13:29:00.091 NotebookApp]小工具不可用。請安裝widgetsnbextension或ipywidgets 4.0 [I 13:29:00.106 NotebookApp]從本地目錄服務筆記本:/ home/hust/anaconda2/bin [I 13:29:00.106 NotebookApp] 0個活動內核 [I 13:29: 00.106 NotebookApp] Jupyter Notebook運行於:http:// localhost:8888/ [I 13:29:00.106 NotebookApp]使用Control-C停止此服務器並關閉所有內核(兩次以跳過確認)。 (process:23340):GLib-CRITICAL **:g_slice_set_config:assertion'sys_page_size == 0'failed –

+0

[I 13:29:42.046 NotebookApp]在 [W 13:29:43.504 NotebookApp]中創建新筆記本404 GET/nbextensions/widgets/notebook/js/extension.js?v = 20160426132900(:: 1)11.87ms referer = http:// localhost:8888/notebooks/Untitled.ipynb?kernel_name = python2 [I 13:29:43.616 NotebookApp ]內核已啓動:0b9c634e-686f-43c0-8969-acde3c38888 ** –

回答

0

我發現這個問題。

在終端:

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'] 

但在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'] 

然後我記得我用下面的代碼來創建一個python2內核。

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

website的描述,如果你在Python 3的運行Jupyter,你可以設置一個Python 2內核是這樣的。但實際上,我正在Python 2上運行Jupyter,所以我無法在jupyter筆記本中新建一個python2腳本的原因應該是別的。

最後,我意識到最好通過pyenv掌握所有蟒蛇的環境。我應該首先安裝pyenv,然後我只需要使用這些命令,即pyenv install anaconda-2.4.0,pyenv global anaconda-2.4.0jupyter notebook

相關問題