Creating a Python requirements.txt File
This can be done quickly by typing:
$ pip freeze >requirements.txt
at the command line.
To install packages using a requirements
file just use
pip
:
$ pip install -r requirements.txt
To check if the packages in your requirements.txt
file
are up-to-date use:
$ pip list --outdated
and to update those packages:
$ pip install -U <packagename>
This process has some drawbacks as packages are sometimes included that are no longer needed and should only be used initially and then maintained manually.
Tags: cli, python, pip, requirements, motd
Python: Initializing a New Project using venv
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