Can I use `pip` instead of `easy_install` for `python setup.py install` dependency resolution?

PythonEasy InstallPip

Python Problem Overview


python setup.py install will automatically install packages listed in requires=[] using easy_install. How do I get it to use pip instead?

Python Solutions


Solution 1 - Python

Yes you can. You can install a package from a tarball or a folder, on the web or your computer. For example:

Install from tarball on web
pip install https://pypi.python.org/packages/source/r/requests/requests-2.3.0.tar.gz
Install from local tarball
wget https://pypi.python.org/packages/source/r/requests/requests-2.3.0.tar.gz
pip install requests-2.3.0.tar.gz
Install from local folder
tar -zxvf requests-2.3.0.tar.gz
cd requests-2.3.0
pip install .

You can delete the requests-2.3.0 folder.

Install from local folder (editable mode)
pip install -e .

This installs the package in editable mode. Any changes you make to the code will immediately apply across the system. This is useful if you are the package developer and want to test changes. It also means you can't delete the folder without breaking the install.

Solution 2 - Python

You can pip install a file perhaps by python setup.py sdist first. You can also pip install -e . which is like python setup.py develop.

Solution 3 - Python

If you are really set on using python setup.py install you could try something like this:

from setuptools import setup, find_packages
from setuptools.command.install import install as InstallCommand


class Install(InstallCommand):
    """ Customized setuptools install command which uses pip. """

    def run(self, *args, **kwargs):
        import pip
        pip.main(['install', '.'])
        InstallCommand.run(self, *args, **kwargs)


setup(
    name='your_project',
    version='0.0.1a',
    cmdclass={
        'install': Install,
    },
    packages=find_packages(),
    install_requires=['simplejson']
)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjoeforkerView Question on Stackoverflow
Solution 1 - PythonColonel PanicView Answer on Stackoverflow
Solution 2 - PythonGeoff ReedyView Answer on Stackoverflow
Solution 3 - PythonTomDotTomView Answer on Stackoverflow