By default, poetry creates a virtual environment in `{cache-dir}/virtualenvs` (`{cache-dir}\virtualenvs` on Windows).
You can change the [`cache-dir`]({{<relref"configuration#cache-dir">}} "cache-dir configuration documentation") value by editing the poetry config.
Additionally, you can use the [`virtualenvs.in-project`]({{<relref"configuration#virtualenvsin-project">}} "#virtualenvs.in-project configuration documentation") configuration variable
to create virtual environment within your project directory.
By default, poetry creates a virtual environment in `{cache-dir}/virtualenvs`.
You can change the [`cache-dir`]({{<relref"configuration#cache-dir">}} "cache-dir configuration documentation") value
by editing the Poetry config.
Additionally, you can use the
[`virtualenvs.in-project`]({{<relref"configuration#virtualenvsin-project">}}) configuration variable to create
virtual environment within your project directory.
There are several ways to run commands within this virtual environment.
{{% note %}}
**External virtual environment management**
Poetry will detect and respect an existing virtual environment that has been externally activated. This is a powerful
mechanism that is intended to be an alternative to Poetry's built-in, simplified environment management.
To take advantage of this, simply activate a virtual environment using your preferred method or tooling, before running
any Poetry commands that expect to manipulate an environment.
{{% /note %}}
### Using `poetry run`
...
...
@@ -129,7 +148,6 @@ Therefore, Poetry has to create a sub-shell with the virtual environment activat
in order for the subsequent commands to run from within the virtual environment.
{{% /note %}}
Alternatively, to avoid creating a new shell, you can manually activate the
virtual environment by running `source {path_to_venv}/bin/activate` (`{path_to_venv}\Scripts\activate.ps1` on Windows PowerShell).
To get the path to your virtual environment run `poetry env info --path`.
...
...
@@ -142,15 +160,14 @@ To deactivate this virtual environment simply use `deactivate`.
In our example, we are requesting the `pendulum` package with the version constraint `^2.1`.
This means any version greater or equal to 2.1.0 and less than 3.0.0 (`>=2.1.0 <3.0.0`).
Please read [Dependency specification]({{<relref"dependency-specification">}} "Dependency specification documentation") for more in-depth information on versions,
how versions relate to each other, and on the different ways you can specify dependencies.
for more in-depth information on versions, how versions relate to each other, and on the different ways you can specify
dependencies.
{{% note %}}
**How does Poetry download the right files?**
...
...
@@ -158,13 +175,12 @@ how versions relate to each other, and on the different ways you can specify dep
When you specify a dependency in `pyproject.toml`, Poetry first takes the name of the package
that you have requested and searches for it in any repository you have registered using the `repositories` key.
If you have not registered any extra repositories, or it does not find a package with that name in the
repositories you have specified, it falls back on PyPI.
repositories you have specified, it falls back to PyPI.
When Poetry finds the right package, it then attempts to find the best match
for the version constraint you have specified.
When Poetry finds the right package, it then attempts to find the best match for the version constraint you have
specified.
{{% /note %}}
## Installing dependencies
To install the defined dependencies for your project, just run the [`install`]({{<relref"cli#install">}}) command.
...
...
@@ -184,7 +200,6 @@ When Poetry has finished installing, it writes all the packages and their exact
locking the project to those specific versions.
You should commit the `poetry.lock` file to your project repo so that all people working on the project are locked to the same versions of dependencies (more below).
### Installing with `poetry.lock`
This brings us to the second scenario. If there is already a `poetry.lock` file as well as a `pyproject.toml` file