【问题标题】:batch: launch pipenv shell, then run command in the virtual environment批处理:启动 pipenv shell,然后在虚拟环境中运行命令
【发布时间】:2018-12-19 19:25:29
【问题描述】:

这是一个批处理脚本:

Z:
cd Z:\different_directory
pipenv shell
cd ..\another_directory


:End
cmd  /k

这里发生的是 pipenv shell 被启动,但虚拟环境没有 cd。相反,一旦我退出 pipenv,它就会运行 cd 命令。

是否可以使用此批处理脚本从 pipenv 内部运行命令?

【问题讨论】:

  • 我也非常希望能够运行这种东西

标签: batch-file pipenv


【解决方案1】:

您可以使用pipenv run 代替pipenv shell 直接运行python 命令或批处理脚本。您将无法直接运行pipenv run cd ../another_dir,但我假设这不是主要目标,因为您只会更改该会话中的目录。你可以创建一个批处理脚本,比如 test.bat,使用

cd ../another_dir
python test.py

然后使用pipenv run test.bat 运行它。下面的页面有更多详细信息。

来源: http://witkowskibartosz.com/blog/pipenv_run_vs_pipenv_shell.html#.W2SBZflKhaQ

【讨论】:

  • 您的意思是说pipenv runpipenv shell 而不是python runpython shell
【解决方案2】:

我知道这个问题很老,但如果你们中的任何人通过谷歌找到了这个,这里是确切的答案:只需使用 pipenv shell "/c command [args]",在这种情况下是 pipenv shell "/c cd ..\another_directory"

为什么会这样:就像documentation 所说,shell 之后的任何内容都将作为参数传递给子shell,并且 CMD 上的参数 /c 在 shell spawn 上运行命令。所以在那里。你甚至可以让它运行一个完整的 .bat。

【讨论】:

  • pipenv shell "cd ..\another_directory" 在 Ubuntu 环境中为我工作
猜你喜欢
  • 1970-01-01
  • 2022-08-18
  • 2019-03-23
  • 1970-01-01
  • 1970-01-01
  • 2019-09-25
  • 2017-07-10
  • 2020-03-27
相关资源
最近更新 更多