2017-02-11 41 views
1

我想在本地機器上運行。我得到一個錯誤 ImportError:只有在jupyter筆記本中沒有名爲'sklearn'的模塊 當我在命令行中使用python和carnd-term1 env激活和停用時,它工作正常。Jupyter Notebook ImportError:沒有名爲'sklearn'的模塊

我用pip,apt-get和conda安裝了sklearn。也試過conda升級scikit-learn。無論是env激活還是停用。


(carnd-term1) [email protected]:~/sdc$ conda upgrade scikit-learn 
Fetching package metadata ......... 
Solving package specifications: . 
# All requested packages already installed. 
# packages in environment at /home/matt/anaconda3/envs/carnd-term1: 
# 
scikit-learn 0.18.1 np112py35_1 

(carnd-term1) [email protected]:~/sdc$ python3 
Python 3.5.2 | packaged by conda-forge | (default, Jan 19 2017, 15:28:33) 
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import sklearn 
>>> 

...: (carnd-term1) [email protected]:~/sdc$ ipython 
    ...: Python 3.5.2 | packaged by conda-forge | (default, Jan 19 2017, 15:28:33) 
    ...: Type "copyright", "credits" or "license" for more information. 
    ...: 
    ...: IPython 5.1.0 -- 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 sklearn 
    ...: 
    ...: In [2]: from sklearn.model_selection import train_test_split 
    ...: 
    ...: In [3]: (carnd-term1) [email protected]:~/sdc$ ipython 
    ...: ...: Python 3.5.2 | packaged by conda-forge | (default, Jan 19 2017, 15:28:33) 
    ...: ...: Type "copyright", "credits" or "license" for more information. 
    ...: ...: 
    ...: ...: IPython 5.1.0 -- 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 sklearn 
    ...: ...: 
    ...: ...: In [2]: from sklearn.model_selection import train_test_split 
    ...: ...: 
    ...: ...: In [3]: 

不從jupyter筆記本電腦工作。

任何想法?

+0

您是否將jupyter筆記本安裝到此環境中? – darthbith

回答

0

這通常意味着兩者不是相同的環境。最好的檢查是sys.executable,並確保它是你所期望的。如果它是不是使用sys.executable您所期望的筆記本,第一步可能是檢查你的路:

which jupyter 
which jupyter-notebook 

最有可能的問題是,筆記本堆棧是不是在你的暢達ENV,它可以解決搭配:

conda install notebook 

第二個最有可能的是,你已經安裝了kernelspec(例如用ipython kernel install --user)這是壓倒一切的ENV。你可以看到你的內核是用:

jupyter kernelspec list 

要確保你已經安裝在同一ENV IPython的內核,你可以這樣做:

conda install ipykernel 
ipython kernelspec install --sys-prefix 

後再次檢查jupyter kernelspec list

相關問題