1 year ago

#70548

test-img

physicalattraction

Multiple eggs in pip's requirements file

Question in short

If I want to install repo[tag_1] and repo[tag_2] from two different dependencies, how can I tell pip such that it knows I want to install repo[tag_1,tag_2]?

Question in detail

I have a few homemade libraries that I want to import from a certain virtual environment. These libraries have dependencies, which are different for a local and a production environment. I am using eggs to make this distinction.

In the first library's setup.py:

setup(
    install_requires=[...]
    extras_require={
        'test': [...],
        'shared_2': [
            'shared_2 @ git+ssh://git@github.com/path_to_shared_2.git@master'
        ]
    }
)

In the second library's setup.py:

setup(
    install_requires=[...]
    extras_require={
        'test': [...],
    }
)

In the requirements file for the virtual environment:

git+ssh://git@github.com/path_to_shared_1.git@master#egg=shared_1[test, shared_2]
git+ssh://git@github.com/path_to_shared_2.git@master#egg=shared_2[test]

If I try to install both these requirements, then due to the first line, we try install path_to_shared_2.git@master#egg=shared_2 and due to the second line, we try to install path_to_shared_2.git@master#egg=shared_2[test]. Pip then quits with the error that it cannot resolve both.

Is there a way that I can specify that any egg for shared_2 is good enough, or even better, that I can specify multiple eggs, and that pip will just combine them, so if I want to install repo[tag_1] and repo[tag_2], pip knows I need to install repo[tag_1,tag_2]?

Error message

On my local environment, pip is not complaining. On my colleague's local environment, he gets the following error message

INFO: pip is looking at multiple versions of shared-2 to determine which version is compatible with other requirements. This could take a while.
INFO: pip is looking at multiple versions of shared-2[test] to determine which version is compatible with other requirements. This could take a while.
ERROR: Cannot install shared-2[test]==2.3.0 and shared-1[test,shared_2]==4.0.1 because these package versions have conflicting dependencies.

The conflict is caused by:
    shared-2[test] 2.3.0 depends on shared-2 2.3.0 (from git+ssh://****@github.com/path_to_shared_2.git@master#egg=shared-2[test])
    shared-1[test,shared_2] 4.0.1 depends on shared-2 2.3.0 (from git+ssh://****@github.com/path_to_shared_2.git@master)

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies
WARNING: You are using pip version 21.1.1; however, version 21.3.1 is available.
You should consider upgrading via the '~/venv/test-sales-venv/bin/python3 -m pip install --upgrade pip' command.

** Solution **

It turned out that upgrading pip from version 21.1.1 to 21.3.1 solved the issue. Apparently there was a bug in an earlier version that got fixed now.

python

pip

setuptools

egg

0 Answers

Your Answer

Accepted video resources