ModuleNotFoundError: No module named 'pandas' on Jupyter Notebook - python

I'm running my Jupyter Notebook in a virtual environment.
I've installed pandas in it with pip3 install pandas (I've tried with sudo python3 -m pip install pandas in other venv and without sudo, too, like this other post suggests)
I've tried doing
export PYTHONPATH=/home/myuser/Notebooks/venv/lib/python3.8/site-packages
but the error remains (I've restarted the notebook kernel, as well). Any idea?

Maybe your are not installing pandas into the virtual environment correctly.
If you have access to a shell, you can possibly cd into the .venv folder.
Then you can run source ./bin/activate, after this there should be a (.venv) prefix in your shell window.
Now run your pip3 install pandas commando once again, this time it will install pandas into your virtual environment instead of your global python environment.

Installing packages from Notebook running this cell:
! pip install --user numpy
! pip install --user pandas
changing the kernel reselecting Python3 in Kernel -> Change kernel and restarting it, the problem was fixed!

Related

Issue with Jupyter notebook and virtual environment pip

I have created a virtual environment using the following commands:
python3 -m venv venv
.\venv\Scripts\activate.bat
pip3 install ipykernel
pip3 install jupyter
python3 -m ipykernel install --user --name=venv
I have created a Jupyter notebook using the venv that I created, but when I install a package in the virtual environment, it is not recognised in the notebook.
For example, I tried to install pandas using pip3 install pandas, but when I try and import it into my notebook I get the error ModuleNotFoundError: No module named 'pandas'
The module has installed in the right place venv\Lib\site-packages\pandas\
Any ideas on what I should do?
EDIT:
I noticed that even though I created the notebook using the venv, it uses the normal python environment rather than the virtual one. Ideas on how to fix this?
Well I think I solved it. If ran the following command:
python -c "import IPython"
Which just installs IPython in my venv.
You need to restart the notebook kernel, it will probably work then.
In the future, in a notebook cell you can run
%%bash
pip install pandas
then you should be able to continue without restarting

How to make Jupyter Notebook import packages in Python3.5

I have several packages being imported perfectly in my Python 3.5. But not in my Jupyter Notebook... When i try to Import those packages in Jupyter i get and error of module not found.
Is there a way to make Jupyter load my Python 3.5 as a kernel... or something similar. I'm working in a virtual environment. Already tried to reinstall the packages again in my virtual env But no success.
Try to install the packages inside a jupyter notebook cell like this:
!pip install package
So you are sure that the packages are installed in jupyter's environment
If you install the ipython kernel form inside the virtualenv, you can guarantee that the packages are imported to the jupyter if they are imported to this env. Also, if you use this approach, you do not need to activate the virtualenv every time you run the jupyter, because jupyter does it automatically.
$ python -m venv projectname
$ source projectname/bin/activate
(venv) $ pip install ipykernel
(venv) $ ipython kernel install --user --name=projectname
(venv) $ pip install {package needed to install}
Source: Using jupyter notebooks with a virtual environment

Install python packages on Jupyter Notebook

I am trying to install 2 python packages on Anaconda Jupyter Notebook. The links to the python packages are as follow:
1) https://iapws.readthedocs.io/en/latest/modules.html
2) https://pythonhosted.org/thermopy/iapws.html#module-thermopy.iapws
But I am getting the following error on both installations. Can anyone tell me what is wrong?
Through Anaconda you should write this on your Jupyter notebook :
# Install a conda package in the current Jupyter kernel
import sys
!conda install --yes --prefix {sys.prefix} packagename
With a normal install of python you should write this on your Jupyter notebook :
# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install packagename
By replacing packagename with the name of your package like numpy.
Cheers
Your Jupyter notebook server does not have access to internet. You operating system might have a firewall or limit internet access to third party applications, especially since this is a work laptop.
Regardless, it is easy to install components using pip. If you cannot access the internet from inside the notebook, try opening a Command Prompt as admin and simply type pip install iapws.

How to link virutualenvwrapper with Jupyter notebook

I have a venv/virtualenvwrapper set up in a directory. After I start working on the venv, i then create a Jupyter notebook inside of the directory, which brings me to Jupyter's localhost browser. I then attempt to import a library, e.g. pandas, which raises the ModuleNotFoundError. I would think that if the venv is being worked on, Jupyter would link to it.
Also, I can import global libraries from pip3, just not the local ones in a venv. Is there a way to use the virtualenvwrapper library with Jupyter?
I found out here I had to install ipykernel after activating the venv, then create a projectname:
​(venv) $ pip install ipykernel
(venv) $ ipython kernel install --user --name=projectname
​
After that, I went back to the Jupyter browser and change the kernel from python 3 to the projectname which is only viewable after executing the second command line above.
This works for both virtualenv and virutalenvwrapper.
The only downfall is installing ipykernel adds a lot of extra libraries to your venv pip3, but I suppose you could just install ipykernel in your global pip3 to keep from installing it in your venv.

Jupyter doesn't work when "setup.py" is used

I tried to install Jupyter on my Mac (10.9).
Since I'm using a computer at the university and don't have permission to write in /usr/local/bin, I downloaded Ipython from GitHub and typed python3.4 setup.py install --user on Terminal.
Though I didn't get any error while installing, Jupyter does not launch when I type ipython notebook (ipython3 notebook or jupyter were the same) and I got command not found error.
(I also tried to install via pip. However, pip does not work on my computer and I couldn't activate it using ensurepip.)
Why does pip not work? (insufficient privileges to write into system packages)?
Have you tried a virtual environments Creation of virtual environments? They are very useful for managing your environment so that you have local packages and a local bin folder for things like ipython:
$ python3 -m venv my_venv
$ source my_venv/bin/activate
$ pip install ipython[all]
This will install into your my_venv environment.

Categories

Resources