从使用ImageMagick的代码中使用pyinstaller生成exe

从使用ImageMagick的代码中使用pyinstaller生成exe,imagemagick,pyinstaller,Imagemagick,Pyinstaller,我编写了一个简单的代码,它使用ImageMagick将PDF转换为JPG,如下所示 import os from wand.color import Color from wand.image import Image if __name__ == "__main__": source_file = os.path.join(os.getcwd(), "sample.pdf") target_file = os.path.join(os.getcwd(), "sample.jp

我编写了一个简单的代码,它使用ImageMagick将PDF转换为JPG,如下所示

import os
from wand.color import Color
from wand.image import Image

if __name__ == "__main__":
    source_file = os.path.join(os.getcwd(), "sample.pdf")
    target_file = os.path.join(os.getcwd(), "sample.jpg")

    with Image(filename=source_file) as img:
        img.alpha_channel = False
        img.background_color = Color('white')
        img.resize(600, 870)
        img.format = 'jpeg'
        img.save(filename=target_file)
python应用程序正在运行,但当我通过命令
pyinstaller extract.py
将其转换为.exe并运行生成的.exe时,出现以下错误:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
  File "C:\Users\Abouzar\pydev\extract\src\build\cover_extract\out00-PYZ.pyz\wand.color", line 9, in <module>
  File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
  File "C:\Users\Abouzar\pydev\extract\src\build\cover_extract\out00-PYZ.pyz\wand.api", line 1173, in <module>
  File "C:\Users\Abouzar\pydev\extract\src\build\cover_extract\out00-PYZ.pyz\ctypes", line 365, in __init__
WindowsError: [Error 126] The specified module could not be found
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“C:\Python27\Lib\site packages\PyInstaller\loader\pyi\u importers.py”,第270行,在load\u模块中
文件“C:\Users\Abouzar\pydev\extract\src\build\cover\u extract\out00 PYZ.PYZ\wand.color”,第9行,在
文件“C:\Python27\Lib\site packages\PyInstaller\loader\pyi\u importers.py”,第270行,在load\u模块中
文件“C:\Users\Abouzar\pydev\extract\src\build\cover\u extract\out00 PYZ.PYZ\wand.api”,第1173行,在
文件“C:\Users\Abouzar\pydev\extract\src\build\cover\u extract\out00 PYZ.PYZ\ctypes”,第365行,在u_init中__
WindowsError:[错误126]找不到指定的模块
有没有办法解决这个问题?

应该是
os.getcwd()
而不是
os.getcwd
。我很惊讶它居然能工作。@rth事实上,在我的python代码中是getcwd(),我只是从代码中粘贴了一个错误的副本,并将错误输出粘贴到了这里。我把正确的行改为。