Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken with Python 3 and Ubuntu 18.04 #2922

Closed
ustun opened this issue Oct 5, 2018 · 12 comments
Closed

Broken with Python 3 and Ubuntu 18.04 #2922

ustun opened this issue Oct 5, 2018 · 12 comments

Comments

@ustun
Copy link

ustun commented Oct 5, 2018

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.

@uranusjr
Copy link
Member

uranusjr commented 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 uranusjr closed this as completed Oct 5, 2018
@uranusjr
Copy link
Member

uranusjr commented Oct 5, 2018

I believe this can be worked around by installing python2-distutils manually.

@redliu312
Copy link

I run into the same issue.
My os version is Ubuntu 18.04
When I tried to use

pipenv --python 3

I got the same error.
I use

sudp apt-get install python3-distutils

to solve this problem

@ketozhang
Copy link

ketozhang commented 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 install output for:

$ pipenv install
...
Using /path/to/python (<some_version>) to create virtualenv...

If your path to Python isn't the path you wanted try recreating your environment via pipenv --rm or removing all Pipfile* (back up Pipfile if needed). See #729.

@cclauss
Copy link
Contributor

cclauss commented Nov 2, 2019

python3 -m pip install setuptools

burnedikt added a commit to Innoactive/ansible-innoactive-portal-role that referenced this issue Dec 4, 2019
burnedikt added a commit to Innoactive/ansible-innoactive-portal-role that referenced this issue Dec 4, 2019
burnedikt added a commit to Innoactive/ansible-innoactive-portal-role that referenced this issue Dec 4, 2019
@simonpojok
Copy link

I run into the same issue.
My os version is Ubuntu 18.04
When I tried to use

pipenv --python 3

I got the same error.
I use

sudp apt-get install python3-distutils

to solve this problem

This has worked for me thanks

@leslie-alldridge
Copy link

sudp apt-get install python3-distutils

should be sudo , thanks though worked a treat!

@ri0t
Copy link

ri0t commented Feb 11, 2020

All the mentioned solutions are not working here.

python3.6:
  Installed: 3.6.7-1
python3-distutils:
  Installed: 3.7.3-1
python-distutils-extra:
  Installed: 2.42

"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
Copy link

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
Copy link

tomhamiltonstubber commented 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
Copy link

I tried all the remedies above and nothing worked. I built and installed python 3.6.8 from source, and that fixed the issue.

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:

