无法导入Tensorflow“没有名为copyreg的模块”
python
tensorflow
4
0

El Capitan OS在这里。我一直在尝试找到将Tensorflow导入我的ipython笔记本的解决方法,但到目前为止还没有运气。

像论坛中的许多人一样,由于有六个软件包,我也遇到了安装tensorflow的问题。经过一番烦恼之后,我得以安装

brew link gdbm
brew install python
rew linkapps python
sudo pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl

我收到一条消息,指示tensorflow已正确安装。即使我做了sudo pip install tensorflow我也得到消息:

Requirement already satisfied (use --upgrade to upgrade): tensorflow in /usr/local/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): six>=1.10.0 in /Library/Python/2.7/site-packages (from tensorflow)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.9.2 in /usr/local/lib/python2.7/site-packages (from tensorflow)

但是,当我在ipython笔记本上执行import tensorflow ,会收到消息: ImportError: No module named tensorflow

我进一步进行了挖掘,并在导入时也发现了此错误:

In [1]: import tensorflow
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-a649b509054f> in <module>()
----> 1 import tensorflow

/usr/local/lib/python2.7/site-packages/tensorflow/__init__.py in <module>()
      2 # module.
      3 # pylint: disable=wildcard-import
----> 4 from tensorflow.python import *

/usr/local/lib/python2.7/site-packages/tensorflow/python/__init__.py in <module>()
     11 
     12 import tensorflow.python.platform
---> 13 from tensorflow.core.framework.graph_pb2 import *
     14 from tensorflow.core.framework.summary_pb2 import *
     15 from tensorflow.core.framework.config_pb2 import *

/usr/local/lib/python2.7/site-packages/tensorflow/core/framework/graph_pb2.py in <module>()
      6 from google.protobuf import descriptor as _descriptor
      7 from google.protobuf import message as _message
----> 8 from google.protobuf import reflection as _reflection
      9 from google.protobuf import symbol_database as _symbol_database
     10 from google.protobuf import descriptor_pb2

/usr/local/lib/python2.7/site-packages/google/protobuf/reflection.py in <module>()
     56   from google.protobuf.pyext import cpp_message as message_impl
     57 else:
---> 58   from google.protobuf.internal import python_message as message_impl
     59 
     60 # The type of all Message classes.

/usr/local/lib/python2.7/site-packages/google/protobuf/internal/python_message.py in <module>()
     57 
     58 import six
---> 59 import six.moves.copyreg as copyreg
     60 
     61 # We use "as" to avoid name collisions with variables.

ImportError: No module named copyreg
参考资料:
Stack Overflow
收藏
评论
共 1 个回答
高赞 时间 活跃

正如乔纳(Jonah)所说,这可以通过以下方式解决:

在MacOSX上

如果遇到:

import six.moves.copyreg as copyreg
ImportError: No module named copyreg

解决方案:TensorFlow取决于protobuf,它需要6-1.10.0。苹果的默认python环境具有六个1.4.1,可能很难升级。因此,我们建议您通过自制软件安装单独的python副本:

brew install python

但我强烈建议为此目的使用virtualenv。

# On Mac:
$ sudo easy_install pip  # If pip is not already installed
$ sudo pip install --upgrade virtualenv

接下来,设置一个新的virtualenv环境。要将其设置在~/tensorflow目录中,请运行:

$ virtualenv --system-site-packages ~/tensorflow
$ cd ~/tensorflow

然后激活virtualenv:

$ source bin/activate  # If using bash
$ source bin/activate.csh  # If using csh
(tensorflow)$  # Your prompt should change

在virtualenv内部,安装TensorFlow:

(tensorflow)$ pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl

然后,您可以运行TensorFlow程序,如下所示:

(tensorflow)$ python tensorflow/models/image/mnist/convolutional.py

# When you are done using TensorFlow:
(tensorflow)$ deactivate  # Deactivate the virtualenv

$  # Your prompt should change back
收藏
评论
新手导航
  • 社区规范
  • 提出问题
  • 进行投票
  • 个人资料
  • 优化问题
  • 回答问题

关于我们

常见问题

内容许可

联系我们

@2020 AskGo
京ICP备20001863号