Skip to content

Commit b9807a0

Browse files
authored
Update virtual-environments.md
1 parent 4eeff93 commit b9807a0

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

python/virtual-environments.md

+47
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Main packages to handle virtual environments
44
- [venv (Standard Library)](#venv-(standard-library))
5+
- [uv](#uv)
56
- [Pipenv](#pipenv)
67
- [virtualenv](#virtualenv-package)
78
- [Poetry](#poetry)
@@ -60,6 +61,52 @@ pip install -r requirements.txt`
6061
```
6162

6263

64+
## uv
65+
66+
To create a virtual environment in a given directory:
67+
```
68+
$ uv venv
69+
```
70+
If no directory name is provided, the venv will be created in the directory `.venv`.
71+
72+
To activate the virtual environment run:
73+
```
74+
$ .venv/Scripts/activate # on Windows Powershell
75+
$ source .venv/bin/activate # Unix system
76+
```
77+
78+
Installing packages from PyPI:
79+
```
80+
$ uv pip install <package_name>
81+
```
82+
83+
Installing from a git repository:
84+
```
85+
$ uv pip install "<package_name> @ https://github.com/<user>/<repo>"
86+
```
87+
88+
To list what’s installed in a given venv
89+
```
90+
$ uv pip freeze
91+
```
92+
You can direct the results to a file like:
93+
```
94+
$ uv pip freeze > requeirements.txt
95+
```
96+
The list will have explicit version requirements for each package, meaning it will be “locked” to the specific versions.
97+
98+
If you want to take an existing `pyproject.toml` or `requirements.in` file and generate a locked dependency set as `requirement.txt`, use:
99+
```
100+
$ uv pip compile pyproject.toml -o requirements.txt
101+
# or
102+
$ uv pip compile requirements.in -o requirements.txt
103+
```
104+
105+
To bring a project’s installed dependencies in sync with a list of locked dependencies use:
106+
```
107+
$ uv pip sync requirements.txt
108+
```
109+
63110
## Pipenv
64111

65112
Installing Pipenv: `$ pip install pipenv`

0 commit comments

Comments
 (0)