Python - Py2exe 无法使用“电子邮件”构建 .exe 模块

发布于 2024-07-06 13:15:55 字数 604 浏览 5 评论 0原文

py2exe 不能与标准电子邮件模块一起

使用 我正在尝试使用 py2exe 将脚本转换为 exe。 构建过程显示:


以下模块似乎缺少

['email.Encoders', 'email.Generator', 'email.Iterators', 'email.MIMEBase', 'email.MIMEMultipart', 'email.MIMEText', 'email.Utils', 'email.base64MIME']

可执行文件不起作用。 不包括引用的模块。 我在互联网上对此进行了研究,发现 py2exe 在标准 lib 电子邮件模块中使用的延迟导入存在问题。 不幸的是我还没有成功找到解决这个问题的方法。 有人可以帮忙吗?

谢谢你,

PS 脚本中的导入如下所示:

代码:全选 导入字符串、时间、sys、os、smtplib 从 email.MIMEMultipart 导入 MIMEMultipart 从 email.MIMEBase 导入 MIMEBase 从 email.MIMEText 导入 MIMEText 从电子邮件导入编码器

py2exe does not work with the standard email module

Hello. I am trying to use py2exe for converting a script into an exe. The build process shows this:


The following modules appear to be missing

['email.Encoders', 'email.Generator', 'email.Iterators', 'email.MIMEBase', 'email.MIMEMultipart', 'email.MIMEText', 'email.Utils', 'email.base64MIME']

The executable does not work. The referenced modules are not included. I researched this on the Internet and I found out that py2exe has a problem with the Lazy import used in the standard lib email module. Unfortunately I have not succeeded in finding a workaround for this problem. Can anyone help?

Thank you,

P.S.
Imports in the script look like this:

Code: Select all
import string,time,sys,os,smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

人心善变 2024-07-13 13:15:55

看看这个问题 how-to-package-twisted-program-with- py2exe 似乎是同样的问题。

给出的答案是在命令行上显式地将模块包含到 py2exe 中。

Have a look at this question how-to-package-twisted-program-with-py2exe it seems to be the same problem.

The answer given there is to explicitly include the modules on the command line to py2exe.

暮年慕年 2024-07-13 13:15:55

您使用什么版本的 Python? 如果您使用的是 2.5 或 2.6,那么您应该像这样进行导入:

import string,time,sys,os,smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email import Encoders

我非常确定 py2exe 的 modulefinder 可以正确找到电子邮件包,如果您正确使用它(即在 Python 2.5+ 中使用上述名称,或使用Python 2.4 中的旧名称-)。 当然,SpamBayes 安装脚本不需要显式包含电子邮件包,并且包含电子邮件模块也没有问题。

其他答案是正确的,因为如果您确实需要专门包含一个模块,则可以通过命令行使用“includes”选项,或者在调用安装程序时传递它们。

What version of Python are you using? If you are using 2.5 or 2.6, then you should be doing your import like:

import string,time,sys,os,smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email import Encoders

I'm pretty certain that py2exe's modulefinder can correctly find the email package if you use it correctly (i.e. use the above names in Python 2.5+, or use the old names in Python 2.4-). Certainly the SpamBayes setup script does not need to explicitly include the email package, and it includes the email modules without problem.

The other answers are correct in that if you do need to specifically include a module, you use the "includes" option, either via the command-line, or passing them in when you call setup.

孤凫 2024-07-13 13:15:55

使用“包含”选项。 请参阅:http://www.py2exe.org/index.cgi/ListOfOptions

Use the "includes" option. See: http://www.py2exe.org/index.cgi/ListOfOptions

甩你一脸翔 2024-07-13 13:15:55

如果您不必使用 py2exe,则 bbfreeze 效果更好,我已经尝试过使用电子邮件模块。 http://pypi.python.org/pypi/bbfreeze/0.95.4

If you don't have to work with py2exe, bbfreeze works better, and I've tried it with the email module. http://pypi.python.org/pypi/bbfreeze/0.95.4

傲世九天 2024-07-13 13:15:55

我通过在 setup.py 中显式包含缺少的模块来使其工作:

旧 setup.py:

setup(console = ['main.py'])

新 setup.py:

setup(console = ['main.py'], 
      options={"py2exe":{"includes":["email.mime.multipart","email.mime.text"]}})

I got it working by explicitly including missing modules in setup.py:

OLD setup.py:

setup(console = ['main.py'])

New setup.py:

