- venv,conda etc can be be used to create virtual environments
- Virtual environments allow you to manage dependencies for different projects separately
The activate file is just a shell script. When you run it, it does one main thing: it creates a new PATH variable by shoving the .venv folder to the very front of the list.
python3 -m venv myenvcreates a virtual environment namedmyenv>source myenv/bin/activateactivates the virtual environmentdeactivatedeactivates the virtual environmentpip freeze > requirements.txtsaves the current environment’s packages to a file.pip install -r requirements.txtinstalls packages from a requirements file
- To remove a virtual environment, simply delete the directory containing it
- To create a virtual environment with specific Python version, use
python3.x -m venv myenvwherexis the minor version number.
uv
uvis a tool for managing Python virtual environmentsuv init --appinitializes a new Python application.uv init --lib&&uv init --packageinitializes a new Python library or package.uv runruns a Python script in the virtual environment.uv addadds a package to the virtual environment.uv removeremoves a package from the virtual environment.uv listlists all packages in the virtual environment.uv treeshows the dependency tree of the virtual environment.