Jupyter Notebook can't find modules for Python
Asked Answered
C

10

30

Not sure what happened but whenever I use ipython, hydrogen (atom) or jupyter notebook can't find any of the installed modules. I know I have pandas installed but the notebook says its not found.

I should add that when I run the script normally (python script.py) it does import without any errors.

Suggestions?

Thanks!

Coolidge answered 18/6, 2018 at 17:35 Comment(8)
Run python --version and show us the output. What I'm thinking is that you have two versions of python running on your machine. The terminal is running one and atom is running the other version.Electroform
Look this answer #35547127Electroform
python --version Python 3.6.5 :: Anaconda custom (x86_64) . @Electroform this is what I get.Coolidge
Put this on your Atom and run it. import platform platform.python_version() Let see what version Atom is using.Electroform
when i run it says 3.6.5Coolidge
@Electroform when I do what you suggested my jupyter notebook and terminal do NOT match python versions: 3.7.4 in jupyter and 3.7.5 in my terminal. It must be related to my problem but the answers given currently do NOT work for me for some reason. I wonder if it has anything to do with the error messages conda is currently throwing at me, documented here: #59619942Typical
related issues: github.com/jupyter/notebook/issues/4439 and github.com/jupyter/jupyter_console/issues/163Typical
@Coolidge Please, remove salutations. Should 'Hi', 'thanks', taglines, and salutations be removed from posts?Jolyn
E
70

Try the following:

pip3 install ipykernel --upgrade
python3 -m ipykernel install --user

Make sure that Panda is installed using pip3.

Electroform answered 18/6, 2018 at 18:34 Comment(8)
ran those commands but the issue still ocurrs in atom via hydrogen. when I ran import pandas it threw the module not found error but when I importy numpy it did not throw me any error.Coolidge
Run pip3 list to show the list of install packages and see if panda is on that list.Electroform
using pip3 install seems to have done the trick. Its strange because when i used pip install and conda install it says the package was already there. Is this something I need to fix or be worried about?Coolidge
pip install install python 2.x packages and pip3 install python 3.x.Electroform
it didn't install anything. Why? Error: Requirement not upgraded as not directly required: tornado>=4.2 in /usr/local/lib/python3.6/site-packages (from ipykernel) (6.0.3) Requirement not upgraded as not directly required: jupyter-client in /usr/local/lib/python3.6/site-packages (from ipykernel) (5.3.4) there are more errors but they don't fit in a comment.Typical
If you don't have pip3, try "python3 -m pip install ipykernel --upgrade"Borderland
Woked for me, thanks. Care to explain what happened and why does this work?Notorious
for some 'python3 -m ipykernel install --user' might not work. Instead use, 'py -3 -m ipykernel install --user' on cmd-windowsVaden
F
7

I was having a similar issue. I installed a text processing tool using pip3. The installation was successful and I was able to run the test-code from the terminal, however I was unable to execute the same code from jupyter notebook. Checked that the sys.version was 3.7.1 in notebook but the terminal version was 3.6.9.

The problem was resolved after executing the following commands and relaunching the notebook:

pip3 install ipykernel --upgrade
python3 -m ipykernel install --user
Ferromanganese answered 6/3, 2020 at 14:38 Comment(1)
for some 'python3 -m ipykernel install --user' might not work. Instead use, 'py -3 -m ipykernel install --user' on cmd-windowsVaden
B
2

For Anaconda/Jupyter Notebook:

This solved my problem.

Firstly go to your Anaconda Prompt.

Then activate your environment (or skip this if you want to do it in base)

pip3 install ipykernel --upgrade

Then put this code.

python -m ipykernel install --user --name torch --display-name "PyTorch (base)"

Here, torch = name of your virtual env (put anaconda-base for the base environment)

PyTorch (base) = display name you want to show in the kernel; replace it with your wish.

Then you will see the option to change the kernel (From Kernel Option) to your virtual environment you are looking for.

Before:

Not Working State Not Working State

After:

Working State Working State

And if it is in VS Code, please check this answer. This solves it perfectly.

https://mcmap.net/q/467080/-jupyter-notebook-can-39-t-find-modules-for-python

Beset answered 11/5, 2021 at 9:27 Comment(0)
E
2

I had the exact same problem on a newly installed virtual env. Turned out the problem was i was using an old version of pip and jupyter. The below did the trick for me:

$pip3 install pip --upgrade
$pip3 install jupyter --upgrade
Ensample answered 25/1, 2023 at 8:3 Comment(0)
C
1

Issue seems to be resolved by running

pip3 install rather than pip install

Coolidge answered 18/6, 2018 at 19:21 Comment(2)
pip3 install jupyterNominal
I tried doing that but then it complains I need to upgrade but when I try to upgrade says it's already upgraded but pip3 doesnt think so...chickecn and egg problem? ` (automl) brandomiranda~ ❯ pip3 install ERROR: You must give at least one requirement to install (see "pip help install") You are using pip version 10.0.1, however version 19.3.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. (automl) brandomiranda~ ❯ pip install --upgrade pip Requirement already up-to-date: pip in ./miniconda3/envs/automl/lib/python3.7/site-packages (19.3.1) `Typical
C
1

Fix for Visual Studio Code

Look to the top right corner and click on the displayed Python version.

enter image description here

It should appear a list of your Python versions. Scroll down to the Python version you want to use and click on it.

enter image description here

After that you should see the Python version you selected in the top right corner.

enter image description here

Cammack answered 7/11, 2020 at 18:19 Comment(0)
T
0

The commands:

pip3 install ipykernel --upgrade
python3 -m ipykernel install --user

worked for me only after I re-installed pip (note I was having the issue for python 3.7).

For that I did:

pip uninstall pip

then I used the (deprecated) command:

sudo easy_install pip

I also deleted any pip related thing in /usr/local/bin with the command:

rm -rf pip*

hopefully, this is helpful to someone else :)

Typical answered 8/1, 2020 at 17:17 Comment(0)
S
0

I had the same problem for my jupyter notebook. I installed the modules using the computers terminal and then when I tried loading them in my jupyter notebook, I couldn't load the modules but they were working just fine in the terminal.

At first, i checked the python versions and the terminal was running a python 3.8.5 version and the jupyter notebook was running 3.8.3, I thought this was the reason behind the problem and I updated the whole anaconda package but it still didn't work.

Then I opened the anaconda prompt and installed the package again and i saw that most of the package was already installed and said requirement satisfied but there was just one part that got installed in the anaconda prompt. (Note: I never uninstalled the package in any terminal, and just installed it again in the anaconda prompt). After installing it in the anaconda prompt, it started working just fine.

In summary, try and install the package again in the anaconda prompt.

pip install (module_name)

Hope this will be of some help!!

Sluggish answered 25/10, 2021 at 18:25 Comment(0)
D
0

I had the same issue with other packages (scikit-commpy and ModulationPy). import <package_name> was working on a script.py but not on a notebook.ipynb

What worked for me:

to run !pip install <package_name> inside the notebook.

You only need to do it once (it will probably say "dependencies already installed" but afterwards it will solve the issue).

what didn't work for me but might be helpful:

  • compare sys.version from both script.py and notebook.ipynb
  • call help('modules') on both and compare
    • you can also do help('modules <package_name>') for filtering the long list to your specific package.
  • reinstalling any of the following packages:
    • defected package
    • ipython
    • ipykernel
  • on Pycharm: File > Invalidate caches
Douche answered 8/2, 2022 at 11:39 Comment(0)
C
0

I solve it with 1 uninstall pip:

pip uninstall pip

then Download get-pip.py:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

or use

wget https://bootstrap.pypa.io/get-pip.py

Finally Run the script:

python get-pip.py

This will reinstall and install or upgrade pip to the latest version.

and that solved the problem.

Caril answered 23/12, 2023 at 21:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.