Repository navigation
Broken with Python 3 and Ubuntu 18.04 #2922
Copy link
Copy link
Closed
Description
This is probably not a bug of Pipenv per se (virtualenv -p python3 had a similar issue), however opening just in case this helps someone.
Running the latest version of Python 3 and Ubuntu 18.04, I was getting the following error:
pipenv --python 3
Creating a virtualenv for this project...
Pipfile: /home/licensing/cimtas_certificate_requests/Pipfile
Using /usr/bin/python3 (3.6.5) to create virtualenv...
⠋Running virtualenv with interpreter /usr/bin/python3
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 25, in <module>
import distutils.spawn
ModuleNotFoundError: No module named 'distutils.spawn'
Error while trying to remove the /home/licensing/.local/share/virtualenvs/cimtas_certificate_requests-U5jN4dWL env:
No such file or directory
Virtualenv location:
Traceback (most recent call last):
File "/usr/local/bin/pipenv", line 11, in <module>
sys.exit(cli())
File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/click/core.py", line 1043, in invoke
return Command.invoke(self, ctx)
File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pipenv/cli.py", line 294, in cli
three=three, python=python, warn=True, site_packages=site_packages, pypi_mirror=pypi_mirror
File "/usr/local/lib/python2.7/dist-packages/pipenv/core.py", line 614, in ensure_project
path_to_python = which('python') or which('py')
File "/usr/local/lib/python2.7/dist-packages/pipenv/core.py", line 115, in which
p = os.path.join(location, 'bin', command)
File "/usr/lib/python2.7/posixpath.py", line 70, in join
elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'
For virtualenv - python3, I was getting the following, which helped me get to the bottom of the issue:
virtualenv -p python3 .venv
Running virtualenv with interpreter /usr/bin/python3
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 25, in <module>
import distutils.spawn
ModuleNotFoundError: No module named 'distutils.spawn'
Installing python3-distutils solved the issue.
Reacted by JZ-2018, Karan Singh Sisodia, Christian Arce, joeykrim, Saket Kumar, haosida123, Collin Joseph, Edison A, Chris Lenk, Ernie Hershey and 14 more
Reacted by Muhammad Bin Zafar
Reacted by Muhammad Bin Zafar
Reacted by Muhammad Bin Zafar
Metadata
Metadata
Assignees
Labels
No labels
Activity
uranusjr commentedon Oct 5, 2018
Actually it is not virtualenv either, it is Ubuntu. Their built-in Python is broken: https://bugs.launchpad.net/ubuntu/+source/apt-btrfs-snapshot/+bug/1763923
As a general rule: Don’t pip-install things to the system Python, almost ever. The system distribution sometimes introduces bugs we cannot anticipate, and cause unnecessary troubles.
uranusjr commentedon Oct 5, 2018
I believe this can be worked around by installing
python2-distutilsmanually.redliu312 commentedon Jan 22, 2019
I run into the same issue.
My os version is Ubuntu 18.04
When I tried to use
I got the same error.
I use
to solve this problem
ketozhang commentedon May 2, 2019
While @redliu312 is the most liked answer, it isn't the right answer. Everyone should be wary of pip installing anything to the system's python (it's owned by root
/usr/bin/python)Some of you may have a python installed in your user locations (e.g., Anaconda) and also run into the same error. Checking
pipenv installoutput for:If your path to Python isn't the path you wanted try recreating your environment via
pipenv --rmor removing allPipfile*(back upPipfileif needed). See #729.cclauss commentedon Nov 2, 2019
python3 -m pip install setuptoolsfix(ci): fix jenkins build pipeline by installing distutils
fix(ci): fix jenkins build pipeline by installing distutils
fix(ci): fix jenkins build pipeline by installing distutils
simonpojok commentedon Dec 25, 2019
This has worked for me thanks
leslie-alldridge commentedon Feb 7, 2020
should be
sudo, thanks though worked a treat!ri0t commentedon Feb 11, 2020
All the mentioned solutions are not working here.
"python2-distutils" does not exist here, at all. Upgrading python3-distutils to 3.8 didn't help either.
What did help in the end was this comment instructing to copy over distutils from 3.7 to 3.6... HtH someone :)
SurferJeffAtGoogle commentedon Feb 13, 2020
I tried all the remedies above and nothing worked. I built and installed python 3.6.8 from source, and that fixed the issue.
tomhamiltonstubber commentedon Apr 24, 2020
For those having this issue, removing and reinstalling python3, then reinstalling distutils as above fixed the issue.
This was after upgrading from 19.10 to 20.04 (not the smartest idea if you're stuck in the depths of countryside with a 1mb internet line btw).
vivekvardhanadepu commentedon Jul 18, 2020
Thanks a lot!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I spent whole day for this. In my case the issue was with dist-utils[see image]. When I updated all my python modules, I don't why, but, pip, of python 3.7.7, [both in virtual environment and real] was not working, although, of 3.8 was working fine. I tried all solutions online like reinstalling distutils, virtualenv, creating a new venv etc and above. But, nothing worked except YOUR SOLUTION
OS: Linux vpn 5.7.0-kali1-amd64 SMP Debian 5.7.6-1kali2 (2020-07-01) x86_64 GNU/Linux
virtualenv verison: 20.0.27
pip list:
Steps:
For restoring virtual environmently only:
virtualenv --python=python3.7 "name"Then you're good to go!!!
Successfully restored virtualenv without losing packages!!!!
hhowe29 commentedon Feb 17, 2021
Ran into this problem today on a clean install of Linux Lite, which is built on Ubuntu 20.04.2. I could create a virtual environment in python 3.8, but not with 3.7. Running
pipenv --python 3.7produced an import error:cannot import name 'dist' from 'distutils'sudo apt install python3-distutilsdid not fix the problem.apt install python3.7-distutilswas not found. Used these commands to debug.I fixed my error by adding the deadsnakes ppa to apt and installing python 3.7 from their packages. That gave me python 3.7.9, and now I can create virtual environments in both 3.7 and 3.8.
Running
apt list --installed | grep python3.7gives me this:H