2017-12-28 4 views
0

Windows 7에서 libcairo-2.dll을로드하는 데 매우 이상한 문제가 있습니다.이 스크립트는 컴파일하기 전에 작동합니다. Windows 7을 사용하여 컴파일하고 있습니다. PyInstaller DLL libCairo-2.dll은 새 Windows 7에서는로드되지 않지만 Windows 10에서는 작동합니다.

내가 컴파일 환경을 준비하는 방법입니다

setup\python-3.6.4.exe /quiet InstallAllUsers=1 TargetDir=C:\Python 
setx path "%path%;C:\Python;" 
setup\visualcppbuildtools_full.exe /Passive 
C:\Python\python -m pip install pyinstaller 
C:\Python\python -m pip install six 
C:\Python\python -m pip install cairosvg 
pause 

을 그리고 여기에 내가 윈도우 7 사용하여 컴파일 할 매우 간단 main.py입니다 :

import ctypes 
import os 
import sys 
#include dlls 
pathname = os.path.dirname(os.path.realpath(sys.argv[0])) 
ctypes.windll.kernel32.SetDllDirectoryW(pathname) 
ctypes.CDLL(pathname+'\\freetype6.dll') 
ctypes.CDLL(pathname+'\\libcairo-2.dll') 
ctypes.CDLL(pathname+'\\libexpat-1.dll') 
ctypes.CDLL(pathname+'\\libfontconfig-1.dll') 
ctypes.CDLL(pathname+'\\libpng14-14.dll') 
ctypes.CDLL(pathname+'\\zlib1.dll') 
print(pathname) 
#import stuff 
import cairosvg 
#make svg file 
svg_code = """ 
    <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 1000 1000" direction="rtl" xml:lang="fa"> 
     <title>...</title> 
     <desc>...</desc> 
     <text x="0" y="10" font-size = "22" font-family="Arial"> 
      <tspan x="10" dy="1.2em">Test</tspan> 
     </text> 
    </svg> 
""" 
#convert 
cairosvg.svg2svg(bytestring=svg_code, write_to="converted.svg") 
cairosvg.svg2pdf(bytestring=svg_code, write_to="converted.pdf") 
cairosvg.svg2png(bytestring=svg_code, write_to="converted.png") 
cairosvg.svg2ps (bytestring=svg_code, write_to="converted.ps") 

프로젝트 파일은 다음과 같습니다

main.py 
freetype6.dll 
libcairo-2.dll 
libexpat-1.dll 
libfontconfig-1.dll 
libpng14-14.dll 
zlib1.dll 

은 내가 컴파일하려면이 명령을 사용

C:\Python\python -m PyInstaller --add-data *.dll;. --clean --onedir --noupx --name "main-win" main.py 

이 오류없이 컴파일 난 신선한 윈도우 10에서 컴파일 된 버전을 실행할 수 있습니다하지만 아래 신선한 윈도우 7, 내가 오류에 대한 컴파일 된 버전 실행하면

[3000] PyInstaller Bootloader 3.x 
[3000] LOADER: executable is C:\Users\Admin\Desktop\main-win_debug\main-win.exe 
[3000] LOADER: homepath is C:\Users\Admin\Desktop\main-win_debug 
[3000] LOADER: _MEIPASS2 is NULL 
[3000] LOADER: archivename is C:\Users\Admin\Desktop\main-win_debug\main-win.exe 
[3000] LOADER: No need to extract files to run; setting extractionpath to homepath 
[3000] LOADER: SetDllDirectory(C:\Users\Admin\Desktop\main-win_debug) 
[3000] LOADER: Already in the child - running user's code. 
[3000] LOADER: Python library: C:\Users\Admin\Desktop\main-win_debug\python36.dll 
[3000] LOADER: Loaded functions from Python library. 
[3000] LOADER: Manipulating environment (sys.path, sys.prefix) 
[3000] LOADER: Pre-init sys.path is C:\Users\Admin\Desktop\main-win_debug\base_library.zip;C:\Users\Admin\Desktop\main-win_debug 
[3000] LOADER: sys.prefix is C:\Users\Admin\Desktop\main-win_debug 
[3000] LOADER: Setting runtime options 
[3000] LOADER: Initializing python 
[3000] LOADER: Overriding Python's sys.path 
[3000] LOADER: Post-init sys.path is C:\Users\Admin\Desktop\main-win_debug\base_library.zip;C:\Users\Admin\Desktop\main-win_debug 
[3000] LOADER: Setting sys.argv 
[3000] LOADER: setting sys._MEIPASS 
[3000] LOADER: importing modules from CArchive 
[3000] LOADER: extracted struct 
[3000] LOADER: callfunction returned... 
[3000] LOADER: extracted pyimod01_os_path 
[3000] LOADER: callfunction returned... 
[3000] LOADER: extracted pyimod02_archive 
[3000] LOADER: callfunction returned... 
[3000] LOADER: extracted pyimod03_importers 
[3000] LOADER: callfunction returned... 
[3000] LOADER: Installing PYZ archive with Python modules. 
[3000] LOADER: PYZ archive: out00-PYZ.pyz 
[3000] LOADER: Running pyiboot01_bootstrap.py 
[3000] LOADER: Running pyi_rth_multiprocessing.py 
[3000] LOADER: Running pyi_rth_pkgres.py 
[3000] LOADER: Running pyi_rth_win32comgenpy.py 
[3000] LOADER: Running main.py 
C:\Users\Admin\Desktop\main-win_debug 
Traceback (most recent call last): 
    File "C:\Users\Admin\Desktop\main.py", line 29, in <module> 
    File "<frozen importlib._bootstrap>", line 971, in _find_and_load 
    File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked 
    File "<frozen importlib._bootstrap>", line 665, in _load_unlocked 
    File "C:\Python\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module 
    File "C:\Python\lib\site-packages\cairosvg\__init__.py", line 29, in <module> 
    File "<frozen importlib._bootstrap>", line 971, in _find_and_load 
    File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked 
    File "<frozen importlib._bootstrap>", line 665, in _load_unlocked 
    File "C:\Python\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module 
    File "C:\Python\lib\site-packages\cairosvg\surface.py", line 24, in <module> 
    File "<frozen importlib._bootstrap>", line 971, in _find_and_load 
    File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked 
    File "<frozen importlib._bootstrap>", line 665, in _load_unlocked 
    File "C:\Python\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module 
    File "C:\Python\lib\site-packages\cairocffi\__init__.py", line 41, in <module> 
    File "C:\Python\lib\site-packages\cairocffi\__init__.py", line 38, in dlopen 
OSError: dlopen() failed to load a library: cairo/cairo-2 
[3000] Failed to execute script main 
[3000] LOADER: OK. 
[3000] LOADER: Cleaning up Python interpreter. 

을 여기에 소스 파일을 포함 시켰습니다 :

나는 많은 것들을 테스트했으며 이것을 이해할 수 없습니다. 누군가 나를 도울 수 있을까요?

감사합니다.

답변

0

다음은 해결책입니다. 프로그램이 실행될 때마다 cairo 호출 전에 아래 코드를로드해야합니다. 이것을 프로그램 상단에 넣는 것이 가장 좋습니다.

관련 문제