Skip to content

Commit

Permalink
Update virtual-environments.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jAniceto authored Sep 24, 2024
1 parent 4eeff93 commit b9807a0
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions python/virtual-environments.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Main packages to handle virtual environments
- [venv (Standard Library)](#venv-(standard-library))
- [uv](#uv)
- [Pipenv](#pipenv)
- [virtualenv](#virtualenv-package)
- [Poetry](#poetry)
Expand Down Expand Up @@ -60,6 +61,52 @@ pip install -r requirements.txt`
```


## uv

To create a virtual environment in a given directory:
```
$ uv venv
```
If no directory name is provided, the venv will be created in the directory `.venv`.

To activate the virtual environment run:
```
$ .venv/Scripts/activate # on Windows Powershell
$ source .venv/bin/activate # Unix system
```

Installing packages from PyPI:
```
$ uv pip install <package_name>
```

Installing from a git repository:
```
$ uv pip install "<package_name> @ https://github.com/<user>/<repo>"
```

To list what’s installed in a given venv
```
$ uv pip freeze
```
You can direct the results to a file like:
```
$ uv pip freeze > requeirements.txt
```
The list will have explicit version requirements for each package, meaning it will be “locked” to the specific versions.

If you want to take an existing `pyproject.toml` or `requirements.in` file and generate a locked dependency set as `requirement.txt`, use:
```
$ uv pip compile pyproject.toml -o requirements.txt
# or
$ uv pip compile requirements.in -o requirements.txt
```

To bring a project’s installed dependencies in sync with a list of locked dependencies use:
```
$ uv pip sync requirements.txt
```

## Pipenv

Installing Pipenv: `$ pip install pipenv`
Expand Down

0 comments on commit b9807a0

Please sign in to comment.