Gregg's MOTD

Tips & Tricks that I've Encountered Over the Years...

Python: Initializing a New Project using venv

July 01, 2023 — Gregg Szumowski

Start out by creating a new directory or cloning a repository (which creates a directory) and cd into it:

$ git clone https://gitlab.com/username/proj-name
$ cd proj-name/

Initialize the virtual environment:

$ python3 -m venv venv
$ source venv/bin/activate

Install whatever dependencies you need:

$ pip install package1 package2

Then develop and/or run your program:

$ python data_model.py
$ python app.py
$ sqlite3 hpr.sqlite "select count(*) from users"

When you’re done working you can deactivate the environment by typing:

$ deactivate

Tags: cli, python, venv, virtual, environment, motd