问题
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