使用manage.py syncdb时,Django没有在virtualenv中找到应用程序
发布时间:2020-12-16 22:55:36 所属栏目:Python 来源:网络整理
导读:我的问题是让manage.py syncdb在virtualenv中运行. 它在某一点上工作得很好,但是当我安装South并更新pip并分发时,似乎已经破坏了. 无论如何,当virtualenv被激活时,我可以在交互式解释器中导入应用程序.通过mod_wsgi运行,也会导入应用程序,并且该站点可以运行
我的问题是让manage.py syncdb在virtualenv中运行.
它在某一点上工作得很好,但是当我安装South并更新pip并分发时,似乎已经破坏了. 无论如何,当virtualenv被激活时,我可以在交互式解释器中导入应用程序.通过mod_wsgi运行,也会导入应用程序,并且该站点可以运行. 当我运行manage.py syncdb时,它无法在我的virtualenv中的INSTALLED_APPS中找到任何应??用程序.它可以很好地获取系统安装的应用程序,但在尝试仅导入virtualenv应用程序时失败. 解决方法
嗨这是一个老问题,但看不到答案.不确定你要做什么,但基本上有两种模式你可以使用virtualenv,
>为了开发,创建自包含的环境 在第一种情况下,您需要首先使用源venv / bin / activate激活您的virtualenv,因为在部署时,您需要确保为您的网站代码激活virtualenv.我个人更喜欢以下方法来确保您的路径设置正确. (我在开发时也将它添加到我的manage.py中,所以我不必担心首先激活环境. 修改后的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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |