gpt4 book ai didi

python - 每次当我想使用多个 python 版本中的 python3 时,都需要取消设置 PYTHONPATH

转载 作者:太空宇宙 更新时间:2023-11-03 20:04:58 24 4
gpt4 key购买 nike

我的 Centos7 中安装了多个 python 版本。

[root@madcodlab-centos7 ~]# python
Python 2.7.16 (default, May 24 2019, 21:44:39)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
[root@madcodlab-centos7 ~]# python3
Python 3.6.8 (default, Aug 7 2019, 17:28:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

但是我无法正常访问python3。在访问 python3 之前,我总是必须设置unset PYTHONPATH,但这并不能永久解决我的问题。当我从我的 vps 注销并再次登录后,我无法访问 python3。看起来这只是一个临时修复。这是我想访问python3时的错误

[root@madcodlab-centos7 ~]# python3                                                                                                                                               
Error processing line 1 of /usr/local/lib64/python3.6/site-packages/zope.interface-4.6.0-py3.6-nspkg.pth:

Failed to import the site module
Traceback (most recent call last):
File "/usr/lib64/python3.6/site.py", line 168, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "/usr/lib64/python3.6/types.py", line 171, in <module>
import functools as _functools
File "/usr/lib64/python3.6/functools.py", line 21, in <module>
from collections import namedtuple
File "/usr/lib64/python3.6/collections/__init__.py", line 32, in <module>
from reprlib import recursive_repr as _recursive_repr
File "/usr/lib/python2.7/site-packages/reprlib/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib64/python3.6/site.py", line 564, in <module>
main()
File "/usr/lib64/python3.6/site.py", line 551, in main
known_paths = addsitepackages(known_paths)
File "/usr/lib64/python3.6/site.py", line 339, in addsitepackages
addsitedir(sitedir, known_paths)
File "/usr/lib64/python3.6/site.py", line 207, in addsitedir
addpackage(sitedir, name, known_paths)
File "/usr/lib64/python3.6/site.py", line 178, in addpackage
import traceback
File "/usr/lib64/python3.6/traceback.py", line 3, in <module>
import collections
File "/usr/lib64/python3.6/collections/__init__.py", line 32, in <module>
from reprlib import recursive_repr as _recursive_repr
File "/usr/lib/python2.7/site-packages/reprlib/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.

我尝试使用virtualenv来解决这个问题

sudo pip install virtualenv --upgrade
virtualenv -p python3 env

但就我而言并不能解决问题。

我可以做什么来永久修复它?

谢谢

最佳答案

虚拟环境是必经之路...

但是你可以只输入 python3 fred.py - 然后事情也应该没问题

关于python - 每次当我想使用多个 python 版本中的 python3 时,都需要取消设置 PYTHONPATH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59018490/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com