Package                      Version
---------------------------- --------------
absl-py                      0.9.0
AdvancedHTTPServer           2.2.0
aiodns                       2.0.0
alembic                      1.4.2
aniso8601                    7.0.0
appdirs                      1.4.4
asgiref                      3.2.10
asn1crypto                   1.3.0
astroid                      2.3.3
astunparse                   1.6.3
atomicwrites                 1.4.0
attrs                        19.3.0
Automat                      20.2.0
Babel                        2.8.0
backcall                     0.2.0
basemap                      1.2.1
bcrypt                       3.1.7
beautifulsoup4               4.9.1
binwalk                      2.2.0
bleach                       3.1.5
blinker                      1.4
boltons                      20.2.0
bottle                       0.12.18
Brlapi                       0.7.0
Brotli                       1.0.7
cachetools                   4.1.1
cbor                         1.0.0
certifi                      2020.6.20
cffi                         1.14.0
Chameleon                    3.8.1
chardet                      3.0.4
click                        7.1.2
click-plugins                1.1.1
colorama                     0.4.3
constantly                   15.1.0
cryptography                 2.9.2
cupshelpers                  1.0
cycler                       0.10.0
dbus-python                  1.2.16
decorator                    4.4.2
defusedxml                   0.6.0
deluge                       2.0.3
deprecation                  2.1.0
dicttoxml                    1.7.4
distlib                      0.3.1
distro                       1.5.0
distro-info                  0.23
Django                       3.0.8
dnslib                       0.9.14
dnspython                    2.0.0
ecdsa                        0.15
email-validator              1.1.1
entrypoints                  0.3
et-xmlfile                   1.0.1
faraday-plugins              1.2
filedepot                    0.5.2
filelock                     3.0.12
filteralchemy                0.1.0
flasgger                     0.9.4
Flask                        1.1.2
Flask-BabelEx                0.9.4
Flask-Classful               0.14.1
Flask-KVSession-fork         0.6.3
Flask-Login                  0.5.0
Flask-Mail                   0.9.1
Flask-Principal              0.4.0
Flask-RESTful                0.3.8
Flask-Restless               0.17.0
Flask-Security               3.0.0
Flask-Session                0.3.1
Flask-SQLAlchemy             2.4.0
Flask-WTF                    0.14.3
future                       0.18.2
gast                         0.3.3
GeoIP                        1.3.2
geoip2                       2.9.0
geojson                      2.5.0
gevent                       1.4.0
google-auth                  1.18.0
google-auth-oauthlib         0.4.1
google-pasta                 0.2.0
gpg                          1.13.1-unknown
graphene                     2.1.7
graphene-sqlalchemy          2.1.2
graphql-core                 2.3.2
graphql-relay                2.0.1
greenlet                     0.4.15
grequests                    0.4.0
grpcio                       1.30.0
h11                          0.9.0
h2                           3.2.0
h5py                         2.10.0
hashID                       3.1.4
hiredis                      1.0.1
hpack                        3.0.0
html2text                    2020.1.16
html5lib                     1.0.1
httplib2                     0.18.1
hupper                       1.10.2
hyperframe                   5.2.0
hyperlink                    19.0.0
icalendar                    4.0.3
idna                         2.10
impacket                     0.9.21
importlib-metadata           1.6.0
incremental                  16.10.1
IPy                          1.0
ipykernel                    5.3.1
ipython                      7.16.1
ipython-genutils             0.2.0
ipywidgets                   6.0.0
isort                        4.3.21
itsdangerous                 1.1.0
jdcal                        1.0
jedi                         0.17.0
Jinja2                       2.11.2
jsonschema                   3.2.0
jupyter-client               6.1.3
jupyter-core                 4.6.3
kaitaistruct                 0.8
Keras                        2.4.3
Keras-Preprocessing          1.1.2
KismetCaptureFreaklabsZigbee 2018.7.0
KismetCaptureRtl433          2019.9.1
KismetCaptureRtladsb         2019.10.1
KismetCaptureRtlamr          2019.10.1
kiwisolver                   1.0.1
lazy-object-proxy            1.4.3
ldap3                        2.7
ldapdomaindump               0.9.1
louis                        3.14.0
lxml                         4.5.0
lz4                          3.0.2+dfsg
Mako                         1.1.3
Markdown                     3.2.2
MarkupSafe                   1.1.1
marshmallow                  3.6.1
marshmallow-sqlalchemy       0.19.0
matplotlib                   3.2.2
maxminddb                    1.4.1
mccabe                       0.6.1
mechanize                    0.4.5
meld                         3.20.2
mimerender                   0.6.0
mistune                      0.8.4
mitmproxy                    5.1.1
more-itertools               4.2.0
msgpack                      0.6.2
nassl                        3.0.0
nbconvert                    5.6.1
nbformat                     5.0.7
netaddr                      0.7.19
notebook                     6.0.3
nplusone                     1.0.0
numexpr                      2.7.1
numpy                        1.18.4
oauthlib                     3.1.0
olefile                      0.46
openpyxl                     2.4.9
opt-einsum                   3.2.1
packaging                    20.4
pandas                       0.25.3
pandocfilters                1.4.2
paramiko                     2.6.0
parso                        0.7.0
passlib                      1.7.2
Paste                        3.4.1
PasteDeploy                  2.1.0
pbr                          5.4.5
pefile                       2019.4.18
pexpect                      4.6.0
pickleshare                  0.7.5
Pillow                       6.2.1
pip                          20.1.1
plaster                      1.0
plaster-pastedeploy          0.5
plotly                       4.7.1
pluggy                       0.13.0
pluginbase                   1.0.0
ply                          3.11
prettytable                  0.7.2
prometheus-client            0.7.1
promise                      2.3
prompt-toolkit               3.0.5
protobuf                     3.11.4
psycopg2                     2.8.5
publicsuffix2                2.20191221
py                           1.8.1
py-ubjson                    0.14.0
pyasn1                       0.4.2
pyasn1-modules               0.2.1
pycairo                      1.16.2
pycares                      3.1.1
pycparser                    2.20
pycrypto                     2.6.1
pycryptodomex                3.9.7
pycups                       1.9.73
pycurl                       7.43.0.2
pydot                        1.4.1
pyelftools                   0.26
pygame                       1.9.6
Pygments                     2.3.1
PyGObject                    3.36.0
PyHamcrest                   1.9.0
pyinotify                    0.9.6
pylint                       2.4.4
pymssql                      2.1.4
PyNaCl                       1.4.0
PyOpenGL                     3.1.5
pyOpenSSL                    19.1.0
pyotp                        2.3.0
pyparsing                    2.4.7
pypcapfile                   0.12.1
pyperclip                    1.8.0
pyproj                       2.6.1
PyQRCode                     1.2.1
PyQt5                        5.15.0
pyqtgraph                    0.11.0
pyramid                      1.10.4
pyrsistent                   0.15.5
pyserial                     3.4
pyshp                        2.1.0
PySimpleSOAP                 1.16.2
pysmbc                       1.0.22
PySocks                      1.6.8
pytest                       4.6.11
python-apt                   2.1.3
python-dateutil              2.8.1
python-debian                0.1.37
python-debianbts             3.0.2
python-distutils-extra       2.39
python-editor                1.0.4
python-libtorrent            1.2.5
python-magic                 0.4.16
python-mimeparse             1.6.0
python-pam                   1.8.4
python-snappy                0.5.3
PyTrie                       0.2
pytz                         2020.1
pyxdg                        0.26
PyYAML                       5.3.1
pyzmq                        18.1.1
qrcode                       6.1
redis                        3.3.11
rencode                      1.0.6
reportbug                    7.7.0
repoze.lru                   0.7
requests                     2.23.0
requests-file                1.5.1
requests-oauthlib            1.3.0
retrying                     1.3.3
rq                           1.4.0
rsa                          4.6
ruamel.yaml                  0.16.10
ruamel.yaml.clib             0.2.0
rule-engine                  1.1.0
Rx                           1.6.1
scapy                        2.4.3
scipy                        1.4.1
Send2Trash                   1.5.0
service-identity             18.1.0
setproctitle                 1.1.10
setuptools                   46.1.3
shodan                       1.23.0
simplejson                   3.17.0
simplekv                     0.13.0
sip                          4.19.23
six                          1.15.0
smoke-zephyr                 2.0.0
sortedcontainers             2.1.0
soupsieve                    2.0.1
speaklater                   1.3
SQLAlchemy                   1.3.18
sqlalchemy-schemadisplay     1.3
sqlparse                     0.3.1
sslyze                       3.0.8
stanza                       1.0.0
stevedore                    1.32.0
syslog-rfc5424-formatter     1.2.2
tables                       3.6.1
Tempita                      0.5.2
tensorboard                  2.2.2
tensorboard-plugin-wit       1.7.0
tensorflow                   2.2.0
tensorflow-estimator         2.2.0
termcolor                    1.1.0
terminado                    0.8.2
testpath                     0.4.4
texttable                    1.6.2
theHarvester                 3.1.0
tls-parser                   1.2.2
torch                        1.5.0
tornado                      5.1.1
tqdm                         4.43.0
traitlets                    4.3.3
translationstring            1.3
Twisted                      18.9.0
txaio                        20.4.1
typing-extensions            3.7.4.2
tzlocal                      2.1b1
u-msgpack-python             2.3.0
unattended-upgrades          0.1
unicodecsv                   0.14.1
Unidecode                    1.1.1
urllib3                      1.25.9
urwid                        2.1.0
venusian                     3.0.0
virtualenv                   20.0.27
wafw00f                      2.1.0
waitress                     1.4.1
wcwidth                      0.1.9
webargs                      6.1.0
webencodings                 0.5.1
WebOb                        1.8.6
websocket-client             0.53.0
WebTest                      2.0.34
Werkzeug                     1.0.0
wfuzz                        2.4.5
wheel                        0.34.2
widgetsnbextension           2.0.0
wifite                       2.5.5
wrapt                        1.11.2
wsproto                      0.15.0
WTForms                      2.2.1
xlrd                         1.1.0
XlsxWriter                   1.1.2
xlwt                         1.3.0
yara-python                  3.10.0
zipp                         1.0.0
zope.component               4.3.0
zope.deprecation             4.4.0
zope.event                   4.4
zope.hookable                5.0.1
zope.interface               4.7.1

