python - 如何让不同版本的 Python 包共存
问题描述
我已经为我的 project1 安装了 1.2.0 版本的 kafka 包,当我为 project2 安装 1.3.0 版本时,以前的版本被覆盖,然后 project1 将无法运行,我该怎么做才能保持两个项目正常运行?
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: dana.powers@gmail.com
License: Apache License 2.0
Location: c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages
Requires: six
Required-by: totems-pycommon
当我安装其他版本时:
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
解决方案
您可以使用 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
您在环境处于活动状态时安装的软件包仅在该环境中可用。通过为每个项目设置环境,您可以避免您正在谈论的那种冲突。
推荐阅读
- google-apps-script - 因内部错误而禁用基于时间的 GAS 触发器
- javascript - 使用 react-number-format: 一次不能输入多个符号
- windows - 无法在 Windows 10 上使用 Git Bash 启动 SSH 代理
- openam - Simplesamlphp 作为 SP,OpenAM 作为 IdP。注销错误“缺少中继状态”
- java - 如何在java中将数据写入application.properties文件
- flutter - Flutter 错误 A RenderFlex 溢出。如何设置图像适合屏幕?
- sql-server - 无法连接到 UWP 上的 SQL Server (SQLEXPRESS)
- google-earth-engine - 无法加载 earthengine-api,即使它已安装
- automation - 如何将日、月和年添加到赛普拉斯中的选定日期
- vue.js - 如何修复 vue2editor 插入链接不起作用的问题?