2012-08-29 104 views
0

我有,這httpd.conf中與mod_wsgi的CentOS中安裝的Django,導入錯誤:沒有模塊名爲OS

NameVirtualHost *:80 
<VirtualHost *:80> 
    ServerName www.hello2.ch 
    DocumentRoot /home/django_www/hello 
    WSGIScriptAlias//var/www/django_www/hardi/django.wsgi 
    ErrorLog /var/www/django_www/hardi/error_log 
    CustomLog /var/www/django_www/hardi/access_log common 
</VirtualHost> 

<VirtualHost *:80> 
    DocumentRoot /var/www/html 
</VirtualHost> 

VI/etc/hosts中

127.0.0.1  localhost.localdomain localhost 
128.178.131.89 www.hello2.ch 
128.178.131.89 ohtersite.ch 

蟒蛇2.5,mod_wsgi的-2.5/root/epd-5.1.0/lib/libpython2.5.so.1.0:已安裝!

LDD /root/epd-5.1.0/bin/python

libpython2.5.so.1.0 => /root/epd-5.1.0/lib/libpython2.5.so.1.0 (0x00002b1bb7333000) 
libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003da0600000) 
libdl.so.2 => /lib64/libdl.so.2 (0x0000003d9fe00000) 
libutil.so.1 => /lib64/libutil.so.1 (0x0000003dadc00000) 
libm.so.6 => /lib64/libm.so.6 (0x0000003da0200000) 
libc.so.6 => /lib64/libc.so.6 (0x0000003d9fa00000) 
/lib64/ld-linux-x86-64.so.2 (0x0000003d9f600000) 

回聲$ LD_LIBRARY_PATH

/root/epd-5.1.0/lib/

但是當我嘗試加載網頁,我碰到下面的error_log:

'import site' failed; use -v for traceback 
[Wed Aug 29 11:52:57 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) 
[Wed Aug 29 11:52:57 2012] [notice] Digest: generating secret for digest authentication ... 
[Wed Aug 29 11:52:57 2012] [notice] Digest: done 
[Wed Aug 29 11:52:57 2012] [notice] mod_python: Creating 4 session mutexes based on 256 max processes and 0 max threads. 
[Wed Aug 29 11:52:57 2012] [notice] Apache/2.2.3 (Red Hat) configured -- resuming normal operations 
[Wed Aug 29 11:55:00 2012] [error] [client 66.249.72.187] Symbolic link not allowed or link target not accessible: /var/www/html/app/webroot/w3 
[Wed Aug 29 11:58:30 2012] [error] [client 66.249.72.187] Symbolic link not allowed or link target not accessible: /var/www/html/app/webroot/w3 
[Wed Aug 29 12:01:58 2012] [error] [client 66.249.72.187] Symbolic link not allowed or link target not accessible: /var/www/html/app/webroot/w3 
[Wed Aug 29 12:05:30 2012] [error] [client 66.249.72.187] Symbolic link not allowed or link target not accessible: /var/www/html/app/webroot/w3 
[Wed Aug 29 12:09:00 2012] [error] [client 66.249.72.187] Symbolic link not allowed or link target not accessible: /var/www/html/app/webroot/w3 
[Wed Aug 29 12:12:29 2012] [error] [client 66.249.72.187] Symbolic link not allowed or link target not accessible: /var/www/html/app/webroot/w3 
[Wed Aug 29 12:14:06 2012] [error] [client 178.33.137.225] Symbolic link not allowed or link target not accessible: /var/www/html/app/webroot/w3 
[Wed Aug 29 12:15:59 2012] [error] [client 66.249.72.187] Symbolic link not allowed or link target not accessible: /var/www/html/app/webroot/w3 
Could not find platform independent libraries <prefix> 
Could not find platform dependent libraries <exec_prefix> 
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] 
'import site' failed; use -v for traceback 
Could not find platform independent libraries <prefix> 
Could not find platform dependent libraries <exec_prefix> 
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] 
.... 
'import site' failed; use -v for traceback 
[Wed Aug 29 12:17:47 2012] [notice] caught SIGTERM, shutting down 
Could not find platform independent libraries <prefix> 
Could not find platform dependent libraries <exec_prefix> 
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] 
'import site' failed; use -v for traceback 
[Wed Aug 29 12:17:47 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) 
[Wed Aug 29 12:17:47 2012] [notice] Digest: generating secret for digest authentication ... 
[Wed Aug 29 12:17:47 2012] [notice] Digest: done 
[Wed Aug 29 12:17:47 2012] [notice] mod_python: Creating 4 session mutexes based on 256 max processes and 0 max threads. 
[Wed Aug 29 12:17:47 2012] [notice] Apache/2.2.3 (Red Hat) configured -- resuming normal operations 
[Wed Aug 29 12:18:01 2012] [error] Traceback (most recent call last): 
[Wed Aug 29 12:18:01 2012] [error] File "/var/www/django_www/hardi/django.wsgi", line 1, in <module> 
[Wed Aug 29 12:18:01 2012] [error]  import os 
[Wed Aug 29 12:18:01 2012] [error] ImportError: No module named os 

