5

I'm trying to convert my Python project to a standalone executable, in order to run it on other servers that don't have Python installed.

Command used:

python setup.py build > build.log

When I try to run the resulting exe, it always spits out the following error message:

zipimport.ZipImportError: can't find module 'cx_Freeze__init__'
Fatal Python error: unable to locate initialization module

Current thread 0x00000b8c (most recent call first):

I've tried to define all the libraries I'm using throughout my project in the setup.py module, though this has made no difference.

I have also added the DLL files to include (described in the post cx-freeze doesn't find all dependencies).

The project consists of the following libraries (output of pip list):

cx-Freeze (4.3.2)
docopt (0.6.1)
pip (1.5.4)
psutil (2.0.0)
pywin32 (218)
requests (2.2.1)
setuptools (2.2)
virtualenv (1.11.4)
WMI (1.4.9)

Contents of setup.py:

include_files=[
           (r'C:\Python34\Lib\site-packages\pywin32_system32\pywintypes34.dll', 'pywintypes34.dll'),
           (r'C:\Python34\Lib\site-packages\pywin32_system32\pythoncom34.dll', 'pythoncom34.dll'),]

build_exe_options = dict(
    packages=['os', 'concurrent.futures', 'datetime', 'docopt', 'email.mime.text', 'configparser', 'enum',
              'json', 'logging', 'psutil', 'requests', 'smtplib', 'socket', 'subprocess', 'sys', 'threading', 'time',
              'wmi', 'pythoncom'],
    excludes=[],
    include_files=include_files)

executable = Executable(
    script = 'pyWatch.py',
    copyDependentFiles = True,
    base = 'Console')

setup(  name= "pyWatch",
        version= "0.1",
        options= {"build_exe": build_exe_options},
        executables= [executable])

cx_freeze's output (too large to paste here): http://pastebin.com/2c4hUSeD

All help would be greatly appreciated!

Community
  • 1
  • 1
DocZerø
  • 8,037
  • 11
  • 38
  • 66
  • The freezing log says it's making a `cx_Freeze__init__` module. Can you look in library.zip and see if there's a `cx_Freeze__init__.pyc` file there? – Thomas K Mar 25 '14 at 17:30
  • @ThomasK: the `cx_Freeze__init__.pyc` is indeed present in the library.zip. The entire zip's contents are available [here](http://pastebin.com/yqcXEYvY). – DocZerø Mar 25 '14 at 19:17
  • Weird. I can't think what could be causing that at the moment. I'll keep thinking. – Thomas K Mar 26 '14 at 00:51
  • @ThomasK: just tried to open the library zip using zipimport, based on a quick look at the cx_freeze source code. No issues when doing so. If you need any files (or even my source code) for testing, just let me know. – DocZerø Mar 26 '14 at 07:45
  • @ThomasK Do you suspect that this is related to the Python version or the packages/libraries used? – DocZerø Mar 26 '14 at 14:13
  • 1
    Hmm, yes, it could well be something in Python 3.4 that cx_Freeze hasn't adapted to yet. If you've got the VS 2010 compiler on your machine, can you try with the development version of cx_Freeze from https://bitbucket.org/anthony_tuininga/cx_freeze ? – Thomas K Mar 26 '14 at 16:30
  • @ThomasK: here's the [build log](http://pastebin.com/z3gk3iFG) and the [output](http://pastebin.com/R8QEuYEK) when running the exe. – DocZerø Mar 26 '14 at 20:03
  • 1
    @ThomasK: I can confirm that it works with Python 3.3.5. So it's definitely related to Python 3.4. – DocZerø Mar 26 '14 at 22:03
  • That sounds like what's described in [this message](http://bugs.python.org/issue20784#msg213136). I'll investigate further. – Thomas K Mar 26 '14 at 23:42
  • Oh, it's also got an issue: https://bitbucket.org/anthony_tuininga/cx_freeze/issue/69/python-340-can-not-import-collectionsabc – Thomas K Mar 26 '14 at 23:49
  • 2
    I've made a PR to fix it: https://bitbucket.org/anthony_tuininga/cx_freeze/pull-request/48/freeze-collectionsabc-into-base/diff – Thomas K Mar 27 '14 at 00:38
  • 1
    This should work in the latest release of cx_Freeze (4.3.3). – Thomas K Jun 09 '14 at 17:30
  • 1
    I had a similar situation, and resolved by downgrading to Python 3.4.0 and cx_Freeze 4.3.2. Good luck. – Sazzy Nov 05 '14 at 13:41

1 Answers1

0

instead of cx_freeze which is last version updated on 2014
there is a module called pyinstaller which is last version update on 2016 pyinstaller

also easy to use just pyinstaller myscript.py and bam

jonDO
  • 1