如何修复诗歌虚拟环境

问题描述 投票:0回答:2

我正在尝试执行一项任务,我必须运行诗歌虚拟环境并执行一些必须运行其虚拟环境并在其中执行其代码的代码。但有一个问题,虚拟环境保持不变。

run.bat(C:\用户\文档\prj2)

cd path/to/prj2
poetry install
poetry show -v

runner.py

import subprocess

import typer

def typer_main(path_to_bath: str = typer.Argument('test')):
    subprocess.run(path_to_bath)


def script_main():
    """Точка входа для запуска скрипта."""
    typer.run(typer_main)


if __name__ == '__main__':
    script_main()

启动.bat

poetry install
poetry run python runner.py ./path/to/prj2/run.bat
poetry show -v

运行这个项目

./start.bat

输出

(project1-py3.10) PS C:\Users\User\Documents\project1>./start.bat

(project1-py3.10) PS C:\Users\User\Documents\project1> poetry install

Installing dependencies from lock file

Package operations: 0 installs, 17 updates, 0 removals

....

(project1-py3.10) PS C:\Users\User\Documents\project1>poetry show -v

Using virtualenv: C:\Users\User\AppData\Local\pypoetry\Cache\virtualenvs\project1-lbkdIgRk-py3.10

....

(project1-py3.10) PS C:\Users\User\Documents\project1>cd C:\User\Documents\prj2

(project1-py3.10) PS C:\User\Documents\prj2>poetry show -v

Using virtualenv: C:\Users\User\AppData\Local\pypoetry\Cache\virtualenvs\project1-lbkdIgRk-py3.10
....

(project1-py3.10) PS C:\User\Documents\prj2> poetry install

Installing dependencies from lock file

Package operations: 0 installs, 16 updates, 0 removals

....

(project1-py3.10) PS C:\User\Documents\prj2>poetry show -v

Using virtualenv: C:\Users\User\AppData\Local\pypoetry\Cache\virtualenvs\project1-lbkdIgRk-py3.10

....

(project1-py3.10) PS C:\User\Documents\prj2>

为什么虚拟环境没有更改为新的虚拟环境?

python batch-file python-poetry
2个回答
0
投票

尝试

poetry shell

此命令应激活 venv。


0
投票

解决这个问题是添加到run.bat 命令

call deactivate

© www.soinside.com 2019 - 2024. All rights reserved.