报错信息如下:
$ mkvirtualenv foobar -p /usr/bin/python3Already using interpreter /usr/bin/python3Using base prefix '/usr'New python executable in /home/isaac/.virtualenvs/foobar/bin/python3Also creating executable in /home/isaac/.virtualenvs/foobar/bin/pythonInstalling setuptools, pkg_resources, pip, wheel...done.[foobar] $ pip install djangoCollecting django Using cached Django-2.2.15-py3-none-any.whl (7.5 MB)Collecting pytz Using cached pytz-2020.1-py2.py3-none-any.whl (510 kB)Collecting sqlparse>=0.2.2 Using cached sqlparse-0.3.1-py2.py3-none-any.whl (40 kB)Installing collected packages: pytz, sqlparse, djangoSuccessfully installed django-2.2.15 pytz-2020.1 sqlparse-0.3.1[foobar] $ pythonPython 3.5.3 (default, Jul 9 2020, 13:00:10)[GCC 6.3.0 20170516] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import djangoTraceback (most recent call last): File "", line 1, in File "/home/isaac/.virtualenvs/foobar/lib/python3.5/site-packages/django/__init__.py", line 1, in from django.utils.version import get_version File "/home/isaac/.virtualenvs/foobar/lib/python3.5/site-packages/django/utils/version.py", line 6, in from distutils.version import LooseVersion File " ", line 969, in _find_and_load File " ", line 958, in _find_and_load_unlocked File " ", line 666, in _load_unlocked File " ", line 577, in module_from_spec File "/home/isaac/.virtualenvs/foobar/lib/python3.5/site-packages/_distutils_hack/__init__.py", line 82, in create_module return importlib.import_module('._distutils', 'setuptools') File "/home/isaac/.virtualenvs/foobar/lib/python3.5/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File " ", line 981, in _gcd_import File " ", line 931, in _sanity_checkSystemError: Parent module 'setuptools' not loaded, cannot perform relative import
1、通过将setuptools降级到49.3.0和将pip降到20.2.1来解决
pip install setuptools==49.3.0
pip install pip==20.2.1
参考文档:https://github.com/pypa/setuptools/issues/2352
2、临时解决方法
export SETUPTOOLS_USE_DISTUTILS=stdlib