如何在诗歌中创造一个全新的虚拟环境或复制现有的虚拟环境?(项目中的多个环境)



我有一个项目和一个用诗歌创建的现有虚拟环境(诗歌安装/init(。因此,据我所知,虚拟环境的目的是避免修改系统基础环境和隔离的可能性(每个项目、每个开发、每个系统等(

如何为我的诗歌项目创造另一个全新的环境?如何最终复制和使用现有的

我的意思是,当前的一个(激活的(不应该参与这个(除了最终复制它(,因为我想测试另一组依赖项和代码。

我知道这一点:

  • https://github.com/python-poetry/poetry/issues/4055(答案不清楚,车票未关闭(
  • https://python-poetry.org/docs/managing-environments/(use命令似乎无法按要求的方式工作(

Poetry似乎被绑定到每个python解释器一个virtualenv。Poetry还绑定到pyproject.toml文件及其路径以生成新环境。

因此有两个棘手的解决方案:

1-在pyproject.toml中更改deps,使用另一个python版本(例如与pyenv一起安装(,然后:

poetry env use X.Y

诗歌将创造一个新的虚拟环境,但这并不完全等同于改变一些项目deps。

2-从另一个路径使用另一个pyproject.toml

mkdir env_test
cp pyproject.toml env_test/pyproject.toml
cd env_test
nano pyproject.toml # edit your dependencies
poetry install # creates a brand new virtual environment
poetry shell
# run your script with the new environment

这将生成一个新的环境,只更改所要求的依赖关系。两种环境都可以同时使用。测试之后,最终可以使用env命令删除新环境。

最新更新