Install library for jupyter notebook - python

I start my jupyter notebook with python2 as:
jupyter notebook nameofnotebook
Then I want to import library like this:
import scipy
But I have an error telling that there is no such library.
So I execute in the notebook cell:
!pip2 install scipy
Requirement already satisfied: scipy in /usr/local/lib/python2.7/dist-packages
How to install package correctly to jupyter kernel?

#håken-lid is right. There are probably several versions of python. So to install your package to python where your jupyter is located:
$ which jupyter
/YOURPATH/bin/jupyter
$ /YOURPATH/bin/pip install scipy
This will do for Python 2.x
For Python 3.x pip3 will be in /YOURPATH/bin instead of single pip

You can run pip from python.
import pip
pip.main(['install', 'scipy'])
If you are using the system python, and running jupyter in a process that doesn't have permission to install global packages, you can use the --user flag to install a module for the current user only.
pip.main(['install', '--user', 'scipy'])

Related

Jupyter notebook cannot import package already installed via pip

python 3.8.12 installed by pyevn seems working as expected, but numpy installed using pip cannot be imported.
pip --list ran in Jupiter notebook shows the package has been installed already.
So as per the path you stated in your comment (reply), execute this command:
/usr/local/opt/python#3.9/bin/python3.9 -m pip install pandas

pip commands not able to install packages successfully

I am unable to successfully install packages from pip commands in my jupyter notebook. Each time I use pip commands, it shows:
Example: pip install matplotlib
Requirement already satisfied: .....
WARNING: Ignoring invalid distribution -umpy(appdata\local\continuum\anaconda3\lib\site-packages)
WARNING: Ignoring invalid distribution -umpy(appdata\local\continuum\anaconda3\lib\site-packages)
WARNING: Ignoring invalid distribution -umpy(appdata\local\continuum\anaconda3\lib\site-packages)
I tried different commands like sudo, !, python -m pip. But nothing works. I am constantly getting
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
pip version: pip 21.2.4 from C:\Users\AppData\Local\Continuum\anaconda3\lib\site-packages\pip (python 3.7)
Use the direct pip of your python using the command:
my/path/to/python -m pip install matplotlib
Often pip is linked with python 2.7 if you have it.
Then pip3 is linked with your first python3 installation.
You have to use directly python -m pip to be sure you are installing modules in the right python directory.

no module name pmadarima

On installing pip install pmdarima via command prompt as admin, I get the below message as successful installation.
Requirement already satisfied: patsy>=0.5 in c:\users\username\appdata\local\programs\python\python39\lib\site-packages (from statsmodels!=0.12.0,>=0.11->pmdarima) (0.5.1)
But unable to work on it via Jupyter, get the below error on running
import pmdarima as pm
from pmdarima.model_selection import train_test_split
ModuleNotFoundError: No module named 'pmdarima'
When you do pip install, you're using your system's default python. You can have multiple versions of Python installed on the same computer.
For example, on my Mac if I do python in the terminal that opens Python 2. If I do python3 in the terminal, that opens Python 3.
When I do pip install numpy, it will install it to Python 2 by default. A program running in Python 3 will not be able to find that package.
To get it working for Python 3, I would do python3 -m pip install numpy. This uses the pip belonging to the right Python interpreter.
What is most likely happening here is that your Jupyter notebook is using a different Python interpreter. Try doing the install inside the notebook itself in a cell and that should work.

Can't install python libraries

got a new laptop (MacBook Air with Catalina) and installed python 3 thru Homebrew.
When trying to install and run some libraries in a jupyter notebook (also installed thru Homebrew) like:
!pip3 install pandas
and then:
import pandas as pd
I get the error:
ModuleNotFoundError: No module named 'pandas'
Same thing with numpy, matplotlib, bs4, etc. Even though when I rerun the !pip3 install something I get the message:
Requirement already satisfied: numpy in /usr/local/lib/python3.8/site-packages (1.19.2)
When I run:
!which python3
!which pip3
I get
/usr/local/bin/python3
/usr/local/bin/pip3
is there something I'm doing wrong?
I’ve catch like this problem
It helped me that:
Uninstall python
And install python
Then reboot system
I guess your Catalina use 3 version py3 this time
It’s need realias
I guess on Mac OS is better to use pip3 by terminal.
Problem seemed to be installing jupyter thru homebrew. Uninstalled it, and then reinstalled it with pip and now everything is working

How to install python dependency when using google-cloud-ml-engine notebook?

I am on google-cloud-ml notebook. Trying to install pandas_ml in order to import it.
I read https://cloud.google.com/ml-engine/docs/notebooks/dependencies tried both options (terminal and a separate installation notebook). None of those solutions work for me
#either
pip install pandas_ml #terminal
#or
!pip install pandas_ml #notebook
Solved!
since I'm using Python 3.5 I had to use pip3 instead of pip
!pip will install your packages on the system level and not in your notebook kernel. Try this instead:
import sys
!{sys.executable} -m pip3 install pandas_ml
Eventually, Google MLE notebooks will support %pip.
More information can be found on Jake VanderPlas's blog: Installing Python Packages from a Jupyter Notebook.

Categories