问题
we are trying to install several own written python3 applications sharing some libraries with conflicting versions.
We are currently discussing employing the order of packages inside the PYTHONPATH and/ or pythons virtualenv.
How would you handle this?
回答1:
You can use pipx.
pipx will do all the work of setting up separate virtual environments for each application, so that all the applications' dependencies remain separate.
If you use virtualenv yourself, you have to switch environments to run a different application. pipx handles the environment for you, so you don't have to mess with the virtualenvs at all.
From the docs:
pipx is made specifically for application installation, as it adds isolation yet still makes the apps available in your shell: pipx creates an isolated environment for each application and its associated packages.
Old Answer (pipsi is no longer maintained, but pipx is almost identical in usage)
You can use pipsi.
pipsi will do all the work of setting up separate virtual environments for each application, so that all the applications' dependencies remain separate.
If you use virtualenv yourself, you have to switch environments to run a different application. pipsi handles the environment for you, so you don't have to mess with the virtualenvs at all.
From the docs:
If you are installing Python packages globally for cli access, you almost certainly want to use
pipsi
instead of runningsudo pip ....
so that you get
- Isolated dependencies to guarantee no version conflicts
- The ability to install packages globally without using sudo
- The ability to uninstall a package and its dependencies without affecting other globally installed Python programs
回答2:
For dependency isolation and management I always have one virtualenv per application. This prevents issues with inter-application dependency conflicts and if there are dependency conflicts within an application's dependency any hackery to workaround them is limited to the affected environment.
Also, dependency upgrades can be performed independently per application.
来源:https://stackoverflow.com/questions/36500141/python-packages-with-conflicting-dependencies