3

I'm developing a Python application built with some packages I've installed with pip such as Flask, requests, PIL.

So how can I distribute my program so that other people can easily install every required dependency/package and simply make it work on every computer? Is setup.py what I'm looking for or not at all? If so, could you please explain what it does and provide an example setup.py that does what I'm trying to do?

PS: I've also got this little question: do I need to provide a __init__.py in the top level folder of my program or just in subdirectories?

4
  • provide a setup file, in which you perform a check for each dependency Commented May 31, 2017 at 17:40
  • Elia, sorry I didn't understand well your question at first. Yes, you are looking for a setup.py, is the best way to do it Commented May 31, 2017 at 17:45
  • 1
    You can follow the guide here Commented May 31, 2017 at 17:46
  • @DamianLattenero I'm looking to share/distribute my application in the form of .py files and I'd like to include a simple and easy way of installing missing packages. Also my project is an application per-se / standalone, it's not meant to be imported in other projects, is other words: it's not supposed to be a library, just a program, I don't know if this makes any difference Commented May 31, 2017 at 17:50

4 Answers 4

7

In the not so old days I used this guide to learn how to package and distribute my python code, then some good people created flit which allows me to do the whole process in three steps.

$pip install flit 

Create my metadata file:

[metadata] author=Some guy [email protected] home-page=https://github.com/someuser/somepackage requires=requests requires-python= >=3 description-file=README.rst classifiers=Intended Audience :: Developers License :: OSI Approved :: BSD License Programming Language :: Python :: 3 Topic :: Software Development :: Libraries :: Python Modules 

Publish my package:

$pip flit publish 

And done!!!

Sign up to request clarification or add additional context in comments.

Comments

2

According to the documentation here

setup.py

There is another type of dependency specification for Python libraries known as setup.py. Setup.py is a standard for distributing and installing Python libraries. If you're building a Python library, such as requests or underwear you must include setup.py so a dependency manager can correctly install both the library as well as additional dependencies for the library. There's still quite a bit of confusion in the Python community over the difference between requirements.txt and setup.py, so read this well written post for further clarification.

Also check this:

What is setup.py?

You can see this example to have an idea of how to make yours:

https://github.com/pypa/sampleproject/blob/master/setup.py

Also, there is a guide here:

https://pythonhosted.org/an_example_pypi_project/setuptools.html

Comments

2

here is the link to the setup file of pandas, where you can see how they perform checks for their dependencies, they might be platform specific or any third party package specific

1 Comment

that's a good answer! Nice to provide an example so he can follow a path, +1
0

Unfortunately, python packaging has a complicated history, and new tools are still emerging. My understanding is that the current "gold standard" is to use setup_tools to define a setup.py file. This file will allow others to install your project's source code using pip. If you want to be able to install with pip without explicitly downloading the source first, you will need to publish your project to pypi using python setup.py upload.

Below is the setup.py boilerplate I use as a starting point:

#!/usr/bin/env python """ boilerplate for new project setup.py """ from setuptools import setup import io import projectname def read(*filenames, **kwargs): encoding = kwargs.get('encoding', 'utf-8') sep = kwargs.get('sep', '\n') buf = [] for filename in filenames: with io.open(filename, encoding=encoding) as f: buf.append(f.read()) return sep.join(buf) long_description = read('README.md') #, 'CHANGES.txt') setup(name='projectname', version=projectname.__version__, description='short desc of projectname', long_description=long_description, author='Tylar Murray', author_email='[email protected]', url='https://github.com/7yl4r/projectname', tests_require=['nose'], install_requires=[ 'networkx' # or whatever ], #cmdclass={'test': PyTest}, packages=['projectname', 'OtherProjectProvidedPackage2'] ) 

NOTE: this template requires you to have a README.md and something like __version__="0.1.23" in your top-level __init__.py

Regarding your P.S. question: Technically you should open a new question for this but in short the answer is you should include both as covered here and in this answer particularly.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.