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']   # 用黑体显示中文
相关推荐
kaizq9 分钟前
AI-MCP-SQLite-SSE本地服务及CherryStudio便捷应用
python·sqlite·llm·sse·mcp·cherry studio·fastmcp
!chen2 小时前
Error: error:0308010C:digital envelope routines::unsupporte
python
小北方城市网2 小时前
分布式锁实战指南:从选型到落地,避开 90% 的坑
java·数据库·redis·分布式·python·缓存
xiaolyuh1232 小时前
【XXL-JOB】 GLUE模式 底层实现原理
java·开发语言·前端·python·xxl-job
likuolei2 小时前
Spring AI框架完整指南
人工智能·python·spring
二哈喇子!3 小时前
PyTorch生态与昇腾平台适配:环境搭建与详细安装指南
人工智能·pytorch·python
Learner3 小时前
Python数据类型(三):列表和元组
开发语言·python
世界唯一最大变量3 小时前
用自创的算法快速解决拉姆奇数
python
leluckys3 小时前
AI- 一种快速实现MCP服务的方法
开发语言·python
写代码的【黑咖啡】3 小时前
探索 Python 中的 Vaex:高效处理大规模数据的新选择
开发语言·python