使用jupyter notebook所踩的坑

在学习机器学习过程中,作者遇到使用jupyter notebook时出现环境错误,原本以为是h5py未安装好,但通过PyCharm测试发现并非如此。错误提示显示notebook运行在不同的Python环境中。作者检查了环境路径,发现notebook运行在默认环境中。解决方案包括在默认环境安装缺失包(可能需要管理员权限)或在创建的环境中启动jupyter notebook。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在学习机器学习的时候,我使用了anaconda并自己创建了一个环境,在Prompt激活该环境,并输入jupyter notebook,并运行机器学习程序,结果出现以下错误。

ImportError                               Traceback (most recent call last)
<ipython-input-3-05f9803d8eb1> in <module>
      1 import numpy as np
      2 import matplotlib.pyplot as plt
----> 3 import h5py
      4 import scipy
      5 from PIL import Image

C:\ProgramData\Anaconda3\lib\site-packages\h5py\__init__.py in <module>
     34 _errors.silence_errors()
     35 
---> 36 from ._conv import register_converters as _register_converters
     37 _register_converters()
     38 

h5py\h5r.pxd in init h5py._conv()

h5py\_objects.pxd in init h5py.h5r()

h5py\_objects.pyx in init h5py._objects()

ImportError: DLL load failed: 找不到指定的程序。

注:我的环境是装在系统用户名目录下

我一开始以为h5py没安装好,于是打开pycharm测试

上网查找解决方案:

 

Usually that indicates that the notebook is running with a different Python or in a different environment from Python in the command prompt. Check `sys.executable` to see which Python it's running in, and `sys.path` to see where it's looking for imports.

发现h5py可以运行,检查运行的环境目录,发现jupyter notebook运行在默认的环境里

 

解决:

  1. 在jupyter notebook输入import sys,在输入sys.path检查一下环境(其实上面错误提示已经写了运行的环境目录了,这一步可以省略)
  2. 这里两种解决办法:

一是可以在默认环境安装缺失包,反正也不是很多,不过要注意默认环境可能在系统文件夹里面,要用到管理员权限打开才能正常安装,否则如下提示:

EnvironmentNotWritableError: The current user does not have write permissions to the target environment.  environment location: C:\ProgramData\Anaconda3

 二是在创建的环境用prompt运行下面语句

conda install nb_conda

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值