1

I'd like to share a program I'm in the process of writing. Is there any way to distribute it along with the modules it uses? Ideally, something that will pull all of the necessary modules from the main file and create a new directory with everything needed to run from source. I do not want to compile and would like to be able to simply share the source and modules in a .zip file or on gitub.

Thanks!

jason
  • 35
  • 5

2 Answers2

1

Make a requirements.txt file that will list all the Python libraries your project requires.

Ideally you'd have a virtualenv for your project, and all the dependencies of your project installed in it - in that case you can simply use pip freeze > requirements.txt to (re)generate it.

Then someone will be easily able to pull the dependencies from PyPI using pip install -r requirements.txt.

http://www.pip-installer.org/en/latest/cookbook.html


Or you could go a step further and make a real Python package? This way it will be very easy to install it directly from github using a single pip install command. Or you could even share it to PyPI.

There's a lot of writing about Python packaging that you might want to read up, for example:

Kos
  • 70,399
  • 25
  • 169
  • 233
  • Ok, I kind of understand the above. Could I simply add a lib folder to my project and copy the module I am using to there and then upload the whole lot to github? I'd like people to be able to download a .zip with everything from Github. With regards to pip-installer, do I need to do anything special with regards to having them host my package? Do they need to approve it or anything? Thanks for your help!! – jason Feb 01 '14 at 11:19
  • You shouldn't copy external libs - what if somebody already has a copy? what if it gets updated with bugfixes? That's why we have dependency tracking. Make a normal Python package, `setuptools` can even generate a Win32 installer for you – Kos Feb 01 '14 at 11:31
  • Ok, I will explore making a package. Am I right in saying that if I use setuptools, it will create a __init__.py that points to the dependencies my program needs to run? – jason Feb 01 '14 at 11:45
  • You configure setuptools by writing a script called `setup.py` and specifying dependencies under `install_requires`; Setuptools will download and install them for your users. Please read [Hitchhiker's guide to Python packaging](http://guide.python-distribute.org/index.html) – Kos Feb 01 '14 at 11:54
  • Great, thank you very much for your help! I am marking this thread as solved. – jason Feb 02 '14 at 10:41
0

Here's a link to another SO thread that shows how you could create and structure a folder with your modules and then zip the folder and share it; Python: sharing common code among a family of scripts

Community
  • 1
  • 1
user1749431
  • 559
  • 6
  • 21