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

Discussão em 'Python' iniciado por Stack, Novembro 30, 2024.

  1. Stack

    Stack Membro Participativo

    I have multiple python versions installed into my Centos7.

    [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. Before I access python3 I always have to set unset PYTHONPATH but it doesn't fix my problem permanently. After I logged out from my vps and log in again I can not access python3. It looks it just a temporary fix. Here is the error when I want to access 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

    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?

    Continue reading...

Compartilhe esta Página