5

I am trying to use cx-freeze to create a static self-contained distribution of my app (The Spye Python Engine, www.spye.dk), however, when I run cx-freeze, it says:

Missing modules:
? _md5 imported from hashlib
? _scproxy imported from urllib
? _sha imported from hashlib
? _sha256 imported from hashlib
? _sha512 imported from hashlib
? _subprocess imported from subprocess
? configparser imported from apport.fileutils
? usercustomize imported from site

This is my setup.py:

#!/usr/bin/env python
from cx_Freeze import setup, Executable

includes = ["hashlib", "urllib", "subprocess", "fileutils", "site"]
includes += ["BaseHTTPServer", "cgi", "cgitb", "fcntl", "getopt", "httplib", "inspect", "json", "math", "operator", "os", "os,", "psycopg2", "re", "smtplib", "socket", "SocketServer", "spye", "spye.config", "spye.config.file", "spye.config.merge", "spye.config.section", "spye.editor", "spye.framework", "spye.frontend", "spye.frontend.cgi", "spye.frontend.http", "spye.input", "spye.output", "spye.output.console", "spye.output.stdout", "spye.pluginsystem", "spye.presentation", "spye.util.html", "spye.util.rpc", "ssl", "stat,", "struct", "subprocess", "sys", "termios", "time", "traceback", "tty", "urllib2", "urlparse", "uuid"]

includefiles=[]
excludes = []
packages = []
target = Executable(
    # what to build
    script = "spye-exe",
    initScript = None,
    #base = 'Win32GUI',
    targetDir = r"dist",
    targetName = "spye.exe",
    compress = True,
    copyDependentFiles = True,
    appendScriptToExe = False,
    appendScriptToLibrary = False,
    icon = None
    )

setup(
    version = "0.1",
    description = "No Description",
    author = "No Author",
    name = "cx_Freeze Sample File",

    options = {"build_exe": {"includes": includes,
                 "excludes": excludes,
                 "packages": packages
                 #"path": path
                 }
           },

    executables = [target]
    )

Please note that I clearly specify the missing modules in the includes list.

How do I fix this?

ervingsb
  • 653
  • 8
  • 9

2 Answers2

0

Missing modules aren't necessarily a problem: a lot of modules try different imports to accommodate different platforms or different versions of Python. In subprocess, for example, you can find this code:

if mswindows:
    ...
    import _subprocess

cx_Freeze doesn't know about this, so it will try to find _subprocess on Linux/Mac as well, and report it as missing. Specifying them in includes doesn't change anything, because it's trying to include them, but unable to find them.

It should build a file anyway, so try running that and seeing if it works.

Thomas K
  • 39,200
  • 7
  • 84
  • 86
-1

I guess, you can not simply += on lists.

You should probably use the list method extend - otherwise the original list will not be modified:

includes.extend(["BaseHTTPServer", "<rest of your modules>"])

EDIT: (Thank @ThomasK)

+= works fine - I only had an online Python interpreter that did not work correctly. (I have no python install on my Windows installation so I had to check online).

BergmannF
  • 9,727
  • 3
  • 37
  • 37
  • Right, I have now fixed that, but I still get the same list of missing modules. How to fix? – ervingsb Apr 18 '12 at 08:06
  • I have update my setup.py here: http://paste.adora.dk/P2357.txt, and the output from "python setup.py build |grep -A12 Missing" is here: http://paste.adora.dk/P2356.txt – ervingsb Apr 18 '12 at 08:21
  • I just googled your problem and it seems to correlate to [libcrypto](http://www.mail-archive.com/cx-freeze-users@lists.sourceforge.net/msg00664.html) (however there was no solution) - maybe cx_freeze does not handle non-python dependencies? – BergmannF Apr 18 '12 at 08:24
  • I hope it can. Otherwise it is appearently impossible to use cx-freeze on any projects that use urllib/urllib2 or hashlib. – ervingsb Apr 18 '12 at 09:00
  • According to the website it can, but I guess you might have more success by asking on the mailing list if / what you can do to solve the problem, as I could not find any solutions when searching old mailing list threads: [cx_freeze mailing list](https://lists.sourceforge.net/lists/listinfo/cx-freeze-users). – BergmannF Apr 18 '12 at 09:15
  • 1
    @Gjallar: You're welcome. If you ever need to test a quick snippet at an interactive shell, try this: http://www.pythonanywhere.com/try-ipython/ – Thomas K Apr 18 '12 at 16:24
  • @ThomasK: That sounds nice, but it does not seem to work in IE 8, which is what I am stuck with. – BergmannF Apr 19 '12 at 08:45
  • @Gjallar: My condolences ;-). I don't know of a REPL that will work, but the Ideone paste bin might let you run code: http://ideone.com/Ef9pJ – Thomas K Apr 19 '12 at 16:37