我在使用Python和Tensorflow时遇到了一个奇怪的错误。当我尝试运行我的代码时,我收到此消息,但是我敢肯定我已经安装了Tensorflow,并且以前运行正常。
我从here下载了代码。我第一次尝试使用它,其余的尝试都没有用。我尝试了太多事情(例如新环境,不同版本的Tensorflow等,但我无法使其正常工作。)
这是我的Anaconda Spyder输出:
from __future__ import absolute_import, division, print_function
# Import TensorFlow >= 1.9 and enable eager execution
import tensorflow as tf
#tf.enable_eager_execution()
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
import unicodedata
import re
import numpy as np
import os
import time
print(tf.__version__)
Traceback (most recent call last):
File "<ipython-input-5-22177e76b58e>", line 4, in <module>
import tensorflow as tf
File "C:\Users\ismetb\Anaconda3\envs\google_nmt\lib\site-packages\tensorflow\__init__.py", line 594, in <module>
del python
NameError: name 'python' is not defined
这是我的Anaconda提示符输出:
(google_nmt) C:\Users\ismetb\Desktop\google_nmt>python google.py
Traceback (most recent call last):
File "google.py", line 10, in <module>
import tensorflow as tf
File "C:\Users\ismetb\Anaconda3\envs\google_nmt\lib\site-packages\tensorflow\__init__.py", line 22, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\ismetb\Anaconda3\envs\google_nmt\lib\site-packages\tensorflow\python\__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "C:\Users\ismetb\Anaconda3\envs\google_nmt\lib\site-packages\tensorflow\core\framework\graph_pb2.py", line 6, in <module>
from google.protobuf import descriptor as _descriptor
File "C:\Users\ismetb\Anaconda3\envs\google_nmt\lib\site-packages\google\protobuf\__init__.py", line 37, in <module>
__import__('pkg_resources').declare_namespace(__name__)
File "C:\Users\ismetb\Anaconda3\envs\google_nmt\lib\site-packages\pkg_resources\__init__.py", line 3086, in <module>
@_call_aside
File "C:\Users\ismetb\Anaconda3\envs\google_nmt\lib\site-packages\pkg_resources\__init__.py", line 3070, in _call_aside
f(*args, **kwargs)
File "C:\Users\ismetb\Anaconda3\envs\google_nmt\lib\site-packages\pkg_resources\__init__.py", line 3114, in _initialize_master_working_set
for dist in working_set
File "C:\Users\ismetb\Anaconda3\envs\google_nmt\lib\site-packages\pkg_resources\__init__.py", line 3114, in <genexpr>
for dist in working_set
File "C:\Users\ismetb\Anaconda3\envs\google_nmt\lib\site-packages\pkg_resources\__init__.py", line 2637, in activate
declare_namespace(pkg)
File "C:\Users\ismetb\Anaconda3\envs\google_nmt\lib\site-packages\pkg_resources\__init__.py", line 2174, in declare_namespace
_handle_ns(packageName, path_item)
File "C:\Users\ismetb\Anaconda3\envs\google_nmt\lib\site-packages\pkg_resources\__init__.py", line 2109, in _handle_ns
loader.load_module(packageName)
File "C:\Users\ismetb\Desktop\google_nmt\google.py", line 24, in <module>
print(tf.__version__)
AttributeError: module 'tensorflow' has no attribute '__version__'
这也发生在我同事的一台笔记本电脑上。他第一次尝试我使它起作用,并且在其余尝试中该代码始终无法运行。
可能是什么问题?