Prompt before recreating a broken virtualenv
See original GitHub issue- I have searched the issues of this repo and believe that this is not a duplicate.
- I have searched the documentation and believe that my question is not covered.
Feature Request
When poetry
detects a broken virtual environment it will currently delete it and recreate it. While that’s great, this operation is destructive. In such cases, it would be best to prompt the user before to ensure they are okay with this happening (at least in an interactive context).
It would also be useful to add more details as to what prompts poetry
to think that the virtual environment is broken so that the user may try to manually fix the issue.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Broken references in Virtualenvs - python - Stack Overflow
I applied this solution, followed by running: virtualenv . in my broken virtual environment. The updated version of virtualenv then recreated the necessary ......
Read more >Broken virtual environments: Why it happened and how I ...
When activating the previously affected venv, and running the python interpreter I am greeted with version 3.8.11 rather than 3.9.5. My ...
Read more >venv — Creation of virtual environments — Python 3.11.1 ...
A virtual environment is created on top of an existing Python installation, known as the virtual environment's “base” Python, and may optionally be...
Read more >Python virtualenv and venv dos and don'ts - InfoWorld
Python virtual environments shine for keeping projects and conflicting packages separate. Just keep these dos and don'ts in mind.
Read more >Rebuilding a Virtualenv - PythonAnywhere help
1) Use a requirements.txt file to record what packages you're using¶ · 2) Remove your old virtualenv¶. Using plain virtualenvs: · 3) Create...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think Poetry’s behavior here is correct. Poetry relies on Virtualenv, which has no built-in mechanism for re-initializing / re-installing / repairing existing environments. So the only reliable option is to remove and re-create the environment. If your virtual environment is missing
python
orpip
, something is seriously wrong with it, and it shouldn’t be Poetry’s job to try to perform surgery on it. It needs to be replaced.Having just written a new feature for VirtualFish that can upgrade or re-create virtual environments, I have a bit of experience with this topic. Unlike Poetry, this feature checks to make sure the environment’s Python functions correctly, and if not, the broken environment is discarded and a new one is created. I chose not to prompt users when this happens precisely because environments should be ephemeral.
In the past, I would sometime store project-specific files in virtual environments, such as Git clones in
$VIRTUAL_ENV/src
or self-signed TLS keys, and I would be annoyed when those artifacts were lost when re-creating the virtual environment. I have since learned the value of not putting anything into virtual environments and treating them as the truly ephemeral structures they were meant to be. So I think Poetry’s current behavior of not prompting users before re-creating virtual environments is correct and should not be changed.That said, my implementation will look for a
trash
executable on$PATH
and use it if found, in which case the operation is not destructive — if needed, the discarded environment can be retrieved from the workstation’s trash.Salvaging virtual environments are inherently a bad idea. I do not think we shoud, alleast by default, prompt if we detect a broken virtual environment.
This might be significantly better in
1.1.0
with parallel installs and also with enhancements to how the local cache is used. This might be a moot point even with 200 dependencies. It would be great to get some numbers either validation or invalidating this assumption.Then again I feel that if 5/10 minutes lost is better than time lost debugging why an enviornment failed and then fixing it.
A potential compromise might be an option like below, that needs to be explicitly disabled.
This could trigger either a prompt or better yet raise an error.