是否可以从TCL激活和执行Virtualenv Python?
这是我执行的bash命令:
source ./virtualenv/Scripts/activate && cd ./deps/scripts && python generate_system_info.py
现在我想在tcl脚本中运行它。我不确定如何实现这一目标。
我知道需要在TCL中进行 exec
。但是,我不确定是否可以使用上面显示的方法从TCL进行Virtualenv的激活。当我在TCL Shell中拨打 exec
时,我也不确定如何集成&
。
我想实现的目标吗?
TCL外壳来自一个名为Xilinx Vivado的程序。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
激活
脚本(由此模板通过明显的替换)设置了这些环境变量(您需要关心):virtual_env
- 虚拟环境根的路径。路径
- 在...很多程序中找到二进制文件!这是脚本的扩展。PS1
- 系统提示。它还删除
pythonhome
环境变量(如果是设置),并定义一个称为deactivate
的函数以撤消所有这些。要在
tclsh
中执行等效词,将Python作为子过程运行时,通常只需要设置前两个变量(并执行此操作)即可。当TCL退出时,清洁会自动发生。 (我们省略配置提示;只有在交互式工作时,您才需要它。)之后,您可以
exec
正常,而事物将只能使用™。The
activate
script (made from this template by obvious substitutions) sets these environment variables (that you need to care about):VIRTUAL_ENV
— The path of the root of the virtual environment.PATH
— Where binaries are found by... lots of programs! This is extended by the script.PS1
— The system prompt.It also removes the
PYTHONHOME
environment variable (if it was set) and defines a function calleddeactivate
to undo all this.To do the equivalent in
tclsh
when running Python as a subprocess, you usually just need to set the first two variables (and do that remove). The clean up happens automatically when Tcl exits. (We omit configuring the prompt; you would only need that if working interactively.)After that, you can
exec
as normal and things will Just Work™.来自 venv 文档:
因此,基本上
激活
只需替换Python脚本的路径(和$ PATH
环境变量,至少在Linux中)。您只需使用完整/相对路径即可从virtualenv
目录中运行 porpor python。如果您在哪里挣扎,则可以激活
virtualenv
,并使用命令来找到它!From the venv documentation:
So basically
activate
just replaces path to your python script (and$PATH
environment variable, at least in linux). You can just run proper python fromvirtualenv
directory using full/relative path.If you struggle where it is, you can activate
virtualenv
and usewhich
command to find it out!如果没有别的,您可以执行这样的整个管道:
&&
只是说“如果上一个命令成功,请继续执行下一个命令”。因此,您可以在三个单独的行上执行这三个命令。问题是source
命令。它需要在当前过程中设置环境变量,默认情况下,TCL将启动一个子壳,当该子壳结束时,环境将消失。您可以在TCL中设置本地环境变量,因此也许选项是将activate
shell脚本转换为tcl命令。那你可以做If nothing else, you can execute the whole pipeline like this:
The
&&
just says "if the previous command succeeded, continue on to the next command". Thus, you could do those three commands on three separate lines. The PROBLEM is thatsource
command. It needs to set environment variables in the current process, and by default tcl would launch a subshell, and when that subshell ended the environment would go away. You CAN set local environment variables in tcl, so maybe the option would be to convert thatactivate
shell script into tcl commands. Then you could do