Django 和 Buildout 部署问题
我正在尝试通过构建部署现有的 django 项目,大致遵循此处。
我的 buildout.cfg 文件是:
[buildout]
parts = django python
develop = .
eggs = myproject
[django]
recipe = djangorecipe
version = 1.2.3
project = myproject
projectegg = myproject
settings = settings
wsgi = true
eggs = ${buildout:eggs}
[python]
recipe = zc.recipe.egg
interpreter = python
eggs = ${buildout:eggs}
有两个问题:
- 首先,如果我通过 ./bin/python 调用 python 解释器,我会收到 import myproject 的导入错误
- 其次,如果我尝试加载 django.wsgi 文件,我还会出现 apache 错误
[Sun Oct 03 11:57:37 2010] [error] [client ::1] mod_wsgi (pid=5045): Target WSGI script '/usr/src/django/myproject/bin/django.wsgi' cannot be loaded as Python module. [Sun Oct 03 11:57:37 2010] [error] [client ::1] mod_wsgi (pid=5045): SystemExit exception raised by WSGI script '/usr/src/django/myproject/bin/django.wsgi' ignored. [Sun Oct 03 11:57:37 2010] [error] [client ::1] Traceback (most recent call last): [Sun Oct 03 11:57:37 2010] [error] [client ::1] File "/usr/src/django/myproject/bin/django.wsgi", line 20, in [Sun Oct 03 11:57:37 2010] [error] [client ::1] application = djangorecipe.wsgi.main('myproject.settings', logfile='') [Sun Oct 03 11:57:37 2010] [error] [client ::1] File "/usr/src/django/myproject/eggs/djangorecipe-0.20-py2.6.egg/djangorecipe/wsgi.py", line 15, in main [Sun Oct 03 11:57:37 2010] [error] [client ::1] sys.exit(1)
我的 django.wsgi 文件是(根据建议的更改更新):
#!/usr/bin/python import sys sys.path[0:0] = [ '/usr/src/django/myproject/src', '/usr/src/django/myproject/eggs/djangorecipe-0.20-py2.6.egg', '/usr/src/django/myproject/eggs/zc.recipe.egg-1.3.2-py2.6.egg', '/usr/src/django/myproject/eggs/zc.buildout-1.5.1-py2.6.egg', '/usr/local/lib/python2.6/dist-packages', '/usr/local/lib/python2.6/dist-packages', '/usr/src/django/myproject/parts/django', '/usr/src/django/myproject/eggs/setuptools-0.6c12dev_r85190-py2.6.egg', '/usr/src/django/myproject/parts/django', '/usr/src/django/myproject', '/usr/src/django/myproject/src(/usr/src/django/myproject)', '/usr/src/django/myproject', ] import djangorecipe.wsgi application = djangorecipe.wsgi.main('myproject.settings', logfile='')
我的 bin/django 文件是:
#!/usr/bin/python import sys sys.path[0:0] = [ '/usr/src/django/myproject/src', '/usr/src/django/myproject/eggs/djangorecipe-0.20-py2.6.egg', '/usr/src/django/myproject/eggs/zc.recipe.egg-1.3.2-py2.6.egg', '/usr/src/django/myproject/eggs/zc.buildout-1.5.1-py2.6.egg', '/usr/local/lib/python2.6/dist-packages', '/usr/local/lib/python2.6/dist-packages', '/usr/src/django/myproject/parts/django', '/usr/src/django/myproject/eggs/setuptools-0.6c12dev_r85190-py2.6.egg', '/usr/src/django/myproject/parts/django', '/usr/src/django/myproject', '/usr/src/django/myproject/src(/usr/src/django/myproject)', '/usr/src/django/myproject', ] import djangorecipe.manage if __name__ == '__main__': djangorecipe.manage.main('myproject.settings')
导入或 apache 服务器似乎都不起作用
I am trying to deploy my existing django project via buildout, following loosely the instructions here.
my buildout.cfg file is:
[buildout]
parts = django python
develop = .
eggs = myproject
[django]
recipe = djangorecipe
version = 1.2.3
project = myproject
projectegg = myproject
settings = settings
wsgi = true
eggs = ${buildout:eggs}
[python]
recipe = zc.recipe.egg
interpreter = python
eggs = ${buildout:eggs}
There are two problems:
- First of all, if i invoke the python interpreter via ./bin/python, i get an import error with import myproject
- Secondly if i try to load the django.wsgi file, i also get an apache error
[Sun Oct 03 11:57:37 2010] [error] [client ::1] mod_wsgi (pid=5045): Target WSGI script '/usr/src/django/myproject/bin/django.wsgi' cannot be loaded as Python module. [Sun Oct 03 11:57:37 2010] [error] [client ::1] mod_wsgi (pid=5045): SystemExit exception raised by WSGI script '/usr/src/django/myproject/bin/django.wsgi' ignored. [Sun Oct 03 11:57:37 2010] [error] [client ::1] Traceback (most recent call last): [Sun Oct 03 11:57:37 2010] [error] [client ::1] File "/usr/src/django/myproject/bin/django.wsgi", line 20, in [Sun Oct 03 11:57:37 2010] [error] [client ::1] application = djangorecipe.wsgi.main('myproject.settings', logfile='') [Sun Oct 03 11:57:37 2010] [error] [client ::1] File "/usr/src/django/myproject/eggs/djangorecipe-0.20-py2.6.egg/djangorecipe/wsgi.py", line 15, in main [Sun Oct 03 11:57:37 2010] [error] [client ::1] sys.exit(1)
My django.wsgi file is (updated as per suggested changes):
#!/usr/bin/python import sys sys.path[0:0] = [ '/usr/src/django/myproject/src', '/usr/src/django/myproject/eggs/djangorecipe-0.20-py2.6.egg', '/usr/src/django/myproject/eggs/zc.recipe.egg-1.3.2-py2.6.egg', '/usr/src/django/myproject/eggs/zc.buildout-1.5.1-py2.6.egg', '/usr/local/lib/python2.6/dist-packages', '/usr/local/lib/python2.6/dist-packages', '/usr/src/django/myproject/parts/django', '/usr/src/django/myproject/eggs/setuptools-0.6c12dev_r85190-py2.6.egg', '/usr/src/django/myproject/parts/django', '/usr/src/django/myproject', '/usr/src/django/myproject/src(/usr/src/django/myproject)', '/usr/src/django/myproject', ] import djangorecipe.wsgi application = djangorecipe.wsgi.main('myproject.settings', logfile='')
my bin/django file is:
#!/usr/bin/python import sys sys.path[0:0] = [ '/usr/src/django/myproject/src', '/usr/src/django/myproject/eggs/djangorecipe-0.20-py2.6.egg', '/usr/src/django/myproject/eggs/zc.recipe.egg-1.3.2-py2.6.egg', '/usr/src/django/myproject/eggs/zc.buildout-1.5.1-py2.6.egg', '/usr/local/lib/python2.6/dist-packages', '/usr/local/lib/python2.6/dist-packages', '/usr/src/django/myproject/parts/django', '/usr/src/django/myproject/eggs/setuptools-0.6c12dev_r85190-py2.6.egg', '/usr/src/django/myproject/parts/django', '/usr/src/django/myproject', '/usr/src/django/myproject/src(/usr/src/django/myproject)', '/usr/src/django/myproject', ] import djangorecipe.manage if __name__ == '__main__': djangorecipe.manage.main('myproject.settings')
Neither the import or the apache server seem to be working
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
中设置了错误的egg依赖项,
你的问题是你在构建部分的配方
你将自己的myproject django项目设置为此
设置中的依赖项,你需要设置所有依赖于它的python Eggs(包) 如果您的 django 项目
例如,
使用 postgresql psycopg2 连接器、south 用于数据库迁移以及 django-debug-toolbar 和 django-extensions,则
您可以从此列表中排除您的 python 系统安装中的任何包。
从eggs设置中删除您的项目,这会混淆您的构建。
your problem is that you are setting wrong your egg dependancies in your recipe
in the buildout part the line
you are setting your own myproject django project as a dependancy
in this settings, you need to set all the python eggs (packages) that are dependencies for your django project
for example
if your project are using postgresql psycopg2 connector, south for database migrations and django-debug-toolbar and django-extensions
you can except from this list any package that you have in your python system install.
remove your project from the eggs setting, this one confuse your buildout.
可能您需要为项目设置额外的路径,以便将其放在 python 路径上。你能粘贴你的 django.wsgi 和 django 文件吗?
尝试这个配置:
您还可以确保 django.wsgi 具有可执行权限
Probably you need to set extra path to your project so it would be put on python path. Could you paste your django.wsgi and django files ?
Try this config:
You can also make sure that django.wsgi has executable rights
看起来很奇怪的一件事: bin/django 和 bin/django.wsgi 文件中的
'/usr/src/django/myproject/src(/usr/src/django/myproject)'
。我从来没见过()那种东西。看起来它可能会破坏东西。
最好的选择:运行
并查看 python 本身认为它的路径是什么。构建设置一切正常,但你的脚本中有一些我以前从未见过的东西。
另一种选择:您确定您的实际代码不包含最终导致应用程序导入错误的导入错误(如果您依赖 PIL 或 cx_oracle 等 C 级库,有时会发生这种情况)。
The one thing that looks really strange:
'/usr/src/django/myproject/src(/usr/src/django/myproject)'
in both your bin/django and bin/django.wsgi file.I've never seen that () stuff. It looks like it might break things.
Best bet: just run
and see what python itself thinks its path is. Buildout sets it up OK, but you've got something I've never seen before in your script.
Another alternative: are you sure your actual code doesn't include import errors that are ending up as import errors of your application (this can sometimes happen if you depend on c-level libraries like PIL or cx_oracle).
对我有用的是根本不触及构建本身,只需确保执行 .wsgi 脚本时所有鸡蛋都在 PYTHONPATH 中。
.wsgi
脚本本身如下所示:What worked for me was just not touching the buildout itself at all, and simply making sure all the eggs were in
PYTHONPATH
when the.wsgi
script is executed. The.wsgi
script itself looked like the following: