簡體   English   中英

Py2exe ImportError:沒有名為外殼程序的模塊

[英]Py2exe ImportError: No module named shell

我的代碼是:

from win32com.shell import shellcon
from win32com.shell.shell import ShellExecuteEx

它在IDLE中工作正常,但是在我執行了exe文件后,我得到了錯誤:

File "Myfile.py", line 1, in <module>
ImportError: No module named shell

py2exe為什么不能導入win32com.shell

以下內容可能會對您有所幫助: py2exe.org win32com.shell

該鏈接將問題描述為win32com執行“魔術”以允許在運行時加載COM擴展。 這些擴展位於站點軟件包的win32comext目錄中,無法直接加載。 將win32com的__path__變量修改為指向win32com和win32comext。 將此運行時間更改為__path__會使py2exe的modulefinder跳閘,因此必須提前告知它。

以下是代碼,可能是來自SpamBayes的源代碼,該代碼處理了相同的問題,因此類似的方法可能對您有用:

# ...
# ModuleFinder can't handle runtime changes to __path__, but win32com uses them
try:
    # py2exe 0.6.4 introduced a replacement modulefinder.
    # This means we have to add package paths there, not to the built-in
    # one.  If this new modulefinder gets integrated into Python, then
    # we might be able to revert this some day.
    # if this doesn't work, try import modulefinder
    try:
        import py2exe.mf as modulefinder
    except ImportError:
        import modulefinder
    import win32com, sys
    for p in win32com.__path__[1:]:
        modulefinder.AddPackagePath("win32com", p)
    for extra in ["win32com.shell"]: #,"win32com.mapi"
        __import__(extra)
        m = sys.modules[extra]
        for p in m.__path__[1:]:
            modulefinder.AddPackagePath(extra, p)
except ImportError:
    # no build path setup, no worries.
    pass

from distutils.core import setup
import py2exe
# The rest of the setup file.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM