使用manage.pysyncdb时,Django在virtualenv中找不到应用程序
我的问题是让manage.pysyncdb在virtualenv中运行。
它曾经工作得很好,但当我安装 South 并更新 pip 和分发时,它似乎在某个时候出现了故障。
无论如何,当激活 virtualenv 时,我可以在交互式解释器中很好地导入应用程序。通过 mod_wsgi 运行,应用程序也会导入,并且站点可以运行。
当我运行manage.pysyncdb时,它无法在我的virtualenv中的INSTALLED_APPS中找到任何应用程序。它可以很好地拾取系统安装的应用程序,但当它尝试仅导入 virtualenv 应用程序时会失败。
My problem is in getting manage.py syncdb to run within a virtualenv.
It was working fine at one point, but seems to have broken sometime around when I installed South and updated pip and distribute.
Anyways, when the virtualenv is activated, I can import apps fine within the interactive interpreter. Running through mod_wsgi, the apps are imported as well, and the site can run.
When I run manage.py syncdb, it fails to find any app in INSTALLED_APPS that is in my virtualenv. It picks up system-installed apps fine, but fails when it tries to import virtualenv only apps.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗨,这是一个老问题,但看到它没有得到解答。不确定您要做什么,但基本上有两种模式可以使用 virtualenv,
在第一种情况下,您需要首先激活 virtualenv使用源 venv/bin/activate,在部署时,您需要确保为您的网站代码激活 virtualenv。就我个人而言,我更喜欢以下方法来确保您的路径设置正确。 (我在开发时也将其添加到我的manage.py中,所以我不必担心首先激活环境。
修改后的manage.py
这有效,由于我构建项目的方式,你必须将其更改为你的目录我的项目的结构如下:
Hi This is an old question, but saw its not answered. Not sure what you are attempting to do, but there are basically two modes you can use virtualenv,
In the first case, you need to first Activate your virtualenv with source venv/bin/activate, for when you deploy, you need to ensure that the virtualenv is activated for your website code. Personally i prefer the following approach to ensuring your path is set correctly. (I also add this to my manage.py when doing development, so i dont have to worry about activating the environment first.
Modified manage.py
This works, due to how i structure my projects, you would have to change it to your directory structure. My projects are structured like so:
我有一个简单的解决方案,
只需从虚拟环境的 bin 中的 python 启动 manage.py 即可。
所以说你的Python在这里 /home/tom/environments/my_env/bin/python 你可以像这样启动manage.py:
/home/tom/environments/my_env/bin/python manage.pysyncdb
然后创建一个符号链接到在你的 django 项目中创建虚拟环境的 python 并将其命名为 env_python 然后你可以这样做:
./env_python manage.pysyncdb
I have a simple solution to this
Just launch manage.py from the python in the bin of your virtual environment.
So say your python is here /home/tom/environments/my_env/bin/python you could launch manage.py like so:
/home/tom/environments/my_env/bin/python manage.py syncdb
then just create a symlink to the virtual environment's python inside your django project and call it env_python then you can do this:
./env_python manage.py syncdb