How do I include library dependencies with a python project?
I am working on a program that some other people will use, built in Python. They all have python installed, however there are several libraries from which this program is imported.
Ideally, I would like to just send them the Python files and they can just run it instead of telling them about each of the libraries they need to install and how to get each one manually using pip.
Is it possible to include all the libraries my project uses with my Python files (or perhaps install an installer that installs it for them)? Or do I just need to give them a complete list of python libraries they need to install and have them do each one by hand?
source to share
This is the topic Python Packaging Tutorial .
In short, you pass them as a install_requires
parameter to setuptools.setup()
.
You can then create the package in many formats including wheel, egg, and even Windows Installer package.
Using a standard packaging framework will also give you the benefit of simple version control.
source to share
You should be using virtualenv
package management for your project. If you do this, you can pip freeze > requirements.txt
keep all project dependencies. This requirements.txt
will then contain all the necessary requirements to run your application. Add this file to your repository. All packages from requirements.txt
can be installed using
pip install -r requirements.txt
Another option is to create a PyPI package. You can find a tutorial on this section here
source to share
You can create a package and specify the dependencies in the setup.py file. This is the right way
http://python-packaging.readthedocs.io/en/latest/dependencies.html
from setuptools import setup
setup(name='funniest',
version='0.1',
description='The funniest joke in the world',
url='http://github.com/storborg/funniest',
author='Flying Circus',
author_email='flyingcircus@example.com',
license='MIT',
packages=['funniest'],
install_requires=[
'markdown',
],
zip_safe=False)
The hack option now needed is some lib that allows your script to interact with the shell. pexpect is my favorite way to automate shell interactions.
source to share