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里面输入:

python 复制代码
import site
site.getsitepackages()

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

python 复制代码
import sys
sys.path.append('D:\\Program Files\\Python3.64\\Lib\\site-packages')

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


Jupyter Notebook 常用import

python 复制代码
# 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']   # 用黑体显示中文
相关推荐
用户2519162427116 小时前
Python之语言特点
python
刘立军6 小时前
使用pyHugeGraph查询HugeGraph图数据
python·graphql
数据智能老司机10 小时前
精通 Python 设计模式——创建型设计模式
python·设计模式·架构
数据智能老司机11 小时前
精通 Python 设计模式——SOLID 原则
python·设计模式·架构
c8i12 小时前
django中的FBV 和 CBV
python·django
c8i12 小时前
python中的闭包和装饰器
python
这里有鱼汤15 小时前
小白必看:QMT里的miniQMT入门教程
后端·python
TF男孩1 天前
ARQ:一款低成本的消息队列,实现每秒万级吞吐
后端·python·消息队列
该用户已不存在1 天前
Mojo vs Python vs Rust: 2025年搞AI,该学哪个?
后端·python·rust
站大爷IP1 天前
Java调用Python的5种实用方案:从简单到进阶的全场景解析
python