Skip to content

Commit 5743357

Browse files
DbCrWkradoering
authored andcommitted
docs: clarify python version usage (#9256)
(cherry picked from commit cab9c42)
1 parent 4118200 commit 5743357

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

docs/basic-usage.md

+24-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,29 @@ Similarly, the traditional `MANIFEST.in` file is replaced by the `tool.poetry.re
6363
`tool.poetry.exclude` sections. `tool.poetry.exclude` is additionally implicitly populated by your `.gitignore`. For
6464
full documentation on the project format, see the [pyproject section]({{< relref "pyproject" >}}) of the documentation.
6565

66+
### Setting a Python Version
67+
68+
{{% note %}}
69+
Unlike with other packages, Poetry will not automatically install a python interpreter for you.
70+
If you want to run Python files in your package like a script or application, you must _bring your own_ python interpreter to run them.
71+
{{% /note %}}
72+
6673
Poetry will require you to explicitly specify what versions of Python you intend to support, and its universal locking
6774
will guarantee that your project is installable (and all dependencies claim support for) all supported Python versions.
75+
Again, it's important to remember that -- unlike other dependencies -- setting a Python version is merely specifying which versions of Python you intend to support.
76+
77+
For example, in this `pyproject.toml` file:
78+
79+
```toml
80+
[tool.poetry.dependencies]
81+
python = "^3.7.0"
82+
```
83+
84+
we are allowing any version of Python 3 that is greater than `3.7.0`.
85+
86+
When you run `poetry install`, you must have access to some version of a Python inrepreter that satisfies this constraint available on your system.
87+
Poetry will not install a Python interpreter for you.
88+
If you use a tool like `pyenv`, you can use the experimental configuration value [`virtualenvs.prefer-active-python`]({{< relref "configuration/#virtualenvsprefer-active-python-experimental" >}}).
6889

6990
### Initialising a pre-existing project
7091

@@ -155,13 +176,15 @@ Likewise if you have command line tools such as `pytest` or `black` you can run
155176
If managing your own virtual environment externally, you do not need to use `poetry run` or `poetry shell` since
156177
you will, presumably, already have activated that virtual environment and made available the correct python instance.
157178
For example, these commands should output the same python path:
179+
158180
```shell
159181
conda activate your_env_name
160182
which python
161183
poetry run which python
162184
poetry shell
163185
which python
164186
```
187+
165188
{{% /note %}}
166189

167190
### Activating the virtual environment
@@ -197,7 +220,7 @@ You can also combine these into a one-liner, such as `source $(poetry env info -
197220
To deactivate this virtual environment simply use `deactivate`.
198221

199222
| | POSIX Shell | Windows (PowerShell) | Exit/Deactivate |
200-
|-------------------| ----------------------------------------------- |----------------------------------------------------------| --------------- |
223+
| ----------------- | ----------------------------------------------- | -------------------------------------------------------- | --------------- |
201224
| Sub-shell | `poetry shell` | `poetry shell` | `exit` |
202225
| Manual Activation | `source {path_to_venv}/bin/activate` | `{path_to_venv}\Scripts\activate.ps1` | `deactivate` |
203226
| One-liner | `source $(poetry env info --path)/bin/activate` | `& ((poetry env info --path) + "\Scripts\activate.ps1")` | `deactivate` |
@@ -273,7 +296,6 @@ the dependencies installed are still working even if your dependencies released
273296
{{% warning %}} If you have added the recommended [`[build-system]`]({{< relref "pyproject#poetry-and-pep-517" >}}) section to your project's pyproject.toml then you _can_ successfully install your project and its dependencies into a virtual environment using a command like `pip install -e .`. However, pip will not use the lock file to determine dependency versions as the poetry-core build system is intended for library developers (see next section).
274297
{{% /warning %}}
275298

276-
277299
#### As a library developer
278300

279301
Library developers have more to consider. Your users are application developers, and your library will run in a Python environment you don't control.

0 commit comments

Comments
 (0)