0

I have a package that depends on docker-py and I want to upgrade the dependency to docker. Unfortunately those two packages don't play along with each other very well.

A safe way to do things would be to first uninstall docker-py and then install my package, which will install docker in its place (I already changed the requirements from docker-py to docker).

Is there a way for this to happen in setup.py when I upgrade my package (via pip or any other way) without messing up the python environment?

The first thing that came to my mind was to check, in setup.py, if docker-py is already installed and run pip uninstall like so:

   from setuptools import setup

   ...

   if 'docker-py' in [x.project_name for x in pip.get_installed_distributions()]:
       submodule.check_call("pip uninstall -y docker-py".split())

   setup(
      ...
   )

Setup will then install the new dependecy and everything will work fine.

Is this safe? Any better alternatives?

giskou
  • 804
  • 2
  • 8
  • 22
  • 2
    I have never seen anybody do it, and I would **really hate if a package started uninstalling** packages when I install it. Why not instead raise an error and let the user decide? – Nils Werner Jun 25 '18 at 11:19
  • I totally agree with you @NilsWerner, but the authors of docker-py probably never thought of the chaos they created when they changed the name in pypi but not the name of the actual module. I would expect an error when docker is installed while docker-py is still there, but I don't get that. The specific package is installed and updated automatically in a lot of hosts and I would also like the situation be be resolved in an automatic way too – giskou Jun 25 '18 at 11:23
  • Aren't docker-py and docker the same thing, docker just being a newer version? – Nils Werner Jun 25 '18 at 11:27
  • Yes but they have different names in pypi. It was initially created as docker-py but stopped at version 1.10.6 when it was renamed to docker. The module remained the same. – giskou Jun 25 '18 at 11:28
  • 2
    And what's the problem with showing an error and asking the user to upgrade to `docker`? If you are installing your package in some automated manner, just run `pip uninstall -y docker-py || true` before `pip install yourlib` – Nils Werner Jun 25 '18 at 11:33
  • I will most likely end up doing something like that. Thanks for the help. – giskou Jun 27 '18 at 10:36

2 Answers2

0

pip is not a full blown package manager, it doesn't have such concepts as "This package is incompatible with that" or "This package replaces that". What you're trying to do is emulating these important concepts. Unfortunately that doesn't work.

pip runs setup.py on user hosts only for source distributions (sdist). For eggs/wheels pip runs setup.py on the developer host and there is no way to configure a pre-install script to be run on user hosts, and wheels these days is the preferred distribution format.

You best bet is to ask user (via documentation) to uninstall docker-py manually.

phd
  • 82,685
  • 13
  • 120
  • 165
-1

There is a simple solution I did is - go to your folder where Python is installed, and in the 'Lib/site-pakages' delete the following files. Then reinstall the docker library again with >>> pip install docker

For reference open this image