setup(console = ['main.py'], 
      options={"py2exe":{"includes":["email.mime.multipart","email.mime.text"]}})
甚是思念 2024-07-13 13:15:55

在将我的应用程序从 py24 移植到 26 时,我遇到了同样的问题。

阅读http://www.py2exe.org/index.cgi/ExeWithEggs
如果最终找到以下解决方案:

在我的 application.py 中:

import email
import email.mime.text
import email.mime.base
import email.mime.multipart
import email.iterators
import email.generator
import email.utils

try:    
    from email.MIMEText import MIMEText
except:    
    from email.mime import text as MIMEText

在 setup.py 中:

import modulefinder
modulefinder.AddPackagePath("mail.mime", "base")
modulefinder.AddPackagePath("mail.mime", "multipart")
modulefinder.AddPackagePath("mail.mime", "nonmultipart")
modulefinder.AddPackagePath("mail.mime", "audio")
modulefinder.AddPackagePath("mail.mime", "image")
modulefinder.AddPackagePath("mail.mime", "message")
modulefinder.AddPackagePath("mail.mime", "application")

对于 py2exe 要使用在运行时加载的包,主要的事情似乎是您在应用程序中的某个位置显式导入应用程序所需的模块。
然后在 setup.py 中使用 moudlefinder.AddPackagePath( , ) 给 py2exe 提示,在哪里搜索 std 找不到的模块。 内省。
在应用程序中

while porting my app from py24 to 26 I had the same problem.

After reading http://www.py2exe.org/index.cgi/ExeWithEggs
if found finaly following solution:

in my application.py:

import email
import email.mime.text
import email.mime.base
import email.mime.multipart
import email.iterators
import email.generator
import email.utils

try:    
    from email.MIMEText import MIMEText
except:    
    from email.mime import text as MIMEText

in setup.py:

import modulefinder
modulefinder.AddPackagePath("mail.mime", "base")
modulefinder.AddPackagePath("mail.mime", "multipart")
modulefinder.AddPackagePath("mail.mime", "nonmultipart")
modulefinder.AddPackagePath("mail.mime", "audio")
modulefinder.AddPackagePath("mail.mime", "image")
modulefinder.AddPackagePath("mail.mime", "message")
modulefinder.AddPackagePath("mail.mime", "application")

For py2exe to work with packages loaded during runtime, the main thing seems to be that u explicitly import the modules needed by your app somewhere in your app.
And then give py2exe in setup.py with moudlefinder.AddPackagePath( , ) the hint, where to search for modules it couldn't find by std. introspection.
in the app

樱桃奶球 2024-07-13 13:15:55

这解决了我的问题:
在setup.py中编辑

includes = ["email"]

This solve my problem:
in setup.py edit

includes = ["email"]
我一直都在从未离去 2024-07-13 13:15:55

请尝试这个。 这适用于我的 py2exe 构建。 只需将“project_name.py”替换为您的主脚本即可。 EXTRA_INCLUDES 是您需要包含在构建中的包,例如电子邮件包。 我这也适合你。

from distutils.core import setup
    import py2exe, sys, os

    sys.argv.append('py2exe')

    EXTRA_INCLUDES = [
        "email.iterators", "email.generator", "email.utils", "email.base64mime", "email", "email.mime",
        "email.mime.multipart", "email.mime.text", "email.mime.base",
        "lxml.etree", "lxml._elementpath", "gzip"
    ]

    setup(
        options = {'py2exe': {'bundle_files': 1, 'compressed': True, 'includes': EXTRA_INCLUDES,
                    'dll_excludes': ['w9xpopen.exe','MSVCR71.dll']}},
        console = [{'script': "project_name.py"}],
        zipfile = None,
    )

Please try this. This works on my py2exe build. Just replace "project_name.py" with your main script. The EXTRA_INCLUDES are packages that you need to include in your build like email package. I this works with you also.

from distutils.core import setup
    import py2exe, sys, os

    sys.argv.append('py2exe')

    EXTRA_INCLUDES = [
        "email.iterators", "email.generator", "email.utils", "email.base64mime", "email", "email.mime",
        "email.mime.multipart", "email.mime.text", "email.mime.base",
        "lxml.etree", "lxml._elementpath", "gzip"
    ]

    setup(
        options = {'py2exe': {'bundle_files': 1, 'compressed': True, 'includes': EXTRA_INCLUDES,
                    'dll_excludes': ['w9xpopen.exe','MSVCR71.dll']}},
        console = [{'script': "project_name.py"}],
        zipfile = None,
    )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文