任何想法,如何讓Django的與mod_wsgi的工作,和浩w我能否使第一個VirtualHost條目與www.hello2.ch網頁以及第二個VirtualHost條目中的所有其他條目匹配?

+0

當您在命令行鍵入'python'時,python shell會打開嗎? – chucksmash

+0

是的,它打開..... – Kreshnik

+0

嗯。好吧,在shell中嘗試'import os'。如果你得到相同的導入錯誤,那麼問題出在你的python安裝上,而不是mod_wsgi或django。 – chucksmash

回答

0

根據你的錯誤,看起來好像有幾件事情可以繼續。然而,我不會將所有這些都置於評論之中,而是作爲回答發佈。

在我django.wsgi文件我有以下兩行更改PATH環境變量,讓蟒蛇導入包從我的Django項目:

import sys 
sys.path.append('/path/to/mysite.com/app/mydjangoproject') 

你還需要確保你加入按照您的httpd.conf將要使用的Django與VirtualHost內:

<Directory /path/to/mysite.com/app/mydjangoproject> 
    Order allow,deny 
    Allow from all 
</Directory> 

編輯:

w ^關於您在評論中提到的錯誤消息中提到的符號鏈接,我不太確定該怎麼做。如果你只是想用它來讓apache的訪問是位於DocumentRoot以外的資源,你要添加的Options FollowSymLinks指令爲Directory包含符號鏈接

+0

我只是想刪除sym鏈接,它指向一個不存在的文件。 – Kreshnik

+0

我想說的是,盡一切辦法。這聽起來像它最初創建的意圖不再相關,如果它指向@什麼都不是。 – chucksmash

+0

[root @ lts5srv1〜]#ldd /usr/lib64/httpd/modules/mod_wsgi.so - > libpython2.5.so.1.0 =>找不到... – Kreshnik

1

運行在mod_wsgi.so「LDD」 。

問題很可能是它找到了不同的Python版本。也可能是因爲你的Python不在標準位置,它不知道在哪裏找到安裝。

在後者的情況下,加在全球範圍內,虛擬主機的外部,在Apache配置:

WSGIPythonHome /root/epd-5.1.0 

的值應該對應於sys.prefix的從你的Python打印時運行的值。

import sys 
print sys.prefix 
+0

現在,我重新啓動apache時出現此錯誤:/- >啓動httpd:httpd:/etc/httpd/conf/httpd.conf的第202行的語法錯誤:無法將/etc/httpd/modules/mod_wsgi.so加載到服務器:libpython2.5.so.1.0:can not打開共享目標文件:沒有這樣的文件或目錄 – Kreshnik

+0

根據http://code.google.com/p/modwsgi/wiki/InstallationIssues#Unable_To_Find_Python_Shared_Library上的文檔,將LD_RUN_PATH環境變量設置爲包含Python庫的目錄,因此可以在運行時找到不在標準位置。 LD_RUN_PATH =/root/epd-5.1.0/lib make –

相關問題