使用jupyter notebook所踩的坑

在学习机器学习的时候,我使用了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运行在默认的环境里

 

使用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