Currently python options for code distribution are bit messy as described here. I spent some time to find right way how to create setup script, which will install external dependencies, so here is the recipe for python3:
Create virtual virtual environment for your project:
virtualenv -p /usr/bin/python3 .
Then create setup.py file – two important things:
try: from setuptools import setup except ImportError: from distutils.core import setup
Import setup function from setuptools, this l enables to specify dependencies, which should be installed automatically by pip
or easy_setup
.
setup(name='packageX', version='1.0', description='Sample package', packages=['x'], author='Your name', author_email='your email', requires= ['six (>=1.4.1)', 'bitarray (>=0.8.1)'], install_requires=['six>=1.4.1', 'bitarray>=0.8.1'], provides=['x'] )
It is important that install_requires
keyword is included. Also note different syntax of version requirements – requires
vs install_requires
. (requires and provides are probably not necessary ).
Test files, readme, license files etc. specify them in MANIFEST.in file in root of distribution – something like this:
recursive-include tests *.txt *.py exclude tests/something_temp.py include README.md
Once all code is ready you can create distribution with command:
python setup.py sdist
This will create packed distribution in dist
subdirectory and then you can try to install in another virtual environment by:
pip install path/to/dist/packageX-1.0.0.tar.gz