简体   繁体   中英

Can't import the installed package in Python3 environment of jupyter notebook

I have already installed the Anaconda software based on Python 2.7, and the Python 3.4 kernel has also been configured.

Using pip3 install xxx , I can install some packages for Python 3 environment. In ipython3, they can be imported well. However, in Python 3 kernel of jupyter notebook, those packages can't be successfully imported.

# Python 3 environment inside the jupyter notebook
import numpy as np
> No module named 'numpy'

My kernel path:

Available kernels:
  ir            /Users/HYF/Library/Jupyter/kernels/ir
  javascript    /Users/HYF/Library/Jupyter/kernels/javascript
  python2       /Users/HYF/anaconda/share/jupyter/kernels/python2
  python3       /usr/local/share/jupyter/kernels/python3

The Python3 environment in jupyter kernel shows like this:

import sys
sys.executable
>'/Users/HYF/anaconda/envs/py35/bin/python'

I thought the problem is that the python3 package path is not loaded in jupyter notebook. How to fix this issue?

Try by installing directly within Jupyter using the following command in a Jupyter cell:

import sys
!{sys.executable} -m pip install your_package_name

You need to activate your python3 environment prior to installing packages:

On the command line: source activate python3_environmane_name (or the name of your python3 environment.

Then you either conda install package_name , or, if not available via conda, pip install package_name , or pip3 install package_name .

Using pip3 in the python2 environment will not magically install anything in another env.

Note: to return to the default env, on command line: source deactivate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM