Why does sklearn package run in terminal but not in jupyter?

本秂侑毒 提交于 2021-01-29 03:00:44

问题


When importing sklearn in jupiter, the result is:

>>> import sklearn
ImportError: No module named 'sklearn'

I've installed scikit-learn with pip, and pip list shows the sklearn is installed. Importing sklearn works fully in terminal, just not here in jupyter.

My only thoughts are that they're running in different environments?

In terminal:

>>> sys.executable
'/Users/Victoria/anaconda3/bin/python'

However, in Jupyter:

>>> sys.executable
'/Users/Victoria/anaconda3/envs/py35/bin/python'

Any help here is greatly appreciated, thanks a lot.


回答1:


You might need to install corresponding kernel dependencies. Execute the following command.

pip install environment_kernels

Now restart your Jupyter notebook. Should work.

Best!




回答2:


  • Activate your environment, you should see the following:

    which python
    '/Users/Victoria/anaconda3/envs/py35/bin/python'
    which jupyter
    '/Users/Victoria/anaconda3/envs/py35/bin/jupyter'
    
  • Install sklearn in the environment (you can use pip or conda)

  • Run jupyter from the environment

If this doesn't work, reinstall jupyter in your environment using conda and try again. You might have to deactivate and activate the environment once after installing the package.



来源:https://stackoverflow.com/questions/41076287/why-does-sklearn-package-run-in-terminal-but-not-in-jupyter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!