question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Poetry creates a broken virtualenv if python3-venv is not installed after running poetry install

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
LaundroMatcommented, Feb 17, 2020

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-venv

You 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
5reactions
nottrobincommented, Dec 6, 2018

Why is it that poetry itself doesn’t install venv? It seems like it should…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Poetry creates a broken virtualenv if python3-venv is ... - GitHub
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.
Read more >
The virtual environment found seems to be broken | python ...
Go to your project directory and start Poetry (if you're not already there); get rid of the broken virtual environment, · Leave Poetry...
Read more >
beeware/general - Gitter
After installing the python3-venv package, recreate your virtual environment. ... Now, when I try to run poetry install , I get the following:...
Read more >
poetry config virtualenvs.create false - You.com | The AI ...
There seems to be an issue running poetry install when: poetry updates the certifi package; config virtualenvs.create is set to false.
Read more >
Managing environments | Documentation - Poetry
Poetry makes project environment isolation one of its core features. What this means is that it will always work isolated from your global...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found