【问题标题】:How to reproduce a Python environment with pip replacing the existing environment?如何用 pip 替换现有环境来重现 Python 环境?
【发布时间】:2020-09-30 20:02:40
【问题描述】:

Python 环境传统上是使用requirements.txt 文件复制的。这只有在您愿意创建一个新环境时才有效

用新环境重现 Python Env

$ python -m venv .venv && source .venv/bin/activate
$ pip install -r requirements.txt
$ pip list

  pkg1==1.0.0
  pkg2==1.0.0
  pkg2_dep==1.0.0 # Not written in requirement.txt

使用现有环境重现 Python Env

$ python -m venv .venv && source .venv/bin/activate
$ pip install requirements.txt

# Made changes to requirements.txt
# Removed pk2==1.0.0
$ pip install requirements.txt
$ pip list

  pkg1==1.0.0
  pkg2==1.0.0 # Should be uninstalled!
  pkg2_dep==1.0.0 # this too

上述限制是由于 pip 无法install and uninstall together。其他语言通过使用锁定文件来支持这一点。


问题:

  • 如何使用 pip 重现带有 requirements.txt 或新的 pyproject.toml 的 Python 环境?
  • 如果 pip 无法实现,那么其他 packager-manager 有哪些其他解决方案可用于此目的?

【问题讨论】:

  • 你是否因为指出重复而感到兴奋?我已经链接了这个问题,并提到它是 pip 的限制,但这本身并不能直接回答我的问题。
  • 很抱歉,我没有通过阅读前几段来点击您的链接,并且知道您的要求,我确实花了很多精力试图为您找到答案,在此期间没有产生任何兴奋过程。
  • @Marcin Orlowski,不,这个问题纯粹是关于使用 requirements.txt 来做到这一点。这个问题询问如何使用 pip 中的任何策略直接重现 Python 环境。使用 requirements.txt 一起安装和卸载软件包已经解决了,但我的问题通常与询问 pip 不同

标签: python pip


【解决方案1】:

看看 pipenv https://docs.pipenv.org/#pipenv-clean

clean
Uninstalls all packages not specified in Pipfile.lock.

pipenv clean [OPTIONS]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-05
    • 2022-10-17
    • 2019-06-15
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多