简体   繁体   English

导入张量流时出错:NameError: name 'python' 未定义

[英]Error importing tensorflow: NameError: name 'python' is not defined

I'm trying to import Tensorflow using Spyder, I previously also tried to import Keras and Theano, but there was an error: module "theano" has no attribute "compile" and the import of Tensorflow was alright.我正在尝试使用 Spyder 导入 Tensorflow,我之前也尝试过导入 Keras 和 Theano,但是出现错误: module "theano" has no attribute "compile"并且 Tensorflow 的导入没问题。

To solve that I installed为了解决我安装

conda install tensor

With that I solved the problem with Keras and Theano, but now Tensorflow doesn't import, shows me the follow error:我用 Keras 和 Theano 解决了这个问题,但现在 Tensorflow 没有导入,显示了以下错误:

import tensorflow
Traceback (most recent call last):

  File "<ipython-input-9-d6579f534729>", line 1, in <module>
    import tensorflow

  File "C:\Users\rodmo\Anaconda3\envs\py35\lib\site-
  packages\tensorflow\__init__.py", line 50, in <module>
    del python

NameError: name 'python' is not defined

PROBLEM SOLVED!!问题解决了!!

Set parameter in system properties ---> Advanced --->Environment Variables--->System variables--->New..在系统属性中设置参数--->高级--->环境变量--->系统变量--->新建..

Variable - MKL_THREADING_LAYER变量 - MKL_THREADING_LAYER

Value - GNU价值 - GNU

Image - Instruction图像 - 说明

I'd be willing to bet that the "module 'theano' has no attribute 'compile'" would be solved by using a different version of the Theano module.我敢打赌,“模块‘theano’没有属性‘编译’”将通过使用不同版本的 Theano 模块来解决。 Usually when I get an error like that it's because the code that's importing it depends on a specific version that has subsequently been changed.通常,当我收到这样的错误时,是因为导入它的代码取决于随后已更改的特定版本。

For the conda stuff, conda doesn't install to your base python directory, so if your pythonpath is pointing to somewhere else, it may spell trouble.对于 conda 的东西,conda 不会安装到你的基本 python 目录,所以如果你的 pythonpath 指向其他地方,它可能会带来麻烦。 Can you post what version of theano you were running?您可以发布您正在运行的 theano 版本吗?

In [1]: import theano
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.

In [2]: theano.compile?
Type:        module
String form: <module 'theano.compile' from '/home/micheal.taylor/.virtualenvs/tensorflow_test/lib/python2.7/site-packages/theano/compile/__init__.pyc'>
File:        ~/.virtualenvs/tensorflow_test/lib/python2.7/site-packages/theano/compile/__init__.py
Docstring:   <no docstring>

In [3]: theano.__version__
Out[3]: u'1.0.1'

For me it is working by leaving open the anaconda prompt.对我来说,它是通过打开 anaconda 提示来工作的。 Before that I have changed the json file to 'KERAS_BACKEND=tensorflow'在此之前,我已将 json 文件更改为 'KERAS_BACKEND=tensorflow'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM