Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Git post recieve钩子运行virtualenv、Django&;各种python脚本_Python 3.x_Django_Git - Fatal编程技术网

Python 3.x Git post recieve钩子运行virtualenv、Django&;各种python脚本

Python 3.x Git post recieve钩子运行virtualenv、Django&;各种python脚本,python-3.x,django,git,Python 3.x,Django,Git,我已经成功地使用Gitpost-receive钩子将文件从本地推送到服务器,在我的post-receive文件中使用了以下内容: #!/bin/sh git --work-tree=/home/myuser/myproject/app --git-dir=/home/myuser/myproject/myproject.git checkout -f #!/bin/sh git --work-tree=/home/myuser/myproject/app --git-dir=/h

我已经成功地使用Git
post-receive钩子
将文件从本地推送到服务器,在我的
post-receive
文件中使用了以下内容:

#!/bin/sh  

git --work-tree=/home/myuser/myproject/app --git-dir=/home/myuser/myproject/myproject.git checkout -f 
#!/bin/sh  

git --work-tree=/home/myuser/myproject/app --git-dir=/home/myuser/myproject/myproject.git checkout -f 
source /home/myuser/venv/bin/activate
python /home/myuser/myproject/manage.py makemigrations
python /home/myuser/myproject/manage.py migrate
python /home/myuser/myproject/app/python_script1.py
python /home/myuser/myproject/app/python_script1.py
sudo systemctl restart gunicorn
现在我还想启动virtualenv,在使用
post-receive
将文件推送到服务器之后运行Django manage.py和各种python脚本

在此基础上,我将以下内容添加到我的原始
post receive
文件中:

#!/bin/sh  

git --work-tree=/home/myuser/myproject/app --git-dir=/home/myuser/myproject/myproject.git checkout -f 
#!/bin/sh  

git --work-tree=/home/myuser/myproject/app --git-dir=/home/myuser/myproject/myproject.git checkout -f 
source /home/myuser/venv/bin/activate
python /home/myuser/myproject/manage.py makemigrations
python /home/myuser/myproject/manage.py migrate
python /home/myuser/myproject/app/python_script1.py
python /home/myuser/myproject/app/python_script1.py
sudo systemctl restart gunicorn
但虚拟环境似乎未启动,出现以下错误:

remote: hooks/post-receive: 4: hooks/post-receive: source: not found
另外,其余错误似乎与虚拟环境未启动有关<代码>管理.py未执行,出现以下错误:

SyntaxError: invalid syntax
remote:   File "/home/myuser/myproject/manage.py", line 16
remote:     ) from exc
python脚本似乎正在运行,但由于virtual env未启动,它们找不到模块

路径、文件名等都是正确的。编辑以添加:Django、python脚本和虚拟环境独立运行成功,用户具有sudo无密码权限,例如
user ALL=NOPASSWD:/bin/systemctl restart gunicorn

编辑添加:远程服务器是Ubuntu 18


我的代码是否有明显的错误或缺失?

解决方案非常简单。我只需要换一个shebang

发件人:
#/bin/sh

致:
#/bin/bash