13

I'm working on a program which a few other people are going to be using, made in Python. They all have python installed, however, there are several libraries that this program imports from.

I would ideally like to be able to simply send them the Python files and them be able to just run it, instead of having to tell them each of the libraries they have to install and as them to get each one manually using pip.

Is there any way I can include all the libraries that my project uses with my Python files (or perhaps set up an installer that installs it for them)? Or do I just have to give them a full list of python libraries they must install and get them to do each one manually?

0

3 Answers 3

7

That's the topic of Python packaging tutorial.

In brief, you pass them as install_requires parameter to setuptools.setup().

You can then generate a package in many formats including wheel, egg, and even a Windows installer package.

Using the standard packaging infrastructure will also give you the benefit of easy version management.

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

Comments

2

You can build a package and specify dependencies in your setup.py. This is the right way

https://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='[email protected]',
  license='MIT',
  packages=['funniest'],
  install_requires=[
      'markdown',
  ],
  zip_safe=False)

The need it now hack option is some lib that lets your script interact with shell. pexpect is my favorite for automating shell interactions.

https://pexpect.readthedocs.io/en/stable/

1 Comment

This does not include the dependencies in the package, but they will be installed when you will install this module.
1

You should use virtualenv to manage packages of your project. If you do, you can then pip freeze > requirements.txt to save all dependencies of a project. After this requirements.txt will contain all necessary requirements to run your app. Add this file to your repository. All packages from requirements.txt can be install with

pip install -r requirements.txt

The other option will be to create a PyPI package. You can find a tutorial on this topic here

2 Comments

This requires the package to be available at PyPI, too.
requirements.txt is used for pinning versions. It's not for specifying dependencies, that's the job of setup.py.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.