【问题标题】:fabric is not getting Django environment织物没有得到 Django 环境
【发布时间】:2016-01-13 15:01:48
【问题描述】:

我的本​​地系统中有一个结构文件,我用它在远程服务器(在 virtualenv 中)部署代码并想对其进行测试。方法定义如下。

    def test_deploy(gitid = '930bfc4'):
        # manually put the commit id at the end
        path = '/tmp/testapp/app1/source/demo4'
        with cd(path):
            commit_id = 'git fetch https://myaccount@github.org/myaccount/demo4.git/heads/master:https://myaccount@github.org/myaccount/demo4.git/remotes/origin/master/'+gitid
            # change the settings.py file and update the database
            run (commit_id)
            run ('cat .git/FETCH_HEAD')

        path1 = '/tmp/testvehic/vehic'
        with cd(path1):
            run ('pwd')
            env.activate = 'source /tmp/testapp/app1/bin/activate'
            run ('python /tmp/testapp/app1/source/demo4/manage.py test')`

这表明

ImportError: 没有名为 django.core.management 的模块

在 Google 中进行一些搜索后,我知道它实际上并没有找到我的 django 环境。
我的虚拟环境路径是/tmp/testapp/app1
源代码在/tmp/testapp/app1/source/app1/
当我在服务器终端运行命令python manage.py test 时,它工作正常。如何通过织物进行测试?

【问题讨论】:

  • 停止绑定激活东西,太多人弄错了,改为:/tmp/testvehic/vehic/bin/python /tmp/testapp/app1/source/demo4/manage.py test它保证不会失败;没有人会看到代码而感到困惑;更容易调试;赢了! :P

标签: python django linux virtualenv fabric


【解决方案1】:

我从下面的链接得到了答案

http://nurupoga.org/articles/deployment-with-fabric-and-virtualenv/

我的代码 sn-p 现在看起来像这样

VENV_DIR = '/home/rootuser/testvehic/vehic'
PROJECT_DIR = '/home/rootuser/testvehic/vehic/source/cabsdemo4'

@contextmanager
def source_virtualenv():
    with prefix('source ' + os.path.join(VENV_DIR, 'bin/activate')):
        yield
def test_deploy(gitid = '930bfc4'):
    # manually put the commit id at the end
    path = '/tmp/testapp/app1/source/demo4'
    with cd(path):
        commit_id = 'git fetch https://myaccount@github.org/myaccount/demo4.git/heads/master:https://myaccount@github.org/myaccount/demo4.git/remotes/origin/master/'+gitid
        # change the settings.py file and update the database
        run (commit_id)
        run ('cat .git/FETCH_HEAD')
    with settings(warn_only=True):
        with cd(PROJECT_DIR):
            with source_virtualenv():
                run('pip install -r requirements.txt')
                run('python manage.py test')

【讨论】:

    猜你喜欢
    • 2022-07-02
    • 2019-11-21
    • 2015-06-17
    • 1970-01-01
    • 2018-11-12
    • 2011-09-05
    • 1970-01-01
    • 2013-09-07
    • 1970-01-01
    相关资源
    最近更新 更多