Python 版本不匹配:模块是为 Python 3.6 编译的,但解释器版本不兼容:3.9.8
Posted
技术标签:
【中文标题】Python 版本不匹配:模块是为 Python 3.6 编译的,但解释器版本不兼容:3.9.8【英文标题】:Python version mismatch: module was compiled for Python 3.6, but the interpreter version is incompatible: 3.9.8 【发布时间】:2022-01-04 06:50:55 【问题描述】:为了安装最新的tensorflow
(2.7.0),我将我的python3
版本从3.6.6
更新为3.9.8
。这是我在 docker 中的操作方法!!。
Download the Python-3.9.8.tgz file
1. tar -xf Python-3.9.8.tgz
2. cd Python-3.9.8 & ./configure --enable-optimizations
3. make -j 12
4. make altinstall
我的python3 --version
是Python 3.9.8
。但是,当我尝试通过import tensorflow.compat.v1 as tf
加载最新的tf
时。错误来了:
File "/workspaces/model/task.py", line 120, in new_model_test
import model_api
File "/lfs/biomind/model_tmp/19bddfc44e8211ecbe172d8a58f5e38e/wmh_v2/model_api.py", line 3, in <module>
import tensorflow.compat.v1 as tf
File "/usr/local/lib/python3.6/site-packages/tensorflow/__init__.py", line 99, in <module>
from tensorflow_core import *
File "/usr/local/lib/python3.6/site-packages/tensorflow_core/__init__.py", line 28, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/usr/local/lib/python3.6/site-packages/tensorflow/__init__.py", line 50, in __getattr__
module = self._load()
File "/usr/local/lib/python3.6/site-packages/tensorflow/__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/usr/local/lib/python3.6/site-packages/tensorflow_core/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python3.6/site-packages/tensorflow_core/python/pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/tensorflow_core/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/local/lib/python3.6/site-packages/tensorflow_core/python/pywrap_tensorflow_internal.py", line 2453, in <module>
from tensorflow.python.util import deprecation
File "/usr/local/lib/python3.6/site-packages/tensorflow_core/python/util/deprecation.py", line 25, in <module>
from tensorflow.python.platform import tf_logging as logging
File "/usr/local/lib/python3.6/site-packages/tensorflow_core/python/platform/tf_logging.py", line 38, in <module>
from tensorflow.python.util.tf_export import tf_export
File "/usr/local/lib/python3.6/site-packages/tensorflow_core/python/util/tf_export.py", line 48, in <module>
from tensorflow.python.util import tf_decorator
File "/usr/local/lib/python3.6/site-packages/tensorflow_core/python/util/tf_decorator.py", line 64, in <module>
from tensorflow.python.util import tf_stack
File "/usr/local/lib/python3.6/site-packages/tensorflow_core/python/util/tf_stack.py", line 29, in <module>
from tensorflow.python import _tf_stack
ImportError: Python version mismatch: module was compiled for Python 3.6, but the interpreter version is incompatible: 3.9.8 (main, Nov 25 2021, 21:54:13)
[GCC 7.5.0].
有没有办法改变Python
的编译版本,或者我做了一些不正确的事情?提前致谢。
【问题讨论】:
【参考方案1】:对于我的问题,问题从File "/usr/local/lib/python3.6/site-packages/tensorflow/__init__.py"
开始。虽然我安装了Python3.9
,python search python3.6
lib 也是如此。解决方法很简单:删除/usr/local/lib/python3.6/
【讨论】:
以上是关于Python 版本不匹配:模块是为 Python 3.6 编译的,但解释器版本不兼容:3.9.8的主要内容,如果未能解决你的问题,请参考以下文章