0

Pythonモジュールをインポートすると、Apacheで実行するとdjangoで例外がスローされます。同じソース コードが django 開発サーバーで正常に動作します。コマンドラインからモジュールをインポートすることもできます。モジュールは Python SWIG ライブラリです。私は Web で同様の問題を調査しましたが、何も役に立ちませんでした (スラッシュ、PYTHONPATH の設定、権限チェックなど)。

投稿の最後の印刷ステートメントでファイル名に二重スラッシュがあることは理解していますが、私の理解では (間違っている可能性があります)、これで問題ありません。

1 つが失敗する 3 つのシナリオを次に示します。

コマンド ラインから次のコマンドを実行すると、正常に動作します。

import QuantLib

django 開発サーバーを使用すると、ビューで次のコードをエラーなしで実行できます。

from django.http import HttpResponse  
import sys  
import QuantLib  
def home(request):
    return HttpResponse("This is a test.")

ここで、次のスクリプトを使用して apache に移動すると、上記と同じビューを使用して次のエラーが発生します。ファイルは django_wsgi です:

import os, sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'tgVAR.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

** * ** *ブラウザのエラー

ImportError at /  
DLL load failed: The specified module could not be found.  
Request Method:     GET  
Request URL:    (here is the url)
Django Version:     1.4  
Exception Type:     ImportError  
Exception Value:    DLL load failed: The specified module could not be found.  

Exception Location:     D:\Program Files (x86)\Python27\lib\site-packages\QuantLib\QuantLib.py in swig_import_helper, line 29  
Python Executable:  D:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin\httpd.exe  
Python Version:     2.7.2  
Python Path:    

['D:\\Program Files (x86)\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg',
 'C:\\Windows\\system32\\python27.zip',
 'D:\\Program Files (x86)\\Python27\\Lib',
 'D:\\Program Files (x86)\\Python27\\DLLs',
 'D:\\Program Files (x86)\\Python27\\Lib\\lib-tk',
 'D:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2',
 'D:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\bin',
 'D:\\Program Files (x86)\\Python27',
 'D:\\Program Files (x86)\\Python27\\lib\\site-packages',
 'D:\\Program Files (x86)\\Python27\\Lib\\site-packages\\QuantLib',
 'D:\\Program Files (x86)\\Django-1.4',
 'D:\\Home',
 'D:\\Home\\tgVAR',
 'c:/Home/test1/test1']

Server time:    Sat, 25 Aug 2012 14:02:27 -0400  

** * *** *失敗するソースコード D:\Program Files (x86)\Python27\lib\site-packages\QuantLib\QuantLib.py in swig_import_helper:

from sys import version_info  
if version_info >= (2,6,0):  
    def swig_import_helper():  
        from os.path import dirname  
        import imp  
        fp = None  
        try:
            fp, pathname, description = imp.find_module('_QuantLib', [dirname(__file__)])
        except ImportError:
            import _QuantLib
            return _QuantLib
        if fp is not None:
            try:    
                #TG start
                print '***********TG***************'
                print fp
                print pathname
                print description
                print '****************************'
            #TG end
                _mod = imp.load_module('_QuantLib', fp, pathname, description)
            finally:
                fp.close()
            return _mod
    _QuantLib = swig_import_helper()
    del swig_import_helper
else:
    import _QuantLib
del version_info

** * ** * *** *例外がスローされたときの Apache のローカル変数:

Variable    Value  
fp  <closed file 'D:\Program Files (x86)\Python27\lib\site-packages\QuantLib\_QuantLib.pyd', mode 'rb' at 0x0429C5A0>  
imp <module 'imp' (built-in)>  
dirname <function dirname at 0x018F29B0>  
pathname    'D:\\Program Files (x86)\\Python27\\lib\\site-packages\\QuantLib\\_QuantLib.pyd'  
description ('.pyd', 'rb', 3)  

** * ** * *** *Apache での実行時のソース コード内の PRINT ステートメントからの出力

[Sat Aug 25 14:02:26 2012] [error] ***********TG***************  
[Sat Aug 25 14:02:26 2012] [error] <open file 'D:\\Program Files (x86)\\Python27\\lib\\site-packages\\QuantLib\\_QuantLib.pyd', mode 'rb' at 0x0429C5A0>  
[Sat Aug 25 14:02:26 2012] [error] D:\\Program Files (x86)\\Python27\\lib\\site-packages\\QuantLib\\_QuantLib.pyd  
[Sat Aug 25 14:02:26 2012] [error] ('.pyd', 'rb', 3)  
[Sat Aug 25 14:02:26 2012] [error] ****************************  

** * ** * *** *PYTHON インタラクティブ インタープリターからインポートする際のソース コード内の PRINT ステートメントからの出力

***********TG***************  
<open file 'D:\Program Files (x86)\Python27\Lib\site-packages\QuantLib\_QuantLib.pyd', mode 'rb' at 0x02879CD8>  
D:\Program Files (x86)\Python27\Lib\site-packages\QuantLib\_QuantLib.pyd  
('.pyd', 'rb', 3)  
****************************  

** * ** * *** *DJANGO 開発サーバー実行時のソースコードの PRINT ステートメントからの出力

***********TG***************  
<open file 'D:\Program Files (x86)\Python27\Lib\site-packages\QuantLib\_QuantLib.pyd', mode 'rb' at 0x0312AAC8>  
D:\Program Files (x86)\Python27\Lib\site-packages\QuantLib\_QuantLib.pyd  
('.pyd', 'rb', 3)  
****************************  
4

1 に答える 1

0

すべての SWIG 生成モジュールと同様に、QuantLib は純粋な Python モジュールではなく、基礎となる C++ 共有ライブラリ (libQuantLib.so と呼ばれる必要があります) に依存しています。これは Apache によってロード可能でなければなりません。たとえば、それが PATH にあること、ld がそれをキャッシュしたこと、または必要な権限があることを確認してください。

于 2012-08-27T07:16:48.617 に答える