Activating the virtual environment
The easiest way to activate the virtual environment is to create a new shell with poetry shell
. To deactivate the virtual environment and exit this new shell type exit
. To deactivate the virtual environment without leaving the shell use deactivate
.
Why a new shell?
Child processes inherit their environment from their parents, but do not share them. As such, any modifications made by a child process, is not persisted after the child process exits. A Python application (Poetry), being a child process, cannot modify the environment of the shell that it has been called from such that an activated virtual environment remains active after the Poetry command has completed execution.
Therefore, Poetry has to create a sub-shell with the virtual envrionment activated in order for the subsequent commands to run from within the virtual environment.
Alternatively, to avoid creating a new shell, you can manually activate the virtual environment by running source {path_to_venv}/bin/activate
(source {path_to_venv}\Scripts\activate.bat
on Windows). To get the path to your virtual environment run poetry env info --path
. You can also combine these into a nice one-liner, source $(poetry env info --path)/bin/activate
To deactivate this virtual environment simply use deactivate
.
Không có nhận xét nào:
Đăng nhận xét