简体   繁体   中英

Error installing seaborn and sklearn on Jupyter Notebook

I'm trying to install seaborn and sklearn on Jupyter Notebook but I always get the error: ModuleNotFoundError: No module named ... for these two libs.

These were my steps:

  1. $ conda create --name myenv
  2. $ conda activate myenv
  3. (myenv) $ conda install -c anaconda seaborn
  4. (myenv) $ conda install -c anaconda scikit-learn

When I run my python script on terminal, everything is good. No error messages. Then I start the jupyter notebook :

  1. (myenv) $ jupyter notebook

And on the notebook, I only write import seaborn as sns and get the error:

ModuleNotFoundError: No module named 'seaborn'

The same error with sklearn .

What am I missing here?

When you activate a Conda environment, many environmental variables are overwritten. The PATH variable, however, is prepended to. When you call jupyter notebook , the shell will search the PATH , first in your current environment, then in the base environment.

My guess is that you did not install jupyter to my_env , so calling jupyter notebook actually runs Jupyter notebook from your base environment.

You can test this by running:

import sys
print(sys.executable)

You can install jupyter to my_env via:

conda install -n my_env jupyter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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