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!

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
Harris2018
  • 503
  • 1
  • 5
  • 13
  • 1
    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. – amb1s1 Jun 18 '18 at 17:44
  • Look this answer https://stackoverflow.com/questions/35546627/how-to-configure-atom-to-run-python3-scripts – amb1s1 Jun 18 '18 at 17:45
  • `python --version` `Python 3.6.5 :: Anaconda custom (x86_64)` . @amb1s1 this is what I get. – Harris2018 Jun 18 '18 at 18:09
  • Put this on your Atom and run it. `import platform` `platform.python_version()` Let see what version Atom is using. – amb1s1 Jun 18 '18 at 18:19
  • when i run it says 3.6.5 – Harris2018 Jun 18 '18 at 18:21
  • @amb1s1 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: https://stackoverflow.com/questions/59619442/how-does-one-fix-the-issue-of-not-writable-paths-with-conda – Charlie Parker Jan 08 '20 at 16:27
  • related issues: https://github.com/jupyter/notebook/issues/4439 and https://github.com/jupyter/jupyter_console/issues/163 – Charlie Parker Jan 08 '20 at 16:40
  • @Harris2018 Please, remove salutations. [Should 'Hi', 'thanks', taglines, and salutations be removed from posts?](https://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts) – maciejwww Apr 18 '21 at 17:56

9 Answers9

70

Try the following:

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

Make sure that Panda is installed using pip3.

amb1s1
  • 1,995
  • 5
  • 22
  • 26
  • 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. – Harris2018 Jun 18 '18 at 18:37
  • 1
    Run `pip3 list` to show the list of install packages and see if panda is on that list. – amb1s1 Jun 18 '18 at 18:48
  • 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? – Harris2018 Jun 18 '18 at 19:17
  • `pip install` install python 2.x packages and pip3 install python 3.x. – amb1s1 Jun 18 '18 at 19:20
  • 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. – Charlie Parker Jan 08 '20 at 16:24
  • If you don't have pip3, try "python3 -m pip install ipykernel --upgrade" – Punnerud Sep 08 '20 at 09:13
  • 3
    Woked for me, thanks. Care to explain what happened and why does this work? – Michael Gruner Oct 16 '20 at 21:51
  • for some 'python3 -m ipykernel install --user' might not work. Instead use, 'py -3 -m ipykernel install --user' on cmd-windows – Faheeem Sajjad Dec 05 '21 at 10:12
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
Doi
  • 137
  • 1
  • 5
  • 1
    for some 'python3 -m ipykernel install --user' might not work. Instead use, 'py -3 -m ipykernel install --user' on cmd-windows – Faheeem Sajjad Dec 05 '21 at 10:13
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://stackoverflow.com/a/64730974/9848043

Joyanta J. Mondal
  • 888
  • 1
  • 8
  • 20
1

Issue seems to be resolved by running

pip3 install rather than pip install

Harris2018
  • 503
  • 1
  • 5
  • 13
  • pip3 install jupyter – Rexcirus Dec 23 '19 at 22:00
  • 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) ` – Charlie Parker Jan 08 '20 at 16:21
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

Gabriel Arghire
  • 1,992
  • 1
  • 21
  • 34
1

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
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 :)

Charlie Parker
  • 5,884
  • 57
  • 198
  • 323
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!!

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
Yarden Cohen
  • 584
  • 2
  • 4
  • 19