简体   繁体   English

用厨师激活python虚拟环境

[英]activate python virtual environment with chef

I have a python virtual environment setup and I would like to activate the virtual environment using a chef recipe. 我有一个python虚拟环境设置程序,我想使用厨师食谱激活虚拟环境。

I'm trying to run a script resource 我正在尝试运行脚本资源

script "Start Virtual Enviroment" do
  interpreter "bash"
  code <<-EOH
  source /path/to/virtual_environment/bin/activate
  EOH
end

when I run the recipe chef does not throw any errors but the virtual environment does not start 当我运行配方厨师时,不会引发任何错误,但是虚拟环境无法启动

I am expecting the command prompt to change.. 我期望命令提示符更改。

 (virtual_environment)[root@po-12-3 to]#

When I run the command without a chef recipe it works 当我在没有厨师食谱的情况下运行命令时

source /path/to/virtual_environment/bin/activate

I would like to avoid using a large third party cookbook like python_pip 我想避免使用大型的第三方食谱,例如python_pip

any help is appreciated 任何帮助表示赞赏

Sourcing the activate script does activate the virtual environment, but only for the duration of that shell. 提供激活脚本的确会激活虚拟环境,但仅在该Shell期间有效。 That is to say, the virtual environment is activated on line 4 of your script and deactivated on line 5. 也就是说,虚拟环境在脚本的第4行被激活,而在第5行被停用。

If you want to use the virtual environment, try something like: 如果要使用虚拟环境,请尝试以下操作:

script "Start Virtual Enviroment" do
  interpreter "bash"
  code <<-EOH
  source /path/to/virtual_environment/bin/activate
  python /path/to/my/python/program.py
  EOH
end

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

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