3

In my Node.JS projects, I save my project metadata into package.json: dependencies, version number, author, description, and so on. This makes it so anyone can clone my project and run npm install to create a virtually identical local environment.

Is there a such thing for Python? Some sort of standard file where I can save project metadata, including a version number and PIP dependencies?

2

Python setuptools is a module that you use to write a script, called setup.py in the main directory of your Python project. For distribution purposes, you can use your setup.py to make a Python egg. 9000's link goes into more detail about how to make the egg.

The first link contains detailed documentation on how to write the perfect setup.py, but below is a complete example modified for a Python project I wrote some time ago.

from setuptools import setup

def readme():
    """
    This is a function I wrote to read my README file and return it.
    """
    with open('README.rst') as f:
        return f.read()

setup(name='stackexample',
      version='0.1',
      description='An answer to a question on StackOverflow',
      long_description=readme(), # Get that README.rst
      classifiers=[
          'Development Status :: 3 - Alpha',
          'License :: OSI Approved :: MIT License',
          'Programming Language :: Python :: 3.0'
      ],
      keywords='questions answers programming',
      url='http://stackexchange.com/',
      author_email='bob@example.com',
      license='MIT',
      entry_points = {
          'console_scripts' :
          ['stackex=stackexample.command_line:main']
      },
      packages=['stackexample'],
      install_requires=[
          "requests",
          "something_on_pip",
      ],
      test_suite='nose.collector',
      test_requires=['nose', 'nose-cover3'], # Requirements for the test suite
      include_package_data=True,
      zip_safe=False)

You can also use a requirements.txt file to list dependencies. This blog post goes into pretty good detail about the difference between requirements.txt and setup.py.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.