I've installed python and pandas using the Anaconda library, but it doesn't work when I try to import pandas in Jupyter Notebook or in the Python Idle. It does work when I run the shell in the terminal.
I am using macOS Mojave and Python version 3.7.6.
In the terminal, it says I have pandas already installed as you can see below.
However, I get the error message "ModuleNotFoundError: No module named 'pandas'" when trying to import it in the Python Idle as you can see below.
I think I know where the problem comes from but I don't know how to troubleshoot or fix it. I installed Anaconda 2 years ago and used it but deleted it when I was done with it to make space in my computer and now I reinstalled it. So I think the Idle and Jupyter Notebook are using a different version of Python than the one that came in the Anaconda package. I might be completely wrong.
Thank you for your help!
You probably haven't installed pandas in the same environment your Jupyter kernel is running in.
You can install it directly from Jupyter notebook by running !pip install pandas. That will install it in the environment that the kernel started in.
In general, running !pip freeze from jupyter notebook should show you all installed libraries. If pandas is not there after you ran !pip install pandas, your environment paths are broken in some big way.
In that case, I'd suggest nuking anaconda and jupyter installation and starting again.
If you want to know more about kernels and how packages work in them https://biasandvariance.com/importing-packages-in-jupyter-notebook/ could help.
If you want to use Anaconda, then just do:
conda install pandas
Mixing conda and pip may cause issues.
Can you try updating pandas?
pip install --upgrade pandas
Related
I tried installing Rasterio library using command- pip install rasterio and also used conda commands in anaconda cmd, both are didn't worked and it's taking too long to install so I aborted the process. Let me know in detail how to install raserio library for python?
I tried with installing GDAL and raterio whl file by using pip commands. It got installed, but when I tried to import module- it's giving me an error saying No module found. Please help to fix this.
Thanks in advance
I just had the similar problem, and tl:dr the issue for me was multiple environments, like Ameya said. Here's a longer version of Ameya's spot-on answer with steps to diagnose and fix.
Without realizing it, I had two environments going on: my jupyter notebook was running python 3.10 and my global python was running 3.9, and each was looking for site-packages in different locations (/opt/homebrew/Cellar/jupyterlab/3.4.7/libexec/lib/python3.10/site-packages vs /Users//Library/Python/3.9/lib/site-packages).
This happened because I had trouble with getting python and specifically jupyterlab running on Monterey and the only fix for me was using homebrew to manage the packages. Anything I installed with brew from the command line, went into /opt/homebrew/Cellar... etc and could be seen by my jupyter notebook. Anything I used pip install to get from within an open notebook also went onto this path that my notebook could see. But anything I used pip install from the command line to get, went to the path of the global environment's site packages. Then, my jupyter notebook couldn't see them.
You don't mention that you are using jupyter notebook but perhaps something analogous could happen between multiple environments for you.
You can check if this is the case for you by doing the following:
start python from the command line
import sys
run sys.path
start jupyter notebook, or start python from your other environment
same thing, import sys, run sys.path
Are they the same? If not, probably pip is putting your rasterio in other python env site-packages.
To fix, you can either pip install from within your preferred environment, or copy and paste the site packages corresponding to rasterio from one site-packages location to the other.
I have recently uninstalled python 3.7 and installed python 3.9. After that, when I try to use pip to install any package, it keeps trying to use python37.exe, which is not installed anymore. I was able to solve that by using python -m pip install, but the same does not work when I try to launch jupyter notebook, which still tries to use python37. I cannot launch it using a similar command python -m jupyter notebook.
I was wondering if there is any solution to this, since I could not find anything related to that.
Thanks in advance.
Maybe try to install it again using your new pip like
pip install notebook
(Sorry not enough reputation for a comment)
This usually occurs when jupyter is installed with a specific version of python. The easiest / best solution is to uninstall jupyter, then reinstall it with the correct version of python.
In your case, you should consider using python3.9 -m pip install jupyter (after first uninstalling jupyter).
Just to give you all an update in case anyone is facing the same problem.
I was able to find some remaining files and files of the previous installation of Python 3.7 in my system that were not deleted for some reason during the uninstall process. I deleted them manually and my system started to recognize Python 3.9 to call pip and jupyter after that.
I'm trying to use the seaborn module in the Spyder IDE. I've installed seaborn (and sklearn) through pip install (pip install seaborn, pip3 install seaborn, pip -m install seaborn, conda install seaborn). I've also tried uninstalling it and installing it again. I see it in my pip list. But when I go into Spyder and actually try to import it using "import seaborn as sns", it says "mo module named 'seaborn'".
I've installed other modules (pandas, numpy, etc), so I'm pretty sure my PATH is set appropriately. I found another thread but it was all about starting virtual environments to work with seaborn, which I'd rather not do.
Any ideas? Please keep in mind that I'm fairly a newbie, so I have a basic IDE setup.
You may want to check whether the Spyder you are using is the correct one.
You can check this with which spyder from the commandline.
It should report Spyder being in the same directory as pip and python are.
Also, check if you can import Seaborn when you are in a normal Python terminal.
This will help tracking down what part of this operation is the issue.
Spyder also has a console of its own. Try pip install seaborn in that terminal. Hopefully it will solve your problem.
I am having major trouble right now trying to use numpy in my jupyter notebook.
When I first tried to simply "import numpy", it came back with the error: "ModuleNotFoundError: No module named 'numpy'"
I then read somewhere that I probably needed to install numpy.
So I did this: "import sys
!conda install --yes --prefix {sys.prefix} numpy"
to which it came back saying: "EnvironmentLocationNotFound: Not a conda environment"
Now when it comes to understanding environments or packages or ANYTHING along those lines, I just have no idea what I'm doing. I am in a very beginner course and just following along.
I wish I could understand all of this environment and versioning stuff.
I have no idea where to go from here.
Any insight here would be GREATLY appreciated!!
Edit: I am in fact using Anaconda to launch Jupyter Notebook. Not sure if that means anything to your understanding of my problem or a potential solution.
Mark
For an easy to use graphical user interface to install Python libraries and manage environments, I would recommend Anaconda. It is well integrated with IPython and Jupyter Notebook in particular.
You could try the line bellow, at the notebook:
!pip install numpy
Or you could open up a terminal inside the jupyter notebook and install there, with:
pip install numpy
Another option is to install python3.7 from the anaconda website:
https://www.anaconda.com/distribution/
With anaconda a lot of packages come together when you install it. It's better for beginners. Good luck!
In my case, inside Jupyter notebook, you need to change Kernel (Anaconda environment). I thought you changed environment using conda activate myEnv, but when launching Jupyter, it defaults to the root environment.
I hope this is in fact true- I am a noob in Anaconda.
I run into this problem in the following picture while importing numpy into jupyter notebook.
Please help:
Here is print(sys.path):
Could you try print(sys.path)?
I have had trouble with jupyter and multiple instances of python in the past. pip installing to one python and running jupyter on another python.
(This should probably be a comment, but I can't comment)
Uninstall numpy('pip uninstall numpy') then again reinstall ('pip install numpy').