ModuleNotFound error for import pandas in Jupyter - python-3.x

I get a moduleNotFoundError when importing pandas in my Jupyter Notebook.
There is not error when I do the same on the Terminal. The default python on my machine is python 3.8
This is the code that i am running on Jupyter
Why Jupyter is unable to find the pandas installed on my machine?

It is indeed caused by different versions of python. Jupyter is not executing the default version installed on my system.
To fetch the right version we need to use print(sys.executable).
Thus, the following code worked for me,
import sys
!{sys.executable} -m pip install pandas

Related

My command line keeps saying that I don't have matplotlib installed. I've tried everything that I saw on Stack Overflow

Here is the code that I used:
import math
import matplotlib.pyplot as plt
The error message was:
no module named 'matplotlib'
I have tried:
pip install matplotlib
python3 install mat plotlib
Tried updating Anaconda Navigator to the latest version.
Tried uninstalling and reinstalling Python 3.10.5
Tried using Visual Studio Code and individual Python files (I'll try Jupyter too).
conda update --all
python - version says that I have Python version 3.6.13
After all of that, I still get the same error that there is no module named matplotlib
The answer was that I had never actually attempted to access matplotlib outside of Jupyter Notebooks. I was only meant to access it inside of Jupyter. I created a virtual environment and that didn't work. I also did conda install matplotlib and that destroyed my Python install and I had to reinstall everything.

When try to run import pandas from Visual Studio Code it thrown an ImportError, but works fine in Anaconda (Jupyter Notebook)

I used to code in Jupyter notebook and importing pandas was never thrown an error. But when I use the same code in Visual Studio Code,
# Import Libraries
from random import seed
from random import randint
import pandas
import numpy
import math
import random
import collections
import itertools
import collections
import matplotlib.pyplot as plt
import seaborn as sns
# %matplotlib inline
I receive the below error.
File "g:/My Drive/M/importlibrary.py", line 5, in <module>
import pandas
File "C:\Users\M\Anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
I try to search for several similar issues and most of the solution ask to first uninstall and then install NumPy and Pandas using the below code,
pip3 uninstall pandas
pip3 uninstall numpy
However, I have followed this workaround but the problem did not resolve. The version of python that I am using is,
Python 3.6.8 :: Anaconda, Inc.
Please help if you can.
Is there a reason why you don't install Numpy/Pandas using anaconda (conda install -c anaconda numpy/pandas)? Did you run Jupyter from inside anaconda when it worked? I suggest going to terminal and figuring out where your modules are installed (i.e. if they are inside the anaconda folders, or somewhere where anaconda has access to).
In general, I'd advise against installing python packages for anaconda using pip, just use conda's package manager if you can. This question seems related. In your case, have you tried uninstalling the pip variant and reinstalling using conda?
The problem is resolved by uninstalling the Anaconda. I checked the control panel of the PC and found that there are multiple instances of python. VS Code uses Python 3.6.8 while Anaconda uses python 3.8. So, I uninstall 3.8, and then reinstall pandas,
pip3 uninstall pandas
pip3 install pandas
The error is no more.

No module named 'pandas_datareader' in Jupyter (Anaconda) after I run pip3 install pandas_datareader

I am trying to learn pandas and want to load some stocks data. I was following a course which advised me to load pandas.io.data, but this did not work as io.data was depreciated. So I decided to use pandas-datareader instead. But I am struggling to instal it on mac in Anaconda (Jupiter notebook).
First time I run import pandas_datareader as pdweb I got ModuleNotFoundError: No module named 'pandas_datareader'. Not surprising as I never used this before so I run pip3 install pandas_datareader in Terminal which successfully installed itself. However, Jupiter notebook is still giving me the same error. At this point, I tried running in Terminal conda install -c https://conda.anaconda.org/anaconda pandas-datareader but it did not work as -bash: conda: command not found.
Please help. I am looking for a detailed explanation as I am not too techie.
What I run in Jupiter
import numpy as np
from pandas import Series, DataFrame
import pandas as pd
import pandas_datareader as pdweb
import datetime
Result
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-6-da568f513c93> in <module>
2 from pandas import Series, DataFrame
3 import pandas as pd
----> 4 import pandas_datareader as pdweb
5 import datetime
ModuleNotFoundError: No module named 'pandas_datareader'
Just run
conda install -c anaconda pandas-datareader
as per instructions here.
In my experience, if you're using conda, you should never install with pip unless you're sure conda doesn't have it. Try searching anaconda.org to see which -c source to use.
The problem was with conda command not being set up during the installation of Anaconda. I solved this by removing Anaconda with App Cleaner & Uninstaller Pro (free soft) and reinstalling later version.
After reinstallation of Anaconda command below worked like a charm.
conda install -c anaconda pandas-datareader
If you using Anaconda and still have issues installing panads-datareader using the conda command 'conda install -c anaconda pandas-datareader'. or the installation is successful but the import pandas_datareader.data as web still gives an error.
Locate where your 'site-packages % ' directory and cd to the site-packages % dir and then run the installation command 'conda install -c anaconda pandas-datareader '. It will work.
For the install, try using
pip
instead of
pip3

Anaconda prompt: running python in prompt vs jupyter notebook

I am running into some issues with packages I can access in anaconda prompt vs what is available in Jupyter Notebook.
I recently created an environment for python 3.6. I installed a few packages, including pandas, using:
conda install pandas
And all is well:
When I check conda list, I also see pandas installed for py36.
conda list
Now, I run the following line to start my jupyter notebook from this same location:
jupyter notebook
I then run into an error when I try to import pandas. I then try to install pandas with no luck.
My guess is this stems from having downloaded anaconda for python 2.7, but I assume there is a way to get things working in both versions of python for jupyter notebook.
To add, I am able to use pandas when I use python 2.7 (referred to as "root"):
activate root
jupyter notebook
Any help would be greatly appreciated!

Scipy cannot be imported in Jupyter Notebook

I'm trying to use scipy in a jupyter notebook and it says I have it installed, but when I try to import it, it gives me the following error.
Any help would be great. thank you.
TLDR: try this
import sys
!{sys.executable} -m pip install scipy
A bit more info:
Jupyter notebooks are able to work with multiple kernels, which are essentially pointers to the Python (or other language) executable that the notebook uses. In a Python kernel, you can figure out which one is being used by typing
import sys
print(sys.executable)
When you run a bash command in the notebook, like !pip install scipy, that uses the bash environment that was active when you launched the notebook which is not necessarily associated with the Python kernel you are using. That means that it may be installing scipy in a different Python location. You can figure out which Python your shell points to by running !which python. If this doesn't match, then !pip install will not be installing in the right place.
You can fix this by explicitly telling the bash prompt which Python/pip you want to use. For example, this should do the trick:
import sys
!{sys.executable} -m pip install scipy
This runs the pip version associated with your executable, and installs scipy with that. For some more details on what's happening behind the scenes, check out this answer.
The pip that you execute is using a shell that may (and that is probably the case here) have a different python interpreter than the one of the jupyter notebook!
Jake VanderPlas to the rescue https://twitter.com/jakevdp/status/841791667472543745
Do the following in the notebook
import sys
sys.executable
Depending on the output of "sys.executable", adjust your command-line call, still in the notebook
!/usr/bin/python3 -m pip install scipy
But as you have scipy installed, the issue is to understand why your anaconda scipy is not found. Do you have a default virtualenv for all your python use? How do you start the notebook?

Resources