You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/docs/advanced/settings.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,15 @@ For this reason it's common to provide them in environment variables that are re
8
8
9
9
/// tip
10
10
11
-
To understand environment variables you can read the page [Environment Variables](../environment-variables.md){.internal-link target=_blank}
11
+
To understand environment variables you can read [Environment Variables](../environment-variables.md){.internal-link target=_blank}.
12
12
13
13
///
14
14
15
15
## Types and validation
16
16
17
17
These environment variables can only handle text strings, as they are external to Python and have to be compatible with other programs and the rest of the system (and even with different operating systems, as Linux, Windows, macOS).
18
18
19
-
That means that any value read in Python from an environment variable will be a `str`, and any conversion to a different type or validation has to be done in code.
19
+
That means that any value read in Python from an environment variable will be a `str`, and any conversion to a different type or any validation has to be done in code.
Copy file name to clipboardExpand all lines: docs/en/docs/environment-variables.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -161,11 +161,11 @@ You can read more about it at <a href="https://12factor.net/config" class="exter
161
161
162
162
These environment variables can only handle **text strings**, as they are external to Python and have to be compatible with other programs and the rest of the system (and even with different operating systems, as Linux, Windows, macOS).
163
163
164
-
That means that **any value** read in Python from an environment variable **will be a `str`**, and any conversion to a different type or validation has to be done in code.
164
+
That means that **any value** read in Python from an environment variable **will be a `str`**, and any conversion to a different type or any validation has to be done in code.
165
165
166
166
You will learn more about using environment variables for handling **application settings** in the [Advanced User Guide - Settings and Environment Variables](./advanced/settings.md){.internal-link target=_blank}.
167
167
168
-
## `PATH`environment variable
168
+
## `PATH`Environment Variable
169
169
170
170
There is a **special** environment variable called **`PATH`** that is used by the operating systems (Linux, macOS, Windows) to find programs to run.
171
171
@@ -192,13 +192,13 @@ This means that the system should look for programs in the directories:
This way, when you type `python` in the terminal, the system will find the Python program in `C:\opt\custompython\bin` (the last directory) and use that one.
Copy file name to clipboardExpand all lines: docs/en/docs/tutorial/security/first-steps.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,9 +58,11 @@ The <a href="https://github.com/Kludex/python-multipart" class="external-link" t
58
58
59
59
However, if you use the `pip install fastapi` command, the `python-multipart` package is not included by default.
60
60
61
-
To install it manually, make sure you create a [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and then install it with:
61
+
To install it manually, make sure you create a [virtual environment](../../virtual-environments.md){.internal-link target=_blank}, activate it, and then install it with:
62
62
63
-
`pip install python-multipart`
63
+
```console
64
+
$ pip install python-multipart
65
+
```
64
66
65
67
This is because **OAuth2** uses "form data" for sending the `username` and `password`.
Copy file name to clipboardExpand all lines: docs/en/docs/virtual-environments.md
+20-9Lines changed: 20 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -106,7 +106,7 @@ But you could customize it passing an additional argument with the directory nam
106
106
107
107
////
108
108
109
-
That creates a new virtual environment in a directory called `.venv`.
109
+
That command creates a new virtual environment in a directory called `.venv`.
110
110
111
111
/// details | `.venv` or other name
112
112
@@ -269,7 +269,7 @@ $ echo "*" > .venv/.gitignore
269
269
/// details | What that command means
270
270
271
271
*`echo "*"`: will "print" the text `*` in the terminal (the next part changes that a bit)
272
-
*`>`: anything printed to the terminal by the previous command before `>` should not be printed but instead written to the file that goes next to`>`
272
+
*`>`: anything printed to the terminal by the command to the left of `>` should not be printed but instead written to the file that goes to the right of`>`
273
273
*`.gitignore`: the name of the file where the text should be written
274
274
275
275
And `*` for Git means "everything". So, it will ignore everything in the `.venv` directory.
@@ -300,7 +300,7 @@ If you're in a hurry and don't want to use a file to declare your project's pack
300
300
301
301
/// tip
302
302
303
-
It's a (very) good idea to put the packages and versions your program needs in a file later (for example `requirements.txt` or `pyproject.toml`).
303
+
It's a (very) good idea to put the packages and versions your program needs in a file (for example `requirements.txt` or `pyproject.toml`).
304
304
305
305
///
306
306
@@ -358,6 +358,7 @@ If you have <a href="https://github.com/astral-sh/uv" class="external-link" targ
358
358
359
359
```console
360
360
$ uv pip install -r requirements.txt
361
+
---> 100%
361
362
```
362
363
363
364
</div>
@@ -486,7 +487,7 @@ flowchart LR
486
487
end
487
488
```
488
489
489
-
But then if you want to run `priosner-of-azkaban`, you will need to uninstall `harry` version `1` and install `harry` version `3` (or just installing version `3` would automatically uninstall version `1`).
490
+
But then if you want to run `prisoner-of-azkaban`, you will need to uninstall `harry` version `1` and install `harry` version `3` (or just installing version `3` would automatically uninstall version `1`).
490
491
491
492
<divclass="termy">
492
493
@@ -498,6 +499,8 @@ $ pip install "harry==3"
498
499
499
500
And then you would end up with `harry` version `3` installed in your global Python environment.
500
501
502
+
And if you try to run `philosophers-stone` again, there's a chance it would **not work** because it needs `harry` version `1`.
503
+
501
504
```mermaid
502
505
flowchart LR
503
506
subgraph global[global env]
@@ -513,7 +516,13 @@ flowchart LR
513
516
end
514
517
```
515
518
516
-
Now, imagine that with **many** other **packages** that all your **projects depend on**. That's very difficult to manage. And you would probably end up trying to run some projects with some **incompatible versions** of the packages, and not knowing why some are working or not.
519
+
/// tip
520
+
521
+
It's very common in Python packages to try the best to **avoid breaking changes** in **new versions**, but it's better to be safe, and install newer versions intentionally and when you can run the tests to check everything is working correctly.
522
+
523
+
///
524
+
525
+
Now, imagine that with **many** other **packages** that all your **projects depend on**. That's very difficult to manage. And you would probably end up running some projects with some **incompatible versions** of the packages, and not knowing why something isn't working.
517
526
518
527
Also, depending on your operating system (e.g. Linux, Windows, macOS), it could have come with Python already installed. And in that case it probably had some packages pre-installed with some specific versions **needed by your system**. If you install packages in the global Python environment, you could end up **breaking** some of the programs that came with your operating system.
That command will create some [environment variables](environment-variables.md){.internal-link target=_blank} that will be available for the next commands.
622
+
That command will create or modify some [environment variables](environment-variables.md){.internal-link target=_blank} that will be available for the next commands.
614
623
615
624
One of those variables is the `PATH` variable.
616
625
@@ -620,7 +629,7 @@ You can learn more about the `PATH` environment variable in the [Environment Var
620
629
621
630
///
622
631
623
-
Activating a virtual environment adds its path,`.venv/bin` (on Linux and macOS) or `.venv\Scripts` (on Windows) to the `PATH` environment variable.
632
+
Activating a virtual environment adds its path `.venv/bin` (on Linux and macOS) or `.venv\Scripts` (on Windows) to the `PATH` environment variable.
624
633
625
634
Let's say that before activating the environment, the `PATH` variable looked like this:
626
635
@@ -701,7 +710,9 @@ and use that one.
701
710
702
711
////
703
712
704
-
Activating a virtual environment also changes a couple of other things, but this is one of the most important details.
713
+
An important detail is that it will put the virtual environment path at the **beginning** of the `PATH` variable. The system will find it **before** finding any other Python available. This way, when you run `python`, it will use the Python **from the virtual environment** instead of any other `python` (for example, a `python` from a global environment).
714
+
715
+
Activating a virtual environment also changes a couple of other things, but this is one of the most important things it does.
705
716
706
717
## Checking a Virtual Environment
707
718
@@ -823,7 +834,7 @@ Once you are ready and want to use a tool to **manage the entire project**, pack
823
834
* Manage the **virtual environment** for your projects
824
835
* Install **packages**
825
836
* Manage package **dependencies and versions** for your project
826
-
* Make sure you have an **exact** set of packages and versions to install, including their dependencies, so that you can be sure that you can run your project exactly the same as in your computer while developing, this is called **locking**
837
+
* Make sure you have an **exact** set of packages and versions to install, including their dependencies, so that you can be sure that you can run your project in production exactly the same as in your computer while developing, this is called **locking**
0 commit comments