Open aalok-sathe opened 2 years ago
poetry shell
starts a new shell and activates the virtual environment. Running deactivate
will deactivate the virtual environment but not close the shell. To close the shell run exit
. This link has more info. Poetry tracks whether the virtual environment is activated by tracking that the shell is still open. Maybe the message needs to be better.
if shell:
if activated:
print("Virtual environment already activated: ...")
else:
print("Poetry shell is already running and virtual environment is deactivated. Exit shell and run again.")
return 0
# create shell and activate venv
It's difficult to know if such a shell is active, and whether it is actually the poetry shell that is active or some other shell. Running exit
can be destructive, especially when there is a process such as screen
nesting your session, or when you are in ssh
. Then exit
will instead cause those contexts to disappear.
There should just be a good way to handle this cleanly within poetry
poetry shell
starts a new shell and activates the virtual environment. Runningdeactivate
will deactivate the virtual environment but not close the shell. To close the shell runexit
.
This should be more documented!
Finally I know what I need to do if I want the venv
to activate. That is fine.
If I do poetry shell
that informs me it's already activated, I press CTRL+D
and then poetry shell
Hallelluyah
This is a tricky business as we are very limited in what we can do to affect a parent process. Poetry starts a subshell as a compromise -- maybe we could print a message about it being a subshell when we spawn it.
Another feature worth considering is a poetry shell --export
that the user can source
to set the variables in their current shell.
I loved Poetry but this is a serious issue that needs to be solved. It should be easier to deactivate the environment running in the subprocess with a simple command outside of the shell. Instead I need to find the Python path and deactivate it manually: https://stackoverflow.com/questions/60580332/poetry-virtual-environment-already-activated
Also, huge bummer that I'm unable to run multiple of the same environments at once: https://stackoverflow.com/questions/70739858/how-to-create-a-brand-new-virtual-environment-or-duplicate-an-existing-one-in-po
Will be moving away from Poetry for now.
[x] I am on the latest Poetry version.
[x] I have searched the issues of this repo and believe that this is not a duplicate.
[x] If an exception occurs when executing a command, I executed it again in debug mode (
-vvv
option).OS version and name: Ubuntu 20.04
Poetry version: 1.1.13
Issue
Often times
poetry
keeps thinking I have a shell already activated, and I don't. This is widely reported by others too (#4622, python-poetry/poetry-plugin-shell#21, python-poetry/poetry#5050, python-poetry/poetry#3136). I also do not have any conda environment activated (not evenbase
). In this case, I am just forced to use the full path to thevenv
to run theactivate
script manually. I propose that we should be able to do this inpoetry
, when it inevitable fails to activate the venv, to--force
activate the environment, so that even if it is "already active" (not actually), it will still be "activated" (for the first time).Current output
Proposed Usage example: