今天在研究图像处理时,使用到了tensorflow,在虚拟环境中使用
pip install tensorflow -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
时,程序在引入tensorfow后就报错,初步,根据日志推测应该是版本的问题
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/tensorflow/__init__.py", line 101, in <module>
from tensorflow_core import *
File "/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/tensorflow_core/__init__.py", line 42, in <module>
from . _api.v2 import audio
File "/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/tensorflow_core/_api/v2/audio/__init__.py", line 10, in <module>
from tensorflow.python.ops.gen_audio_ops import decode_wav
File "/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_audio_ops.py", line 10, in <module>
from tensorflow.python.eager import context as _context
File "/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/tensorflow_core/python/eager/context.py", line 29, in <module>
from tensorflow.core.protobuf import config_pb2
File "/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/tensorflow_core/core/protobuf/config_pb2.py", line 7, in <module>
from google.protobuf import descriptor as _descriptor
File "/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/google/protobuf/__init__.py", line 37, in <module>
__import__('pkg_resources').declare_namespace(__name__)
File "/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/pkg_resources/__init__.py", line 84, in <module>
__import__('pkg_resources.extern.packaging.requirements')
File "/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 9, in <module>
from pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
File "/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/pkg_resources/extern/__init__.py", line 43, in load_module
__import__(extant)
File "/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/pkg_resources/_vendor/pyparsing.py", line 4756, in <module>
_escapedPunc = Word( _bslash, r"\[]-*.$+^?()~ ", exact=2 ).setParseAction(lambda s,l,t:t[0][1])
File "/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/pkg_resources/_vendor/pyparsing.py", line 1284, in setParseAction
self.parseAction = list(map(_trim_arity, list(fns)))
File "/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/pkg_resources/_vendor/pyparsing.py", line 1066, in _trim_arity
this_line = extract_stack(limit=2)[-1]
File "/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/pkg_resources/_vendor/pyparsing.py", line 1050, in extract_stack
frame_summary = traceback.extract_stack(limit=-offset+limit-1)[offset]
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/traceback.py", line 211, in extract_stack
stack = StackSummary.extract(walk_stack(f), limit=limit)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/traceback.py", line 363, in extract
f.line
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/traceback.py", line 285, in line
self._line = linecache.getline(self.filename, self.lineno).strip()
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py", line 16, in getline
lines = getlines(filename, module_globals)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py", line 48, in getlines
for mod in sys.modules.values():
RuntimeError: dictionary changed size during iteration
>>>
解决方案如下
pip uninstall tensorflow
pip install tensorflow==2.0.0-alpha0 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
结果服务回归正常
>>> import tensorflow as tf
/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:523: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:524: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:532: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])
/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
/Users/icsoc/.virtualenvs/photo2cartoon/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])
>>> exit();