【问题标题】:`ImportError: No module named pyautocad` whenever I try to create an exe with py2exe`ImportError: No module named pyautocad` 每当我尝试使用 py2exe 创建 exe 时
【发布时间】:2016-10-11 18:43:06
【问题描述】:

不确定发生了什么以及为什么 py2exe 无法找到该模块。我的setup.py文件如下:

from distutils.core import setup
import py2exe
import shutil

setup(windows=["RotoWorks.py"], options={'py2exe': {'includes': ['pyautocad']}})

我不确定从哪里开始或如何解释 py2exe 无法导入 pyautocad 的原因。如果我打开 IDLE 或只打开 python shell 并输入import pyautocad,它可以正常导入。

【问题讨论】:

    标签: python python-2.7 py2exe


    【解决方案1】:

    您需要包含您的 pyautocad.pyd。 Py2exe 的结构不同于 python 解释器,它会查看模块的站点包...

    你可以这样做(没有确切的代码,只是结构性建议......!):

    import glob, shutil, py2exe
    
    correct_Pyd_file = 'none'
    for file in glob.glob('*.pyd'):
       if file.startswith("pyautocad"):
          correct_Pyd_file = file
    
    correct_Pyd_file.strip('.pyd') #strip ending for py2exe
    
    
    opts = {'py2exe': {'compressed': True, "dll_excludes": ["MSVCP90.dll"], "includes" : ["sip"]}}
    
    setup(console=[{"script" : "main.py"}], options=opts, data_files=correct_Pyd_file)
    shutil.rmtree('build', ignore_errors=True)     #Remove the build folder
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-18
      • 1970-01-01
      • 2012-10-25
      • 2013-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-19
      相关资源
      最近更新 更多