jupyter notebook 导入已经在pycharm里pip install过的包报错

1. 问题描述

: 当我每天都在cmd/Terminal等地方pip install我的python lib时,打开Jupyter notebook 发现,有一些包明明在电脑里有,比如torch, searborn之类的,在jupyter notebook 里import 对应包确报错,找不到这些包

2. 处理方法

查看平时pip install 的lib文件目录
在jupyter notebook 的cell里面输入:

import site
site.getsitepackages()

运行上面代码,得到输出,将输出的类似于python\lib\site-packages这个文件目录添加到当前系统文件夹

import sys
sys.path.append('D:\\Program Files\\Python3.64\\Lib\\site-packages')

再次导入报错的包,发现不再报错


Jupyter Notebook 常用import

# Ignore future warnings from pandas
import warnings
warnings.filterwarnings('ignore')

# Required libraries
# Importing the libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
plt.style.use('fivethirtyeight')
matplotlib.rcParams['font.sans-serif']=['SimHei']   # 用黑体显示中文

你可能感兴趣的:(jupyter,pip,python)