Steps:

  1. As said[in my case it is 3.7.7] remove python 3.7.7 and reinstall from scratch. Refer https://realpython.com/installing-python/ [follow all the steps impeccably]

For restoring virtual environmently only:

  1. create new venv
    virtualenv --python=python3.7 "name"
  2. replace the python3.7 folder[in venv_name/lib] with your original one.

Then you're good to go!!!

Successfully restored virtualenv without losing packages!!!!

Screenshot from 2020-07-18 18-41-09

@hhowe29
Copy link

hhowe29 commented 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.7 produced an import error: cannot import name 'dist' from 'distutils'

sudo apt install python3-distutils did not fix the problem. apt install python3.7-distutils was not found. Used these commands to debug.

>python3.8 --version
Python 3.8.5
>python3.8 -c "from distutils import dist;print('success')"
success

> python3.7 --version
Python 3.7.6
> python3.7 -c "from distutils import dist;print('success')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'dist' from 'distutils' (/usr/lib/python3.7/distutils/__init__.py)

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.

sudo add-apt-repository -y ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.7 python3.7-dev

Running apt list --installed | grep python3.7 gives me this:

libpython3.7-dev/focal,now 3.7.9-1+focal1 amd64 [installed,automatic]
libpython3.7-minimal/focal,now 3.7.9-1+focal1 amd64 [installed]
libpython3.7-stdlib/focal,now 3.7.9-1+focal1 amd64 [installed]
libpython3.7/focal,now 3.7.9-1+focal1 amd64 [installed,automatic]
python3.7-dev/focal,now 3.7.9-1+focal1 amd64 [installed]
python3.7-distutils/focal,focal,now 3.7.9-1+focal1 all [installed,automatic]
python3.7-lib2to3/focal,focal,now 3.7.9-1+focal1 all [installed,automatic]
python3.7-minimal/focal,now 3.7.9-1+focal1 amd64 [installed]
python3.7/focal,now 3.7.9-1+focal1 amd64 [installed]

H

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests