StormRider
StormRider

Reputation: 422

Pip install with pip in requirements

I made a package (called "my_package" in the following) that needs minimal versions of pip and setuptools to install. Is it possible to update them during the "pip install my_package" (but not by doing "pip install -U pip" before installing my_package)? I tryied to add them in the requirements but I end with the following exception:

pkg_resources.VersionConflict: (pip 1.5.6 (~/.virtualenvs/test/lib/python2.7/site-packages), Requirement.parse('pip>=9.0.0'))

My setup.py is as follow:

from setuptools import setup

package_name = 'my_package'

requires = [
    'pip >= 9.0.0',
    'setuptools >= 36.0.0'
]


setup(name=package_name,
      author="Me",
      use_scm_version=True,
      packages=[package_name],
      zip_safe=False,
      setup_requires=['setuptools_scm'] + requires,
      install_requires=requires)

Thanks

SOLUTION 1: It does not solve my issue but it makes it more explicit to the user:

from pkg_resources import get_distribution, parse_version

if parse_version(get_distribution('pip').version) < parse_version('9.0.0'):
    raise ImportError('The pip version is too old, please update it using the following command: pip install -U pip')

if parse_version(get_distribution('setuptools').version) < parse_version('36.0.0'):
    raise ImportError('The setuptools version is too old, please update it using the following command: pip install -U setuptools')

Upvotes: 0

Views: 15332

Answers (2)

nivhanin
nivhanin

Reputation: 1908

You can start your setup.py code with upgrade command to pip, then reload and continue as usual. If there are still issues, try to use subscript around it.

For example(use os or subprocess module):

import os
import pip
import importlib
from setuptools import setup

# duplicate this part to another script then reload.
os.system("python -m pip install -U pip")
# Python 3
importlib.reload(pip)
importlib.reload(setuptools)
# Python 2
reload(pip)
reload(setuptools)

package_name = 'my_package'

requires = [
    'pip >= 9.0.0',
    'setuptools >= 36.0.0'
]


setup(name=package_name,
      author="Me",
      use_scm_version=True,
      packages=[package_name],
      zip_safe=False,
      setup_requires=['setuptools_scm'] + requires,
      install_requires=requires)

Upgrading pip

On Linux or macOS:

pip install -U pip

On Windows:

python -m pip install -U pip

Upvotes: 0

tuannv256
tuannv256

Reputation: 501

You should upgrade pip version:

pip install --upgrade pip

Upvotes: 1

Related Questions