Search code examples
python-2.7distutilssetup.py

Is possible to write in Python script setup.py which is going to check if all required packages already installed - otherwise install them


I am making Tornado application(new to Python and Tornado so maybe question is stupid), and I am using additional Python packages like lepl, sqlalchemy and so on. Is possible to write in Python script setup.py which is going to check if all those packages already installed - otherwise install them ? Or I need to do this in bash ?


Solution

  • Use setuptools, and only specify these requirements:

    from setuptools import setup
    
    setup(
        # ...
        setup_requires=['lepl', 'sqlalchemy', ...],
    )
    

    Then use a proper installing tool such as pip, easy_install (comes with setuptools) or buildout to manage installation of those dependencies.

    By separating dependency management and installation, you have much better control over what gets installed when.

    I can recommend you read the Python Packaging User Guide to learn more about packaging of python code and dependency management.