简体   繁体   English

Py2Exe“缺少模块”

[英]Py2Exe “Missing Modules”

I'm trying to convert my python project into an exe using Py2Exe. 我正在尝试使用Py2Exe将我的python项目转换为exe。 It is worth noting that cx_freeze complains about the same three "missing modules", along with several dozen others. 值得注意的是,cx_freeze抱怨同样的三个“缺失的模块”以及其他几十个。 The problem is, no one anywhere tells how to resolve this. 问题是,没有人知道如何解决这个问题。

I'm building on MS Windows XP 32-bit (VirtualBox). 我正在使用MS Windows XP 32位(VirtualBox)。

C:\Documents and Settings\Jason\Desktop\redstring2>python setup.py py2exe
running py2exe
running build_py
creating build
creating build\lib
copying redstring.py -> build\lib

  3 missing Modules
  ------------------
? readline                            imported from cmd, code, pdb
? win32api                            imported from platform
? win32con                            imported from platform
Building shared code archive 'dist\library.zip'.
Copy c:\windows\system32\python34.dll to dist
Copy C:\Python34\DLLs\select.pyd to dist\select.pyd
Copy C:\Python34\DLLs\_ssl.pyd to dist\_ssl.pyd
Copy C:\Python34\DLLs\_ctypes.pyd to dist\_ctypes.pyd
Copy C:\Python34\DLLs\_lzma.pyd to dist\_lzma.pyd
Copy C:\Python34\DLLs\_hashlib.pyd to dist\_hashlib.pyd
Copy C:\Python34\DLLs\pyexpat.pyd to dist\pyexpat.pyd
Copy C:\Python34\DLLs\_socket.pyd to dist\_socket.pyd
Copy C:\Python34\DLLs\_bz2.pyd to dist\_bz2.pyd
Copy C:\Python34\DLLs\unicodedata.pyd to dist\unicodedata.pyd

My setup.py is as follows. 我的setup.py如下。

#!/usr/bin/python python

from setuptools import setup
import py2exe

setup(name="Redstring",
    version="2.0",
    description="REDundant STRING generator",
    author="MousePaw Labs",
    url="http://www.mousepawgames.com/",
    author_email="info@mousepawgames.com",
    data_files=[("", ["redstring.png", "redstring_interface.glade"])],
    py_modules=["redstring"],
    )

This is a Python 3.4 project using GTK+ 3 (built in Glade). 这是一个使用GTK + 3(内置Glade)的Python 3.4项目。 It runs just peachy on Ubuntu, and from python redstring.py, but I can't get the thing to compile down to an .exe. 它在Ubuntu和python redstring.py上运行只是peachy,但是我无法将其编译成.exe。

So far I tried import platform , from platform import win32api , and all the like in both redstring.py and setup.py , along with importing platform via py2exe options in the setup file. 到目前为止,我尝试了import platformfrom platform import win32api ,以及redstring.pysetup.py ,以及通过安装文件中的py2exe选项导入平台。

So, it would happen that these libraries were never installed to begin with. 因此,从来没有安装过这些库。 Python may be "batteries included", but not to this extent. Python可能是“包含电池”,但不是这种程度。 However, I'm answering this because fixing it isn't the most obvious thing in the world to some (myself included). 但是,我正在回答这个问题,因为修复它并不是世界上最明显的事情(包括我自己)。

You need to install win32api (or pywin32, as it is officially called) from Sourceforge (at the moment, browse the files for the latest version, as the Download button links to README.txt) That will resolve win32con as well. 您需要从Sourceforge安装win32api(或正式调用的pywin32)(目前,浏览文件以获取最新版本,因为下载按钮链接到README.txt)这也将解析win32con。 (You cannot install pywin32 from pip at the moment, unfortunately.) (不幸的是,目前你无法从pip安装pywin32。)

readline is not compatible with Windows , yet it asks for it. readline与Windows不兼容 ,但它要求它。 You actually have to install pyreadline, which is easiest from pip install pyreadline . 你实际上必须安装pyreadline,这是从pip install pyreadline最容易的。

That should resolve all of those issues for py2exe. 这应解决py2exe的所有问题。 I'm still having trouble, but it's different trouble, so it's a different question. 我仍然遇到麻烦,但这是一个不同的麻烦,所以这是一个不同的问题。

win32api and win32con are part of Mark Hammond's Python Windows extensions (aka pywin32). win32api和win32con是Mark Hammond的Python Windows扩展(又名pywin32)的一部分。 readline is a module that is used (if present) by some code interacting with the console. readline是一些与控制台交互的代码使用(如果存在)的模块。

Both readline and pywin32 are optional modules/packages that are not abolutely required but will be used when present. readline和pywin32都是可选的模块/包,不是绝对必需的,但会在使用时使用。

All in all - py2exe notices that these modules/packages are referenced by some code which will be included into your exe (it even mentions the modules that reference these mod/packages: cmd, code, pdb, platform). 总而言之 - py2exe注意到这些模块/包被一些代码引用,这些代码将包含在你的exe中(它甚至提到了引用这些mod /包的模块:cmd,code,pdb,platform)。 I hope you have tested your script - in the 'non-compiled' form, if it works correctly than you can safely ignore these messages: they are only warnings. 我希望你已经测试了你的脚本 - 以'非编译'形式,如果它正常工作,你可以安全地忽略这些消息:它们只是警告。

The reason that no executable is built is that the line 'console=["redstring"]' or 'windows=["redstring"]' is missing in the setup() call. 没有构建可执行文件的原因是setup()调用中缺少'console = [“redstring”]'或'windows = [“redstring”]'。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM