0

I'm relatively new to Jupyter Notebook and have been struggling with python versions with Jupyter Notebook.

I installed seaborn but import error occurred saying no seaborn package found. It shows on upper right corner of Jupyter "Python 3" but it returned Python 2.7 when I run !python --version. Also when I run print(sys.path), the result is below.

['', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mysql-0.0.1-py3.5.egg', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python35.zip', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/IPython/extensions', '/Users/Cynthia/.ipython']

My guess is that my python kernel isn't pointing correctly to python3 although notebook shows it's python3. Could someone pls help me solve this? It would be helpful if there could be code to run in Jupyter cell. Thank you!

14
  • Did you added python 3 to the path?Check that out. Commented Aug 23, 2020 at 6:58
  • 1
    You should probably look at sys.version - !python --version could be starting a different python. Commented Aug 23, 2020 at 6:59
  • 1
    python is usually the name of the Python2 executable. Just because you are running this command from inside Python3 does not change that. Check sys.executable to see what is the executable of the current program. You likely installed seaborn for the wrong Python executable as well. Commented Aug 23, 2020 at 7:00
  • Loosely related, when you start messing with different python versions and package versions I would recommend to a package manager like conda (install conda). There is also Anaconda, the GUI based approach (install anaconda) Commented Aug 23, 2020 at 7:08
  • @alaniwi when I run sys.version, it says '3.5.0 (v3.5.0:374f501f4567, Sep 12 2015, 11:00:19) \n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]' Commented Aug 23, 2020 at 8:14

2 Answers 2

1

When you run python --version, It won't spit python 3.5.x, because python refers to python2 unless you aliased python as python3. So it makes sense that you see python 2.7.x when you run python --version.

As for py2 when you run conda env list, they are env names you set. They are just names, not python versions.

What needs to be done I think is to find out where your jupyterlab is installed, which I think in (base) environment. In your base environment, run conda list, where you will see a list like this:

(base) âžś  test conda list
# packages in environment at /Users/gwanghyeongim/.pyenv/versions/miniconda3-latest:
#
# Name                    Version                   Build  Channel
brotlipy                  0.7.0           py38haf1e3a3_1000  
ca-certificates           2020.6.24                     0  
certifi                   2020.6.20                py38_0  
cffi                      1.14.1           py38hed5b41f_0  
chardet                   3.0.4                 py38_1003  
conda                     4.8.4                    py38_0  
conda-package-handling    1.6.1            py38h1de35cc_0  
cryptography              2.9.2            py38ha12b0ac_0  
idna                      2.10                       py_0  
libcxx                    10.0.0                        1  
libedit                   3.1.20191231         h1de35cc_1  
libffi                    3.3                  hb1e8313_2  
ncurses                   6.2                  h0a44026_1  
openssl                   1.1.1g               h1de35cc_0  
pip                       20.2.2                   py38_0  
pycosat                   0.6.3            py38h1de35cc_1  
pycparser                 2.20                       py_2  
pyopenssl                 19.1.0                     py_1  
pysocks                   1.7.1                    py38_1  
python                    3.8.3                h26836e1_1  
python.app                2                       py38_10  
readline                  8.0                  h1de35cc_0  
requests                  2.24.0                     py_0  
#and so on...

See if you see jupyterlab in the list. If so, your jupyter notebook is in (base) environment.

Now the most likely scenario is you installed seaborn in py2 environment. That means you dind't install seaborn in your base environment. Install it by running conda install seaborn or pip install seaborn.

If something didn't work so far, try runnning conda upgrade --all -y to upgrade packages. It might be from collision between deprecated packages.

P.S My suggestion is you create a separate environment and run packages on it.

  1. Run conda create -n your_env_name to do so(replace your_env_name to the name you want set)

  2. Activate by running conda activate the_env_you_just_created

  3. If 2 doesn't work somehow, make sure you run conda init your_shell, where your_shell can be found by running echo $SHELL, where the last word after / is your shell.

  4. Make sure you see (your_env_name) at the first part of command prompt. If so, your env is activated. Now install packages on here and do your project, rather than on base environment.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you so much! I run conda list, and yes jupyterlab is in my base list. But when I run conda install seaborn or pip install seaborn, it shows "Requirement already satisfied: seaborn in /Users/Cynthia/anaconda3/lib/python3.6/site-packages (0.9.0)" So now I'm running conda upgrade --all -y. Hopefully I can import seaborn after this update...
It finished running with an error saying "RemoveError: 'setuptools' is a dependency of conda and cannot be removed from conda's operating environment."
@flyunicorn This and this suggest that you run conda update conda. Check them out and consider trying it out.
I run echo $SHELL, it returns /bin/bash. Next I run !conda init bash, it returns a list of "no change and no action taken."
Have you tried closing and opening your terminal(or command prompt for windows)?
0

Since you mentioned you use conda you can do something like the following. From your terminal:

conda create -n sb python=3
conda activate sb
conda config --env --add channels conda-forge
conda install -y pandas matplotlib numpy scipy seaborn jupyterlab # some default packages
jupyter lab

Whenever you want to use this conda environment again you have to do

conda activate sb

before you can run jupyter lab.

Note, if you didn't changed the default, you should see your terminal prompt changing when activating an environment, i.e. the name of the environment comes before your prompt. In our case here (sb) <prompt>.

To solve the issue with your current conda environment, more information is needed.

9 Comments

By second line(conda activate sb), it returns: CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'. To initialize your shell, run $ conda init <SHELL_NAME> Currently supported shells are: - bash - fish - tcsh - xonsh - zsh - powershell See 'conda init --help' for more information and options. IMPORTANT: You may need to close and restart your shell after running 'conda init'.
@flyunicorn Have you tried running conda init <your shell>? If not, please do so.
I was able to run conda update conda and conda install seaborn. Both run successfully, but when I import seaborn, same error of no such module. So my notebook is accessing different location for packages other than through conda?
I think I know where the mismatch is. After I run pip install seaborn, it returns: Requirement already satisfied: seaborn in /Users/Cynthia/anaconda3/lib/python3.6/site-packages (0.9.0)....After I run sys.path, it shows:'/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5'. So it seems seaborn is saved in python 3.5 whereas the path was pointing to python 3.5. How to solve this?
@flyunicorn sys.path isn't just one thing. It is a list containing paths. It equals what you see when you run echo $PATH. It can have multiple Versions, if you have installed multiple python versions.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.