Stven David
Stven David

Reputation: 33

How do I get different versions of Python packages to coexist

I have install kafka package with the version 1.2.0 for my project1 , and when I install the version 1.3.0 for project2,the previous version was overwritten, and then project1 will not run, What can I do to keep both projects running properly?

D:\soar\totems-siip-soar-plugins\totems-siip-soar-plugins-pycommon>pip show kafka
Name: kafka
Version: 1.2.0
Summary: Pure Python client for Apache Kafka
Home-page: https://github.com/dpkp/kafka-python
Author: Dana Powers
Author-email: [email protected]
License: Apache License 2.0
Location: c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages
Requires: six
Required-by: totems-pycommon

when I install the other version:

D:\soar\totems-siip-soar-plugins\totems-siip-soar-plugins-pycommon>pip install kafka==1.3.0
Looking in indexes: http://192.168.218.125:8081/repository/pypi_group_test/simple
Collecting kafka==1.3.0
  Downloading http://192.168.218.125:8081/repository/pypi_group_test/packages/kafka/1.3.0/kafka-1.3.0-py2.py3-none-any.whl (193 kB)
     |████████████████████████████████| 193 kB ...
Installing collected packages: kafka
  Attempting uninstall: kafka
    Found existing installation: kafka 1.2.0
    Uninstalling kafka-1.2.0:
      Successfully uninstalled kafka-1.2.0
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
totems-pycommon 1.0.0 requires kafka==1.2.0, but you have kafka 1.3.0 which is incompatible.
Successfully installed kafka-1.3.0

Upvotes: 0

Views: 159

Answers (1)

IljaManakov
IljaManakov

Reputation: 11

You can use python's venv to create separate environments with independent packages

To create an environment you can use the following command:

python3 -m venv /some/path/env-name

After that, you can activate it with

/some/path/env-name/Scripts.bat            # on Windows
source /some/path/env-name/bin/activate    # on Linux

The packages you install when an environment is active are only available inside that environment. By setting up an environment for each of your projects you can avoid conflicts of the sort you are talking about.

Upvotes: 1

Related Questions