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

标签 python python-3.x python-2.7 centos7 pythonpath

我的 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/

相关文章:

python - 我可以用数据框一次替换一些值吗?

python-2.7 - 如何使用 ctrl+c 停止 Tornado Web 服务器?

Python 使用 BOM 编写 UCS-2 Little Endian (utf-16-le) 文件

python - 如何将多迹线图制作为可重用代码?

python - 带有 stub 列表的 Pandas Wide_to_long

python - PyGTK 和 Visual-Python

python - 内存高效的 Python 批处理

python - 在大矩阵中找到满足特定条件的元素的所有索引给出 MemoryError

python - 对行值进行排序并显示列顺序

python - django:管理小部件CSS?