Skip to content

Instantly share code, notes, and snippets.

@ryanbehdad
Last active May 3, 2024 10:10
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ryanbehdad/858b47b54be441a684efb7ae6ca98a75 to your computer and use it in GitHub Desktop.
Save ryanbehdad/858b47b54be441a684efb7ae6ca98a75 to your computer and use it in GitHub Desktop.
Python venv cheat sheet

Python venv virtual environment cheat sheet

Create a venv

To create a virtual environment, go to the root of your project and run

python -m venv venv

It will create a virtual environment called venv

Activate venv

.\venv\Scripts\activate

Intall packages

pip install jupyter matplotlib numpy pandas scipy scikit-learn

or

python -m pip install -U jupyter matplotlib numpy pandas scipy scikit-learn

Create requirements.txt

pip freeze > requirements.txt

Deactivate venv

deactivate

Install packages from requirements.txt

pip install -r requirements.txt

Place the requirements.txt file in the root of your project directory. When ready to install the dependencies, ensure your terminal is navigated to the project directory and your virtual environment is activated. Then, run pip install -r requirements.txt to install the listed packages within your virtual environment.

@fernandoaestrella
Copy link

Pasting these 3 for even easier access:

python -m venv venv
.\venv\Scripts\activate
pip install -r requirements.txt

@albertodavincishekhawat
Copy link

also specify where we should paste the requirements.txt file before executing this command

@ryanbehdad
Copy link
Author

ryanbehdad commented Mar 7, 2024

also specify where we should paste the requirements.txt file before executing this command

Place the requirements.txt file in the root of your project directory. When ready to install the dependencies, ensure your terminal is navigated to the project directory and your virtual environment is activated. Then, run pip install -r requirements.txt to install the listed packages within your virtual environment. I updated the original text to include this.

@albertodavincishekhawat
Copy link

Place the requirements.txt file in the root of your project directory. When ready to install the dependencies, ensure your terminal is navigated to the project directory and your virtual environment is activated. Then, run pip install -r requirements.txt to install the listed packages within your virtual environment. I updated the original text to include this.

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment