为什么python3.4试图在RedHat7上加载python2.7 TensorFlow包?

为什么python3.4试图在RedHat7上加载python2.7 TensorFlow包?,python,python-2.7,python-3.x,tensorflow,Python,Python 2.7,Python 3.x,Tensorflow,我的RedHat7机器上同时安装了python2.7和python3.4。我为这两个版本安装了tensorflow P2.7似乎工作正常: Python 2.7.5 (default, Oct 11 2015, 17:47:16) [GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>

我的RedHat7机器上同时安装了python2.7和python3.4。我为这两个版本安装了
tensorflow

P2.7似乎工作正常:

Python 2.7.5 (default, Oct 11 2015, 17:47:16) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import site; site.getsitepackages()
['/usr/lib64/python2.7/site-packages', '/usr/lib/python2.7/site-packages', '/usr/lib/site-python']
>>> import tensorflow
>>> 
对于p3.4,我得到:

Python 3.4.3 (default, Jan 26 2016, 02:25:35) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import site; site.getsitepackages()
['/usr/lib64/python3.4/site-packages', '/usr/lib/python3.4/site-packages', '/usr/lib/site-python']
>>> import tensorflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/tensorflow/__init__.py", line 23, in <module>
    from tensorflow.python import *
  File "/usr/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 48, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/usr/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/usr/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
  File "/usr/lib64/python3.4/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
ImportError: /usr/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so: undefined symbol: PyClass_Type
>>> 
看到下面的街区

...
import 'types' # <_frozen_importlib.SourceFileLoader object at 0x7fd5b3e7e8d0>
import 'site' # <_frozen_importlib.SourceFileLoader object at 0x7fd5b3f4bba8>
# code object from /usr/lib/python2.7/site-packages/tensorflow/__init__.py
# could not create '/usr/lib/python2.7/site-packages/tensorflow/__pycache__/__init__.cpython-34.pyc': PermissionError(13, 'Permission denied')
# wrote '/usr/lib/python2.7/site-packages/tensorflow/__pycache__/__init__.cpython-34.pyc'
# /usr/lib64/python3.4/__pycache__/__future__.cpython-34.pyc matches /usr/lib64/python3.4/__future__.py
# code object from '/usr/lib64/python3.4/__pycache__/__future__.cpython-34.pyc'
import '__future__' # <_frozen_importlib.SourceFileLoader object at 0x7fd5b3ea04e0>
# code object from /usr/lib/python2.7/site-packages/tensorflow/python/__init__.py
# could not create '/usr/lib/python2.7/site-packages/tensorflow/python/__pycache__/__init__.cpython-34.pyc': PermissionError(13, 'Permission denied')
# wrote '/usr/lib/python2.7/site-packages/tensorflow/python/__pycache__/__init__.cpython-34.pyc'
...
但我仍然得到以下信息:

import 'imp' # <_frozen_importlib.SourceFileLoader object at 0x7fb372a1f320>
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/usr/lib/python2.7/site-packages/tensorflow/__init__.py", line 23, in <module>
    from tensorflow.python import *
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/usr/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 48, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "<frozen importlib._bootstrap>", line 2284, in _handle_fromlist
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/usr/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/usr/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
  File "/usr/lib64/python3.4/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
ImportError: /usr/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so: undefined symbol: PyClass_Type
# clear builtins._
# clear sys.path
有没有可能是
pip3
不正常,指向p2.7而不是p3.4?也就是说,我认为TF安装的一部分是安装
numpy
,在将其导入p3.4时,我没有收到任何错误,因此可能还有其他问题

更新#4:我已经要求我们的系统管理员(最初为我安装了TF)在他这边运行
python3-v-c'import tensorflow'
命令。他的结果与我的不同:python3拉取正确的库,TF加载良好。以下是我的日志摘录:

# /usr/lib/python2.7/site-packages/tensorflow/__pycache__/__init__.cpython-34.pyc matches /usr/lib/python2.7/site-packages/tensorflow/__init__.py
# code object from '/usr/lib/python2.7/site-packages/tensorflow/__pycache__/__init__.cpython-34.pyc'
# /usr/lib/python2.7/site-packages/tensorflow/python/__pycache__/__init__.cpython-34.pyc matches /usr/lib/python2.7/site-packages/tensorflow/python/__init__.py
# code object from '/usr/lib/python2.7/site-packages/tensorflow/python/__pycache__/__init__.cpython-34.pyc'
以下是他的:

# /usr/lib/python3.4/site-packages/tensorflow/__pycache__/__init__.cpython-34.pyc matches /usr/lib/python3.4/site-packages/tensorflow/__init__.py
# code object from '/usr/lib/python3.4/site-packages/tensorflow/__pycache__/__init__.cpython-34.pyc'
# /usr/lib/python3.4/site-packages/tensorflow/python/__pycache__/__init__.cpython-34.pyc matches /usr/lib/python3.4/site-packages/tensorflow/python/__init__.py
# code object from '/usr/lib/python3.4/site-packages/tensorflow/python/__pycache__/__init__.cpython-34.pyc'

PYTHONPATH
既不是为他定义的,也不是为我定义的。那么为什么python对我们的工作方式不同呢?

sys.path
中列出的任何目录中都没有符号链接?@MartijnPieters我在所有目录上运行了
ls-lR
。有一个很长的列表,但我没有看到任何链接。下一步尝试:
python3-v-c'import tensorflow'
。这可能会提供一些线索。您是如何安装Python3.4的?您是如何安装tensorflow的?什么是
/usr/lib/site python
?对我来说就像一个符号链接。
# Ubuntu/Linux 64-bit, CPU only, Python 3.4
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp34-cp34m-linux_x86_64.whl
sudo pip3 install --upgrade $TF_BINARY_URL
# /usr/lib/python2.7/site-packages/tensorflow/__pycache__/__init__.cpython-34.pyc matches /usr/lib/python2.7/site-packages/tensorflow/__init__.py
# code object from '/usr/lib/python2.7/site-packages/tensorflow/__pycache__/__init__.cpython-34.pyc'
# /usr/lib/python2.7/site-packages/tensorflow/python/__pycache__/__init__.cpython-34.pyc matches /usr/lib/python2.7/site-packages/tensorflow/python/__init__.py
# code object from '/usr/lib/python2.7/site-packages/tensorflow/python/__pycache__/__init__.cpython-34.pyc'
# /usr/lib/python3.4/site-packages/tensorflow/__pycache__/__init__.cpython-34.pyc matches /usr/lib/python3.4/site-packages/tensorflow/__init__.py
# code object from '/usr/lib/python3.4/site-packages/tensorflow/__pycache__/__init__.cpython-34.pyc'
# /usr/lib/python3.4/site-packages/tensorflow/python/__pycache__/__init__.cpython-34.pyc matches /usr/lib/python3.4/site-packages/tensorflow/python/__init__.py
# code object from '/usr/lib/python3.4/site-packages/tensorflow/python/__pycache__/__init__.cpython-34.pyc'