The Python Way

Some (tentative) best practices for Python projects
Author

Lars Vilhuber

Single configuration file with relative paths

  • Encouraged:

NEEDS CONTENT

Use of relative paths in main program for inclusions

NEEDS CONTENT

Dependency management

Python can manage dependencies through the use of the “requirements.txt” file (for more info, see PIP documentation).

The requirements.txt will list the Python dependencies:

MyApp
Framework==0.9.4
Library>=0.2

which can then be installed in other users by running

pip install -r requirements.txt

A working environment can “freeze” the dependencies by running

pip freeze > requirements.txt

which needs to be edited to include only the main dependencies, not the cascading other dependencies, to avoid too much platform-specificity.

Virtual environments

Python virtual environments can be used to create isolated environments for different projects, ensuring that each project has its own dependencies and versions. This is particularly useful when working on multiple projects that may require different versions of the same package.

See LDI Replication Lab Manual for an example.