11

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?

1
  • 1
    There might be multiple versions of python installed. Try import sys; print(sys.path); to see where the running jupyter python kernel is looking for installed modules. Commented Jun 28, 2017 at 10:57

2 Answers 2

5

@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

Sign up to request clarification or add additional context in comments.

Comments

2

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']) 

2 Comments

It provides the error AttributeError: 'module' object has no attribute 'main'
It's no longer recommended to use pip as a module. pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.