The other day I was working on a Dockerfile based on a Debian distro. I noticed that if you only have python, pip and setuptools, when running poetry install, Poetry starts building a Python virtualenv at $HOME/.cache/pypoetry/virtualenvs, but it fails midway because of this error:
Creating virtualenv app-py3.5 in /root/.cache/pypoetry/virtualenvs
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt-get install python3-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: ['/root/.cache/pypoetry/virtualenvs/app-py3.5/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
If you happen to install python3-venv afterwards, and do poetry install again, you get this:
Using virtualenv: /root/.cache/pypoetry/virtualenvs/app-py3.5
[FileNotFoundError]
[Errno 2] No such file or directory: 'pip'
Exception trace:
/usr/local/lib/python3.5/dist-packages/cleo/application.py in run() at line 94
status_code = self.do_run(input_, output_)
/usr/local/lib/python3.5/dist-packages/poetry/console/application.py in do_run() at line 87
return super(Application, self).do_run(i, o)
/usr/local/lib/python3.5/dist-packages/cleo/application.py in do_run() at line 197
status_code = command.run(input_, output_)
/usr/local/lib/python3.5/dist-packages/poetry/console/commands/command.py in run() at line 72
return super(BaseCommand, self).run(i, o)
/usr/local/lib/python3.5/dist-packages/cleo/commands/base_command.py in run() at line 146
status_code = self.execute(input_, output_)
/usr/local/lib/python3.5/dist-packages/cleo/commands/command.py in execute() at line 107
return self.handle()
/usr/local/lib/python3.5/dist-packages/poetry/console/commands/install.py in handle() at line 34
self.poetry.pool,
/usr/local/lib/python3.5/dist-packages/poetry/installation/installer.py in __init__() at line 56
installed = self._get_installed()
/usr/local/lib/python3.5/dist-packages/poetry/installation/installer.py in _get_installed() at line 514
return InstalledRepository.load(self._venv)
/usr/local/lib/python3.5/dist-packages/poetry/repositories/installed_repository.py in load() at line 17
freeze_output = venv.run("pip", "freeze")
/usr/local/lib/python3.5/dist-packages/poetry/utils/venv.py in run() at line 271
cmd, stderr=subprocess.STDOUT, **kwargs
/usr/lib/python3.5/subprocess.py in check_output() at line 316
**kwargs).stdout
/usr/lib/python3.5/subprocess.py in run() at line 383
with Popen(*popenargs, **kwargs) as process:
/usr/lib/python3.5/subprocess.py in __init__() at line 676
restore_signals, start_new_session)
/usr/lib/python3.5/subprocess.py in _execute_child() at line 1282
raise child_exception_type(errno_num, err_msg)
The only way to fix this is to delete the whole directory at $HOME/.cache/pypoetry/virtualenvs/app-py3.5 before running poetry install again. This not only happened to me on a Docker container, I had the same thing happen on a new Ubuntu machine that didn't have virtualenv installed when I tried using Poetry.
Here is a gist with a Dockerfile and steps on how to reproduce bug.
I will try looking into it, although I'm not sure how Poetry should handle this. Perhaps it should do the ensurepip check in a previous instance?
It's probable that this PR https://github.com/sdispater/poetry/pull/262 would fix this issue.
I'm having the same error (from a slightly different setup: poetry is installed itself in a venv), and replacing the direct calls to the "pip" command to "python -m pip" did fix this error.
Why is it that poetry itself doesn't install venv? It seems like it should...
@sdispater I've run the docker file provided by @munshker and this is still an issue.
This seems to qualify as a bug but PR #262 could fix this. Do you want me to take a look at the PR once again (since you've already done it)? The test of #262 is failing as well so we might have to ask the PR author to fix those.
PR #262 fix the issue.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Closing this issue automatically because it has not had any activity since it has been marked as stale. If you think it is still relevant and should be addressed, feel free to open a new one.
confirm this issue on Poetry version 1.0.0
I also just ran into it:
acerl@research-library-2020:~/acerl$ poetry --version
Poetry version 1.0.0
acerl@research-library-2020:~/acerl$ poetry install
Installing dependencies from lock file
Package operations: 71 installs, 0 updates, 0 removals
- Installing pytz (2016.3)
[FileNotFoundError]
[Errno 2] No such file or directory: 'pip': 'pip'
I had only pip3 on that system (Debian 10).
pip3 install --user -U pip fixed it, but I needed to delete and recreate the venv directory.
This was my error:
Creating virtualenv xxxxxxxxxx-bQgWWZ0z-py3.8 in /home/xxxxxxxxx/.cache/pypoetry/virtualenvs
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.apt-get install python3-venvYou may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.Failing command: ['/home/xxxxxxxxxx/.cache/pypoetry/virtualenvs/xxxxxxxxxx-bQgWWZ0z-py3.8/bin/python', '-Im', 'ensurepip', '--upgrade', '--default-pip']
Simply installing python3-venv did not work.
I had to install a version of python3-venv specific to my Python version for Poetry to create a non-broken virtual environment:
sudo apt-get install python3.8-venv
Most helpful comment
This was my error:
Simply installing python3-venv did not work.
I had to install a version of python3-venv specific to my Python version for Poetry to create a non-broken virtual environment: