managing-environments.md (poetry-1.1.15) | : | managing-environments.md (poetry-1.2.0) | ||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
# Managing environments | # Managing environments | |||
Poetry makes project environment isolation one of its core features. | Poetry makes project environment isolation one of its core features. | |||
What this means is that it will always work isolated from your global Python ins tallation. | What this means is that it will always work isolated from your global Python ins tallation. | |||
To achieve this, it will first check if it's currently running inside a virtual environment. | To achieve this, it will first check if it's currently running inside a virtual environment. | |||
If it is, it will use it directly without creating a new one. But if it's not, i t will use | If it is, it will use it directly without creating a new one. But if it's not, i t will use | |||
one that it has already created or create a brand new one for you. | one that it has already created or create a brand new one for you. | |||
By default, Poetry will try to use the currently activated Python version | By default, Poetry will try to use the Python version used during Poetry's insta llation | |||
to create the virtual environment for the current project. | to create the virtual environment for the current project. | |||
However, for various reasons, this Python version might not be compatible | However, for various reasons, this Python version might not be compatible | |||
with the `python` requirement of the project. In this case, Poetry will try | with the `python` requirement of the project. In this case, Poetry will try | |||
to find one that is and use it. If it's unable to do so then you will be prompte d | to find one that is and use it. If it's unable to do so then you will be prompte d | |||
to activate one explicitly, see [Switching environments](#switching-between-envi ronments). | to activate one explicitly, see [Switching environments](#switching-between-envi ronments). | |||
{{% note %}} | ||||
If you use a tool like [pyenv](https://github.com/pyenv/pyenv) to manage differe | ||||
nt Python versions, | ||||
you can set the experimental `virtualenvs.prefer-active-python` option to `true` | ||||
. Poetry | ||||
will then try to find the current `python` of your shell. | ||||
For instance, if your project requires a newer Python than is available with | ||||
your system, a standard workflow would be: | ||||
```bash | ||||
pyenv install 3.9.8 | ||||
pyenv local 3.9.8 # Activate Python 3.9 for the current project | ||||
poetry install | ||||
``` | ||||
{{% /note %}} | ||||
{{% note %}} | ||||
Since version 1.2, Poetry no longer supports managing environments for Python 2. | ||||
7. | ||||
{{% /note %}} | ||||
## Switching between environments | ## Switching between environments | |||
Sometimes this might not be feasible for your system, especially Windows where ` pyenv` | Sometimes this might not be feasible for your system, especially Windows where ` pyenv` | |||
is not available, or you simply prefer to have a more explicit control over your environment. | is not available, or you simply prefer to have a more explicit control over your environment. | |||
For this specific purpose, you can use the `env use` command to tell Poetry | For this specific purpose, you can use the `env use` command to tell Poetry | |||
which Python version to use for the current project. | which Python version to use for the current project. | |||
```bash | ```bash | |||
poetry env use /full/path/to/python | poetry env use /full/path/to/python | |||
``` | ``` | |||
skipping to change at line 102 | skipping to change at line 121 | |||
You can also list all the virtual environments associated with the current proje ct | You can also list all the virtual environments associated with the current proje ct | |||
with the `env list` command: | with the `env list` command: | |||
```bash | ```bash | |||
poetry env list | poetry env list | |||
``` | ``` | |||
will output something like the following: | will output something like the following: | |||
```text | ```text | |||
test-O3eWbxRl-py2.7 | ||||
test-O3eWbxRl-py3.6 | test-O3eWbxRl-py3.6 | |||
test-O3eWbxRl-py3.7 (Activated) | test-O3eWbxRl-py3.7 (Activated) | |||
``` | ``` | |||
You can pass the option `--full-path` to display the full path to the environmen | ||||
ts: | ||||
```bash | ||||
poetry env list --full-path | ||||
``` | ||||
## Deleting the environments | ## Deleting the environments | |||
Finally, you can delete existing virtual environments by using `env remove`: | Finally, you can delete existing virtual environments by using `env remove`: | |||
```bash | ```bash | |||
poetry env remove /full/path/to/python | poetry env remove /full/path/to/python | |||
poetry env remove python3.7 | poetry env remove python3.7 | |||
poetry env remove 3.7 | poetry env remove 3.7 | |||
poetry env remove test-O3eWbxRl-py3.7 | poetry env remove test-O3eWbxRl-py3.7 | |||
``` | ``` | |||
You can delete more than one environment at a time. | ||||
```bash | ||||
poetry env remove python3.6 python3.7 python3.8 | ||||
``` | ||||
Use the `--all` option to delete all virtual environments at once. | ||||
```bash | ||||
poetry env remove --all | ||||
``` | ||||
If you remove the currently activated virtual environment, it will be automatica lly deactivated. | If you remove the currently activated virtual environment, it will be automatica lly deactivated. | |||
End of changes. 5 change blocks. | ||||
2 lines changed or deleted | 39 lines changed or added |