简体   繁体   English

每次我想使用来自多个 python 版本的 python3 时都需要取消设置 PYTHONPATH

[英]Need to unset PYTHONPATH every time when I want to use python3 from multiple python versions

I have multiple python versions installed into my Centos7.我的 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.
>>>

But I cannot access python3 normally.但是我无法正常访问python3。 Before I access python3 I always have to set unset PYTHONPATH but it doesn't fix my problem permanently.在我访问 python3 之前,我总是必须设置unset PYTHONPATH但它不能永久解决我的问题。 After I logged out from my vps and log in again I can not access python3.从我的 vps 注销并再次登录后,我无法访问 python3。 It looks it just a temporary fix.看起来只是临时修复。 Here is the error when I want to access 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.

I tried to solve this by using virtualenv我试图通过使用virtualenv来解决这个问题

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

but in my case doesn't solve the problem.但在我的情况下并不能解决问题。

What can I do to fix it permanently?我该怎么做才能永久修复它?

thanks谢谢

Virtual Env is the way to go ...虚拟环境是要走的路......

But you could just type python3 fred.py - and things then should be ok also但是你可以只输入python3 fred.py - 然后事情也应该没问题

就我而言,我能够通过在 $HOME/.bashrc 文件中注释掉export PYTHONPATH命令来修复它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM