"This package should not be accessible on Python 3" when running python3

Question:

I was trying to use virtualenv to switch between python versions before learning that I could use both python and python3 on my Mac.

I was able to fix my python 2.7 version so that still works fine however, now when I run python3, I get this error:

Failed to import the site module
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 544, in <module>
main()
  File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
  File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 282, in addusersitepackages
user_site = getusersitepackages()
  File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 258, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
  File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 248, in getuserbase
USER_BASE = get_config_var('userbase')
  File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 601, in get_config_var
return get_config_vars().get(name)
  File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 580, in get_config_vars
import _osx_support
  File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_osx_support.py", line 4, in <module>
import re
  File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py", line 125, in <module>
import functools
  File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/functools.py", line 21, in <module>
from collections import namedtuple
  File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/collections/__init__.py", line 32, in <module>
from reprlib import recursive_repr as _recursive_repr
  File "/usr/local/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’ve looked online for this error but most of the conversation was on fixing up the patch and then upgrading virtualenv. However, this still doesn’t fix my issue.

python3 -V: Python 3.6.0
virtualenv --version: 15.1.0
env | egrep -i 'python|virtualenv': PYTHONPATH=/usr/local/lib/python2.7/site-packages:
Asked By: user1883614

||

Answers:

Your environment contains PYTHONPATH=/usr/local/lib/python2.7/site-packages

This doesn’t work with Python 3 for obvious reasons. To remove it:

unset PYTHONPATH
Answered By: Charles Duffy

I solved my problem with below command

sudo pip install virtualenv --upgrade
virtualenv -p python3 env
Answered By: anjaneyulubatta505
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.