Issue
I want to import numpy and pandas in jupyter but I get the message:
----> 1 import pandas as pd
ModuleNotFoundError: No module named 'pandas'
Now when I open the anaconda prompt and do pip list
then I can see the latest version of numpy
Even when I say pip install
it says requirement already satisfied.
I know that this relates in some way to the PATH of python.
Honestly as someone from a math background learning how to code I'm really unsure what this means and how I can check and fix whether the Path is correct or not.
Does it just mean where jupyter looks for python.exe
? I dont know for sure where to check for this.
where python
in the Anaconda Prompt gives me:
C:\Users\MyName\Anaconda3\python.exe
C:\Program Files\Python37\python.exe
When I run this on the jupyter notebook:
from jupyter_core.paths import jupyter_data_dir
print(jupyter_data_dir())
I get:
C:\Users\NyName\AppData\Roaming\jupyter
Is this the source of the problem?
Solution
The problem is that your Jupyter kernel is using a different Python from the one in your Anaconda prompt.
If you don't use virtual environments, you should start. To make one, open an Anaconda prompt and do this (changing the name myenv
to whatever you like):
conda create -n myenv python=3.7 jupyter matplotlib pandas
Change the version of Python or the other packages too if you want.
When that's finished, switch to that environment:
conda activate myenv
Now do this:
python -m ipykernel install --user --name myenv
This adds a Jupyter kernel for this environment. You only need to do this once, after creating the environment.
Now restart Jupyter notebook or Jupyter lab or whatever. Or install more stuff in this environment if you want. You can just use pip
like so:
pip install awesomepackage
You should now see your environment under Kernel > Change kernel, and under New when making a new notebook.
Forgive me if you know all this, but this is the only way I've been able to keep environments straight, and to know exactly where I'm installing stuff. Good luck!
Answered By - Matt Hall
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.