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
そして、ここでは、私は、Windows 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
これはエラーなしでコンパイルされ、私は新鮮なWindowsの10でコンパイルされたバージョンを実行することができます。しかし、私は新鮮なWindows 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.
私はここにソースファイルを含めました: src.zip
私は多くのものをテストしましたが、これは分かりません。誰かが私を助けてくれますか?
ありがとうございました。