`install-poetry.py`: ModuleNotFoundError: No module named 'virtualenv'
See original GitHub issue-
I am on the latest Poetry version.
-
I have searched the issues of this repo and believe that this is not a duplicate.
-
[N/A] If an exception occurs when executing a command, I executed it again in debug mode (
-vvv
option). -
OS version and name: Ubuntu 18.04 WSL
-
Poetry version: N/A
-
Link of a Gist with the contents of your pyproject.toml file: N/A
-
install-poetry.py
version: 9e17159
I originally posted this at https://github.com/python-poetry/poetry/issues/4195#issuecomment-894313710, but later realized that my situation was different from that issue, so I decided to copy that comment to a seperate issue.
I searched the issues and found python-poetry/install.python-poetry.org#61 which was related, but that post didn’t fully cover the issue. ensurepip
is not available for the system python
in Ubuntu, and the correct way to install system pip
can vary among ditros. Additionally, the wheel of virtualenv
does not contain its dependencies, and thus poetry has to provide a version of virtualenv
with all of its dependencies vendorized.
Below is my original comment, with a little editing. If my solution would be accepted, I would be willing to make a PR to implement it.
Issue
python3 install-poetry.py
fails with ModuleNotFoundError: No module named 'virtualenv'
.
At first it was because of pip
not being installed by default for the system python, but after sudo apt install python3-pip
the problem persisted.
Then I tried installing virtualenv
manually to see what was going on:
$ mktemp -d
/tmp/tmp.YuayGzcNwi
$ python3 -m pip install virtualenv -t /tmp/tmp.YuayGzcNwi
[unrelated logs omitted]
Exception:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 360, in run
prefix=options.prefix_path,
File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/usr/lib/python3/dist-packages/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/usr/lib/python3/dist-packages/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/usr/lib/python3/dist-packages/pip/wheel.py", line 247, in move_wheel_files
prefix=prefix,
File "/usr/lib/python3/dist-packages/pip/locations.py", line 153, in distutils_scheme
i.finalize_options()
File "/usr/lib/python3.6/distutils/command/install.py", line 274, in finalize_options
raise DistutilsOptionError("can't combine user with prefix, "
distutils.errors.DistutilsOptionError: can't combine user with prefix, exec_prefix/home, or install_(plat)base
But if I use a newer version of pip
, virtualenv
can be successfully installed:
$ mktemp -d
/tmp/tmp.4j1OAffTGx
$ python3.9 -m pip install virtualenv -t /tmp/tmp.4j1OAffTGx
[unrelated logs omitted]
Installing collected packages: six, platformdirs, filelock, distlib, backports.entry-points-selectable, virtualenv
Successfully installed backports.entry-points-selectable-1.1.0 distlib-0.3.2 filelock-3.0.12 platformdirs-2.2.0 six-1.16.0 virtualenv-20.7.0
$ python3 -m pip -V # system python with system pip
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
$ python3.9 -m pip -V
pip 21.2.3 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
And with this version of pip
, poetry
can be successfully installed:
$ curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python3.9 -
[unrelated logs omitted]
Poetry (1.1.7) is installed now. Great!
You can test that everything is set up by executing:
`poetry --version`
$ poetry --version
Poetry version 1.1.7
So there are three problems with install-poetry.py
:
- It assumes that
pip
is installed. - It assumes that an up-to-date
pip
is installed. - The
pip install
error message is suppressed.
One possible solution to the first and second problems: provide a version of virtualenv
with all of its dependency vendorized, and let the script download this version of virtualenv directly instead of using pip
.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (1 by maintainers)
@Skyross are you executing
poetry install --no-dev
in the same environment as you installedpoetry
in? In that case this is expected behaviour.The new version of poetry does not rely on
virtualenv
from the environment anymore.You can also try one of the following options.Option 1 - Use a virtual environment
Option 2 - Use pipx*
@christopherpickering the isue you are facing is due to missing build time dependencies for
cffi
as this is in the dependency tree for Poetry and is not available as a wheel compatible with your environment.poetry-install-error.log
You can avoid this by installing the required build dependencies.
We no longer expect pip to be present in the environment. We however, require that if the
venv
module is present (unlike ubuntu distro) with your python installation, for it to addpip
to an virtual environment it creates, If thevenv
module is not present, we now fallback to thevirtualenv
zipapp instead. (#4099)Given all of the above. I am going to close this. For future issues about the installer, use https://github.com/python-poetry/install.python-poetry.org/issues.
The subprocess should probably check if pip is installed first… maybe something like this:
but its still broken for python3 on linux.