gpt4 book ai didi

python - 使用 Fabric 进行 Django 自动部署

转载 作者:行者123 更新时间:2023-12-01 09:22:53 24 4
gpt4 key购买 nike

我想使用 Fabric3 自动部署我的 django 项目

这是我的 fabfile.py

    from fabric.api import env    from fabric.api import run    from fabric.operations import sudo    GIT_REPO = "https://github.com/........"    env.user = 'root'    env.password = '...'    env.hosts = ['demo....com']    env.port = '22'    def deploy():        source_folder = '/home/.../sites/..../...'        run('cd %s && git pull' % source_folder)        run("""            cd {} &&            ../env/bin/pip install -r requirements.txt &&            ../env/bin/python3 manage.py collectstatic --noinput &&            ../env/bin/python3 manage.py migrate            """.format(source_folder))        sudo('restart gunicorn-demo.charon.me')        sudo('service nginx reload')

这是我运行它的方式:
python fabfile.py fab 部署

最后出现错误:

Traceback (most recent call last):  File "/Users/charon/Documents/PycharmProjects/try_blog/fabfile.py", line 1, in     from fabric.api import env  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/fabric/api.py", line 10, in     from fabric.context_managers import (cd, hide, settings, show, path, prefix,  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/fabric/context_managers.py", line 27, in     from fabric.state import output, win32, connections, env  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/fabric/state.py", line 9, in     from fabric.network import HostConnectionCache, ssh  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/fabric/network.py", line 16, in     from fabric.exceptions import NetworkErrorImportError: cannot import name 'NetworkError'

请帮我解决这个问题!!!!

最佳答案

不应该是fab -f fabfile.py部署

无论如何,您的安装可能很困惑,请尝试:

which python

是否匹配:

/Library/Frameworks/Python.framework/Versions/3.6/bin/python

关于python - 使用 Fabric 进行 Django 自动部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50681800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com