Keras,numpy,tensorflow不适用于spyder,juptyer,可以在python

时间:2018-04-18 09:28:44

标签: python numpy tensorflow jupyter spyder

我已经从我找到的whl文件中为GPU安装了tensorflow。它是1.5.0版本。

我还安装了keras和matplotlib。 我认为numpy是从其中一个模块安装的。

当我尝试从spyder或jupyter中运行python时几乎没有任何作用,但是一切都可以从控制台运行python。

导入tensorflow spyder时不知道这个模块是什么。

runfile('D:/LearnANN/untitled2.py', wdir='D:/LearnANN')
Traceback (most recent call last):

  File "<ipython-input-1-ecb61dbb011d>", line 1, in <module>
    runfile('D:/LearnANN/untitled2.py', wdir='D:/LearnANN')

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "D:/LearnANN/untitled2.py", line 8, in <module>
    import tensorflow

ModuleNotFoundError: No module named 'tensorflow'

导入numpy或keras或matplotlib

runfile('D:/LearnANN/untitled2.py', wdir='D:/LearnANN')
Traceback (most recent call last):

  File "<ipython-input-2-ecb61dbb011d>", line 1, in <module>
    runfile('D:/LearnANN/untitled2.py', wdir='D:/LearnANN')

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "D:/LearnANN/untitled2.py", line 8, in <module>
    import numpy

  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
    from . import add_newdocs

  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc

  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
    from .type_check import *

  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx

  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 26, in <module>
    raise ImportError(msg)

ImportError: 
Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

Original error was: DLL load failed: The specified module could not be found.

在控制台上运行python scriptName.py时,所有这些模块都可用并且正常工作。

我在窗户上。

如何为jupyter / spyder修复此问题?

2 个答案:

答案 0 :(得分:0)

你应该在激活virtualenv之后和virtualenv内部调用Jupyter / Spyder。只有这样才会引用本地安装的库。 你可以通过运行

来激活virtualenv
  

actiavte

然后使用

安装tensorflow
  

pip install tensorflow

安装TensorFlow后,从virtualenv内部运行spyder / jupyter notebook,如下所示

enter image description here

使用以下行创建一个新的.py文件,以检查要引用的TensorFlow

import tensorflow
print(tensorflow.__file__)

答案 1 :(得分:0)

如果您在Windows上使用 Jupyter笔记本,请尝试以下操作:

  1. 使用anaconda提示符/命令提示符,使用 conda create -n YOUR_ENV_NAME python = 3.6
  2. 创建虚拟环境
  3. 源激活YOUR_ENV_NAME
  4. conda安装ipykernel
  5. ipython内核安装--name YOUR_ENV_NAME --user

完成后,从Jupyter笔记本启动您的python代码 选择内核->更改内核-> YOUR_ENV_NAME

您可以在此环境中安装tensorflow和其他软件包,