Remove docker-py in setup.py before installing docker

Question:

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?

Asked By: giskou

||

Answers:

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.

Answered By: phd

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

Answered By: Bhanu Pratap