如何让不同版本的Python包共存?



我为我的project1安装了1.2.0版本的kafka包,当我为project2安装1.3.0版本时,以前的版本被覆盖了,然后project1无法运行。我能做些什么来保持两个项目正常运行?

D:soartotems-siip-soar-pluginstotems-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: dana.powers@gmail.com
License: Apache License 2.0
Location: c:usersadministratorappdatalocalprogramspythonpython39libsite-packages
Requires: six
Required-by: totems-pycommon

当我安装其他版本时:

D:soartotems-siip-soar-pluginstotems-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

您可以使用python的venv创建带有独立包的独立环境

要创建一个环境,可以使用以下命令:

python3 -m venv /some/path/env-name
之后,你可以用 激活它
/some/path/env-name/Scripts.bat            # on Windows
source /some/path/env-name/bin/activate    # on Linux

当环境处于活动状态时安装的包仅在该环境中可用。通过为每个项目设置一个环境,您可以避免您正在谈论的那种冲突。

最新更新