我的问题在于manage.py syncdb在Virtualenv中运行。

它在某一时刻工作正常,但是当我安装南部并更新PIP和分发时,似乎已经破裂了。

无论如何,当激活VirtualEnv时,我可以在交互式解释器中将应用程序罚款。通过mod_wsgi运行,也会导入应用程序,并且网站可以运行。

当我运行manage.py syncdb时,它将无法在我的VirtualEnv中找到安装_App中的任何应用程序。它可以拾取系统安装的应用程序,但是当它尝试仅导入Virtualenv应用程序时失败。

有帮助吗?

解决方案

嗨,这是一个古老的问题,但发现它没有回答。不确定您正在尝试做什么,但是基本上有两种模式可以使用Virtualenv,

  1. 用于开发,创建独立环境
  2. 用于部署,创建独立环境

在第一种情况下,您需要首先使用源VENV/bin/activate激活虚拟的,因为在部署时,您需要确保为网站代码激活Virtualenv。我个人更喜欢以下方法来确保正确设置您的道路。 (我还将其添加到我的管理时。

修改后的manage.py

#!/usr/bin/env python
import os.path

# Cater for Virtual env, add to sys.path
pwd = os.path.abspath(os.path.dirname(__file__))
project = os.path.basename(pwd)
new_path = pwd.strip(project)
activate_this = os.path.join(new_path,'venv','bin','activate_this.py')
execfile(activate_this, dict(__file__=activate_this))

from django.core.management import execute_manager
try:
    import settings # Assumed to be in the same directory.
except ImportError:
    import sys
    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
    sys.exit(1)

if __name__ == "__main__":
    execute_manager(settings)

由于我如何构建项目,因此您必须将其更改为目录结构。我的项目结构如此:

TopLevelDir
|
|- Project DIR
|- venv
|- requirements 
|- deployment configs

其他提示

我有一个简单的解决方案

只需在虚拟环境的垃圾箱中启动Manage.py即可。

因此,说您的python在这里/home/tom/emoverments/my_env/bin/python您可以启动manage.py这样:

/home/tom/emoverments/my_env/bin/python manage.py syncdb

然后,只需在Django项目中与虚拟环境的Python创建一个符号链接,并将其称为Env_Python,那么您就可以做到这一点:

./env_python manage.py syncdb

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top