11

I'm trying to convert my python project into an exe using Py2Exe. It is worth noting that cx_freeze complains about the same three "missing modules", along with several dozen others. The problem is, no one anywhere tells how to resolve this.

I'm building on MS Windows XP 32-bit (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.

#!/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). It runs just peachy on Ubuntu, and from python redstring.py, but I can't get the thing to compile down to an .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.

MERose
  • 4,048
  • 7
  • 53
  • 79
CodeMouse92
  • 6,840
  • 14
  • 73
  • 130
  • Does the project run under windows? – Eric Nov 11 '14 at 21:58
  • Affirmative. python redstring.py in Windows XP cmd brings it up without any problems at all. – CodeMouse92 Nov 11 '14 at 21:58
  • Have you tried this : http://stackoverflow.com/questions/10098444/py2exe-include-modules-when-should-they-be-managed-manually ? – Eric Nov 11 '14 at 22:01
  • Well, if you mean using the py2exe option 'include': 'platform', yeah, while it didn't throw any errors, it also didn't solve the problem. – CodeMouse92 Nov 11 '14 at 22:03

2 Answers2

10

win32api and win32con are part of Mark Hammond's Python Windows extensions (aka pywin32). readline is a module that is used (if present) by some code interacting with the console.

Both readline and pywin32 are optional modules/packages that are not abolutely required but will be used when present.

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). 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.

theller
  • 2,809
  • 19
  • 19
  • I had tested thoroughly - the script did not require these at all, however, py2exe would not create an executable unless it had them. – CodeMouse92 Nov 12 '14 at 16:28
  • 1
    Ah, now I see the problem: you are missing the 'console=["redstring"]' line in the setup() function call. This specifies the executable that you want to be created. – theller Nov 12 '14 at 17:07
  • Yeah, I spotted that later, too. Good catch. In my case, that needed to be 'windows=["redstring"]', due to the fact this is GUI, but yes. If you edit your answer (since, yes, it works on script compile, but I omitted that line, so no executable), I'll accept the answer. – CodeMouse92 Nov 12 '14 at 21:12
8

So, it would happen that these libraries were never installed to begin with. Python may be "batteries included", but not to this extent. 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. (You cannot install pywin32 from pip at the moment, unfortunately.)

readline is not compatible with Windows, yet it asks for it. You actually have to install pyreadline, which is easiest from pip install pyreadline.

That should resolve all of those issues for py2exe. I'm still having trouble, but it's different trouble, so it's a different question.

Community
  • 1
  • 1
CodeMouse92
  • 6,840
  • 14
  • 73
  • 130
  • Actually I am printing like "Hello world", how do I check after converting to .exe that it's printing, means my conversion works fine. – Piyush S. Wanare Aug 03 '18 at 07:40