简体   繁体   English

在Shell脚本中启动virtualenv

[英]Start a virtualenv inside a shell script

I'm working on a Python project that's wrapped in a virtualenv. 我正在处理包装在virtualenv中的Python项目。 I'd like to have a script that does all the "footwork" of getting set up as soon as I clone my git repo -- namely make the virtualenv, download my requirements, and stay in the virtualenv after exiting . 我想拥有一个脚本,该脚本可在克隆git repo时立即完成设置的所有“工作”-即制作virtualenv,下载我的需求,并在退出后保留在virtualenv中 However, once the shell script finishes, I'm no longer in my virtualenv, since the changes it makes to its shell don't propagate to mine. 但是,一旦Shell脚本完成,我就不再处于virtualenv中,因为它对其外壳所做的更改不会传播到我的外壳中。

How can I have the virtualenv "stick" to the parent shell that ran the script? 我怎样才能使virtualenv坚持运行脚本的父外壳?

Use a function instead of a separate script. 使用函数而不是单独的脚本。 A function executes in the context of your current shell. 一个函数在您当前的shell上下文中执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM