No module named Pandas in Jupyter Notebook - python

I know there is a huge number of questions on this topics, but not even one worked for me, not here, not on github.
I have installed anaconda2 for macOS a few days before. I know pandas come with Anaconda by default, and in the last year I haven't any trouble with any python package on Ubuntu, but now I have a weird problem.
When I run jupyter notebook and import pandas as pd, I got an error: no module named pandas. It's not just about pandas, none of libraries work.
When I try to install pandas with conda, return me Requirement already satisfied. The same with pip.
Also, I have tried to run jupyter notebook with a full path to jupyter package, and doesn't help either.
Probably there is a problem with PATH, but I'm not really good with that and not sure what to do.
But everything works fine when I run iPython in terminal, python in terminal, just doesn't work in jupyter notebook.
> python --version
: Python 2.7.15 :: Anaconda, Inc.
> which python :/anaconda2/bin/python
> which jupyter-notebook:
/anaconda2/bin/jupyter-notebook
> conda env list:
conda environments:
base * /anaconda2
Thanks for any help in advance.

Try this in jupyter cell:
!pip install pandas

Related

Why can I not import a module (Batman) in Jupyter Notebook

I'm trying to import a module (batman, for model transits) in jupyter notebook, but its telling me file not found. However when I use the anaconda terminal it imports without issues
This is the error I get from Jupyter Notebook
I've tried reinstalling the package, and I've tried to find a kernel in which it works, but I'm not sure how to go about that
any help is appreciated
Try checking if the module installed properly by running this:
python -c 'import batman; batman.test()'
the batman module also seems to have some issues when installing on windows.
Read this github if you're on windows https://github.com/lkreidberg/batman/issues/26
I've faced the same issue when I use Jupyter in an Anaconda environment. Jupyter Notebook doesn't use the same kernel as Anaconda and I had to specify it manually.
What you can do is comparing the Python version on your Anaconda environment by running this command in your shell:
python --version
And in your Notebook :
import sys
print(sys.version)
Are the versions different ? If so, you must add your Anaconda kernel to your Notebook :
ipython kernel install --name "local-anaconda-env" --user
Then select it in your Notebook.
I was facing the same issue in VSC. What I did is that first I moved the folder(In your case batman) to where VSC had been installed on my laptop. Then I changed the default directory to where VSC was installed on my laptop by running the following code in VSC.
import os
os.chdir("The path where VSC is installed")
Also If you could try to do the code in a python file instead of jupyter notebook
In a cell within your notebook run the following:
%pip install batman-package
Based on here.
And the use of modern pip install magic to handle installing to correct enviornment from inside a notebook, see here.
For others, hitting here and not seeing what they want/expect.
Above is for batman:
Bad-Ass Transit Model cAlculatioN. Associated Github Repo is here, and Python Package Index page.
This is a poor name for a package as at least three developers have claimed this. Also see:
Anaconda install for Batman at conda-forgeBayesian Analysis Tool for Modelling and uncertAinty quaNtification
BATMAN: A Python deployment toolbelt -Batman 0.7.0 at the Python Package Index
Maybe those links will help you.

Removing one of the two installed Jupyters

In my system, by mistake, a second Jupyter is now installed.
which -a jupyter:
/opt/homebrew/bin/jupyter #latest jupyter which should be removed
/opt/anaconda3/bin/jupyter #previous working jupyter
While the second one,"/opt/anaconda3/bin/jupyter" is what I was working with, the first one,"/opt/homebrew/bin/jupyter" does not work because of its wrong python path and uninstalled packages.
I have tried to remove this jupyter by brew uninstall jupyter, but it didn't work because of this error Error: No such keg: /opt/homebrew/Cellar/jupyter.
As I have numerous packages and libraries on the second jupyter.
Thus, I am not willing to reinstall jupyter from scratch.
Calling Jupyer notebook at the moment calls the first path. Do you have any suggestions to fix this issue?
You have a python that was installed through brew, you should be able to do
/opt/homebrew/bin/pip3 uninstall jupyter
Note that the underlying issue seems to be that your PATH is not set such that the anaconda bin folder takes precedence over the homebrew/bin folder, which you might or might not want to adress. You could also consider uninstalling the homebrew python version with
brew uninstall python

why does import pandas suddenly not work?

I am running the latest anaconda on ubuntu linux. Everything was working ok until this week. I can't import pandas on python3. I could last week using the same programs. I've tried it on python called from the bash and also from spyder and jupyter, and I get a message that it can't find pandas. I've tried reinstalling pandas using both pip and conda, and it said that it was correctly installed.
Any suggestions?
Thank you.
Howard
You can create a new environment on Anaconda and then install pandas in that environment. Otherwise, try re-installing Anaconda.

(Jupyter Notebook) ModuleNotFoundError: No module named 'pandas'

In my terminal, I ran:
pip install pandas
pip3 install pandas
Installation seemed to go well. When I write some code in a file and execute it in my terminal (prompting 'python filename.py' or 'python3 filename.py'), the pandas library can be imported and used without a problem. However, when using Jupyter Lab and Jupyter Notebook, and I get this error when trying to import pandas:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-38d4b0363d82> in <module>
----> 1 import pandas
ModuleNotFoundError: No module named 'pandas'
It seems like Jupyter Notebook does not recognize this library. Very confused as of why and what I should do. FYI reinstalling anaconda did not help, and I am using 'pip' and 'pip3' to install libraries.
I had a similar problem. Your best bet is to install your packages direct from Jupyter notebook, then you can be sure that the packages are being installed into the local python instance.
! pip install --user <package>
The ! tells the notebook to execute the cell as a shell command.
you've got at least 3 versions of Python installed (the system version, a copy of 3.7 and 3.8). you need to figure out which is which, i.e. what you've done to your system!
to know which version of Python is being run you can use something like (from your shell/command prompt, not in Python):
which python3
see here for an explanation and alternatives. this tells you where some version of Python is, but you can also ask for pip3 and conda, jupyter, etc, to see where those have ended up, and to make sure you're running the right one. note that this involves your "shell's path" which you can customise so it picks the right one
next you need tools to figure out the equivalent "within Python". Python libraries aren't independent programs/executables (i.e. what $PATH determines) so this is a seperate set of options
to display where Python looks for code you can do this (inside Python):
import sys
print(sys.path)
see here for more info about what's going on here
note that what happens when you "open jupyter notebook by clicking on the icon with Anaconda Navigator" is a bit more difficult to debug. sys.executable might be useful to figure out what's going on
if you know xkcd, we're sort of in this state

Importing Numpy results in error even though Anaconda says it's installed?

I signed up for a statistics udemy course which uses jupyter running the stock numpy package out of anaconda.
Numpy is working when I run python 3.4.4 in pycharm, but it will not work in either anaconda2 nor anaconda3.. this makes no sense because numpy comes stock as part of the anaconda library.
When I try importing numpy in jupyter, running a local instance of a python 2 script, I get this:
Thinking I could sidestep the error using a IDE, I tried pycharm and I got this:
Numpy is part of the anaconda default library which I'm running, so I checked and made sure the numpy package was there via the Anaconda Prompt using 'conda list'...
Why won't it import successfully?
Before I uninstall and reinstall everything, does anyone have any ideas?
Yayyyy. I figured it out. So I had several different python versions before I was running python through anaconda/jupyter. As a result, the tethering in-between the additional package libraries to the version of python running was shifty. For example, I may have had numpy working configured to 3.4 but not 2.7..
anyways, to break down the steps I took, I uninstalled all instances of python (both anaconda and normal versions). Then I deleted the old 3.4 libraries from my C drive. Then I installed anaconda 2.7.11 again, tested importing numpy and got the same error. Then I thought to myself, what if the packages are installed separate from the python library and their configuration didn't get reset via the reinstall.. so via the anaconda prompt I typed:
pip uninstall numpy
which removed the package I was having trouble with. and then :
pip install numpy
which downloaded and reset a whole new instance of the package. Then I tested importing numpy in both the anaconda prompt and jupyter = both worked.
I'm very happy that this ended up working out as I can continue on as planned. For anyone else who experiences a similar problem, I would try uninstalling, then reinstalling the problem causing package via pip commands - this step seemed to have the most impact on fixing the problem. Then if that doesn't work proceed to uninstall and reinstall the environments in intervals.
You can try using the following command:
pip install numpy --upgrade
This will uninstall old installed version of numpy and install a new version. This command solved my issue.
try activating you base conda environment before starting jupyter.
>activate root
>jupyter notebook

Categories

Resources