-1

I have a situation where my Python2.7 project requires a different version than one of my dependencies.

Say, for example, my project has lib1 and lib2. My project requires lib2 v1.1, but lib1 requires lib2 v2.0. Version 2.0 is not backward compatible with v1.1.

How can install both versions of the same package that won't conflict each other or install lib1 with its dependencies isolated and just import it without conflicting with my packages.

Addition: This question is about how to resolve dependencies on different versions of the same package and using them in the same code base.

Is there any general solution to isolate sub-dependencies, and be sure your packages not conflicting each other ?

Having multiple environments where you can use different versions of a dependency won't help for this.

  • 1
    Possible duplicate of [Installing multiple versions of a package with pip](https://stackoverflow.com/questions/6570635/installing-multiple-versions-of-a-package-with-pip) – Darrick Herwehe Mar 26 '18 at 12:48
  • Why all answers are marked down? If they do not answer your question satisfactorily, then perhaps your question is not clear enough. At least, they attempted to answer your question and help! – amanb Mar 26 '18 at 12:51
  • 1
    @user8212173 I did that, not the OP. They answer a different question. Not the one that was asked. – Darrick Herwehe Mar 26 '18 at 13:18
  • 1
    Possible duplicate of [Installing python packages with multiple versions on OSX](https://stackoverflow.com/questions/25430463/installing-python-packages-with-multiple-versions-on-osx) – phd Mar 26 '18 at 15:42
  • @phd That question is how to `pip install` into the correct python version. This question is about how to manage different versions of a library within the same project. – Darrick Herwehe Mar 26 '18 at 16:17
  • @DarrickHerwehe how this is duplicate question ? at first, my question is not just a find a way to have 2 versions of same package but solve problem when subdependencies conflicting. Clearer sample of this situation is npm or yarn. They have same problem when you want to use same package as first level dependency but they can isolate subdependencies. And the approved answer of your marked question was in 2013 and as we know pip is a tool with active status. – VahagnNikoghosian Mar 26 '18 at 17:46
  • Why question was marked down ? I think nothing wrong with this question, moreover I still can't find a way to solve problem. – VahagnNikoghosian Mar 26 '18 at 17:56

1 Answers1

-2

You could create two different virtual enviroments:

install virtual env:

pip install virtualenv

create a enviroment:

virtualenv env1

Activate your env (linux):

source activate env1

(win --> source bin env1)

In env1:

(env1)pip install package=1.2

In env2:

(env2)pip install package=1.1
Julio CamPlaz
  • 857
  • 8
  • 18