Best way to incorporate third-party dependencies in a Python application

What is the best way to distribute dependencies for an application?

Let's say I want to publish an application that depends on SqlAlchemy - is there a clean way to include SqlAlchemy in my repository without forcing the user to install it?

+7
python virtualenv
source share
2 answers

Community standard - use pip package manager with requirements file .

eg.

 SQLAlchemy>=0.9.8 

This will force the installation of SQLAlchemy with a version higher than or equal to 0.9.8 .

If you want to distribute your code autonomously, you might consider creating a separate directory for third-party packages and expanding the PYTHONPATH environment variable.

export PYTHONPATH=$PYTHONPATH:/path/to/3rdpartypackages/

+2
source share

Although this will force the user to install it, I would recommend using the requirements file for this. ( http://www.pip-installer.org/en/latest/user_guide.html#requirements-files )

For this specific task, the file can be as simple as one line:

 SQLAlchemy 

As a general practice, you should indicate the version number that you depend on in this file. If you do not want the user to install things because you are worried about the pollution of their main installation, I would like to use VirtualEnv for this ( http://www.virtualenv.org/en/latest/ ). This is the recommended dependency distribution tool for Django projects at a minimum.

0
source share

All Articles