[英]Rake task failing with `source: not found` on Heroku
I have a Rails project with a rake task called update_data
, which is as follows: 我有一个Rails项目,其中包含一个名为update_data
的瑞克任务,如下所示:
every 1.day, :at => '2:30 am' do
root = File.expand_path('../..', __FILE__)
system("""(source #{root}/data_scripts/venv/bin/activate;
python #{root}/data_scripts/scripts/main.py;
deactivate)""")
end
This should first activate the virtualenv, run the script, and then deactivate the virtualenv. 这应该首先激活virtualenv,运行脚本,然后取消激活virtualenv。 When I run rake update_data
, this works perfectly. 当我运行rake update_data
,这可以完美地工作。 However, when I run heroku run rake update_data
, it fails with sh: 1: source: not found
. 但是,当我运行heroku run rake update_data
,它失败并显示sh: 1: source: not found
。 What should I do so that source
is available on Heroku? 我应该怎么做才能使Heroku上的source
可用?
The error message sh: 1: source: not found
means that: 错误消息sh: 1: source: not found
表示:
sh
instead of bash
, 您运行sh
而不是bash
, source
is not a built-in command and the shell isn't able to find source
in PATH
. source
不是内置命令,shell无法在PATH
找到source
。 To confirm this run heroku run sh
, type source
and compare the output with trying to execute foobar
. 为了证实这一点来看heroku run sh
,类型source
和输出与试图执行比较foobar
。
I recommend you try passing the command to bash (via `bash -c "your command goes here"). 我建议您尝试将命令传递给bash(通过`bash -c“您的命令在此处”)。 You may also need a Python buildpack. 您可能还需要Python buildpack。 You can add it with: 您可以添加以下内容:
heroku buildpacks:add heroku/python
I feel like you don't need to activate your virtualenv. 我觉得您不需要激活您的virtualenv。
Just use the virtualenv's python executable: 只需使用virtualenv的python可执行文件即可:
every 1.day, :at => '2:30 am' do
root = File.expand_path('../..', __FILE__)
system("#{root}/data_scripts/venv/bin/python #{root}/data_scripts/scripts/main.py")
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.