30

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 it's not found.

When I run the script normally (python script.py) it does import without any errors.

What can be the reason and solution?

8
  • 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. Commented Jun 18, 2018 at 17:44
  • Look this answer stackoverflow.com/questions/35546627/… Commented Jun 18, 2018 at 17:45
  • python --version Python 3.6.5 :: Anaconda custom (x86_64) . @amb1s1 this is what I get. Commented Jun 18, 2018 at 18:09
  • Put this on your Atom and run it. import platform platform.python_version() Let see what version Atom is using. Commented Jun 18, 2018 at 18:19
  • when i run it says 3.6.5 Commented Jun 18, 2018 at 18:21

11 Answers 11

71

Try the following:

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

Make sure that pandas is installed using pip3.

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

8 Comments

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.
Run pip3 list to show the list of install packages and see if panda is on that list.
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?
pip install install python 2.x packages and pip3 install python 3.x.
Woked for me, thanks. Care to explain what happened and why does this work?
|
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

1 Comment

for some 'python3 -m ipykernel install --user' might not work. Instead use, 'py -3 -m ipykernel install --user' on cmd-windows
3

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

Comments

3

For Anaconda/Jupyter Notebook:

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

Comments

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

Comments

1

The issue seems to be resolved by running pip3 install rather than pip install.

2 Comments

pip3 install jupyter
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) `
0

Something that worked for me, after hours looking for an answer was to delete the local Jupyter setting folder.

.jupyter/*

This helped - https://github.com/jupyter/notebook/issues/2359#issuecomment-648380681

Comments

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)

Comments

0

First, 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.

Comments

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*

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.