Forums

Jupyter Notebook doesn't use right kernel/virtual environment

Hi, I'm new to Python Anywhere. I'd like to run code in a Jupyter notebook.

  • I have the most recent system image (haggis).
  • I created a virtual environment following these instructions: https://help.pythonanywhere.com/pages/IPythonNotebookVirtualenvs/.

  • I installed the numpy and mapie packages following these instructions https://help.pythonanywhere.com/pages/InstallingNewModules/.

  • I checked the versions of the packages in the bash console using pip list: numpy 1.24.2 and MAPIE 0.6.4. Bash code:

    mkvirtualenv testenv --python=python3.10
    ipython kernel install --name "testenv" --user
    workon testenv
    pip install mapie pip list

  • I opened a new Jupyter notebook en changed the kernel to the virtual environment I created. It says 'testenv' in the right upper corner of the screen.

  • I import numpy and check the version in my notebook. It's 1.21.6 :-(
  • I try to import mapie in my notebook but get a ModuleNoFoundError: No module named 'mapie' .

So it seems to me the notebook is not using the right kernel/virtual environment. What am I doing wrong here? I'd really appreciate any pointers you could give me.

Best, Willy

Make sure that you installed packages in the venv and that command ipython kernel install --name "testenv" --user was executed in the venv as well.

Thank you for your response @pafk but it didn't solve my problem. Do you have any other suggestions?

Make sure that you have switched to the kernel that matches your virtualenv and that you have restarted the kernel.