How to stop Python program compiled in py2exe from displaying ImportError: No Module names 'ctypes'

TheMountainFurnaceGabriel

I was wondering if this might be a compilation error or if there is something I can do to stop it from displaying. I have made an argparse program for cmd. I compiled it with py2exe and when I run it, it exacutes the program properly but always gives this error before running the code:

Traceback (most recent call last):
  File "boot_common.py", line 46, in <module>
ImportError: No module named 'ctypes'

If it is something in my code, here is my script:

import argparse
import zipfile
import os
from contextlib import closing

def parse_args():
    parser = argparse.ArgumentParser('ziputil '+\
    '-m <mode> -f <file> -p <output>')
    parser.add_argument('-f', action="store", dest='files', type=str,
                        help='-f <file> : Specify the files to be zipped, or the .zip to be unzipped.')
    parser.add_argument('-m', action="store", dest='mode', type=str,
                        help='-m <mode> : Zip to zip files, UnZip, to unzip files, or     ZipDir to zip entire directories.')
    parser.add_argument('-p', action="store", dest='path', type=str, nargs='?',     const=os.getcwd(),
                        help='-p <path> : specify the path to unpack/pack to.')


    return vars(parser.parse_args())

def unzipPackage(path, files):
    with zipfile.ZipFile(files, "r") as z:
        z.extractall(path)

def zipPackage(path, files):
    files = files.split(', ')
    zf = zipfile.ZipFile(path, mode='w')
    try:
        for file in files:
            zf.write(file)
    finally:
        zf.close()

def zipdir(path, zip):
    for root, dirs, files in os.walk(path):
        for file in files:
            zip.write(os.path.join(root, file))



dict = parse_args()
files = dict['files']
path = dict['path']
mode = dict['mode']

if mode == 'Zip':
    zipPackage(path, files)
elif mode == 'UnZip':
    unzipPackage(path, files)
elif mode == 'ZipDir':
    zipf = zipfile.ZipFile(path, 'w')
    zipdir(files, zipf)
    zipf.close()
Victor Aurélio

This is caused by a bug in py2exe, it'll be fixed in next release. More Info

The solution is to add ctypes to bootstrap_modules in C:\Python34\Lib\site-packages\py2exe\runtime.py file (line 117).

...
# modules which are always needed
bootstrap_modules = {
    # Needed for Python itself:
    "ctypes",
    "codecs",
    "io",
    "encodings.*",
    }
...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to stop Python program compiled in py2exe from displaying ImportError: No Module names 'ctypes'

From Dev

How to get function names from compiled Python module without importing it?

From Dev

How to get function names from compiled Python module without importing it?

From Dev

program wont work after being compiled with py2exe

From Dev

how to use py2exe packing python+gevent program into .exe file?

From Dev

How do I prevent multiple sessions launch for a Python program packed with py2exe?

From Dev

Generating exe from PyQt program with py2exe

From Dev

Python py2exe Not Including `os` Module

From Dev

Python: ImportError from compiled source code

From Dev

ImportError: No module names 'matplotlib' Python 3.3

From Dev

How to get Windows window names with ctypes in python

From Dev

py2exe fails with "No module named 'clr'" when trying to build exe from script using pythonnet

From Dev

How to stop a python program executable from opening a cmd shell?

From Dev

How can i stop my python program from crashing

From Dev

how to use py2exe when rewriting an imported module (and using the rewritten version)

From Dev

Ubuntu - Error while running program in python: "ImportError: No module named mxnet"

From Dev

Py2exe - module does not find

From Dev

Py2exe - module does not find

From Dev

Can we do file handling from executable created by py2exe in Python?

From Dev

Python ImportError: No module named 'convert.py'

From Dev

Read config.py file from a compiled python .exe script

From Dev

Stop command prompt from opening when running compiled .exe

From Dev

Missing file in compiled py2exe app selenium

From Dev

How to stop program from exiting itself out?

From Dev

How to stop runnable from within program

From Dev

How to stop program from exiting itself out?

From Dev

How to stop runnable from within program

From Dev

Pandas with py2exe: ImportError: C extension: dist not built

From Dev

Python, pygame, py2exe

Related Related

  1. 1

    How to stop Python program compiled in py2exe from displaying ImportError: No Module names 'ctypes'

  2. 2

    How to get function names from compiled Python module without importing it?

  3. 3

    How to get function names from compiled Python module without importing it?

  4. 4

    program wont work after being compiled with py2exe

  5. 5

    how to use py2exe packing python+gevent program into .exe file?

  6. 6

    How do I prevent multiple sessions launch for a Python program packed with py2exe?

  7. 7

    Generating exe from PyQt program with py2exe

  8. 8

    Python py2exe Not Including `os` Module

  9. 9

    Python: ImportError from compiled source code

  10. 10

    ImportError: No module names 'matplotlib' Python 3.3

  11. 11

    How to get Windows window names with ctypes in python

  12. 12

    py2exe fails with "No module named 'clr'" when trying to build exe from script using pythonnet

  13. 13

    How to stop a python program executable from opening a cmd shell?

  14. 14

    How can i stop my python program from crashing

  15. 15

    how to use py2exe when rewriting an imported module (and using the rewritten version)

  16. 16

    Ubuntu - Error while running program in python: "ImportError: No module named mxnet"

  17. 17

    Py2exe - module does not find

  18. 18

    Py2exe - module does not find

  19. 19

    Can we do file handling from executable created by py2exe in Python?

  20. 20

    Python ImportError: No module named 'convert.py'

  21. 21

    Read config.py file from a compiled python .exe script

  22. 22

    Stop command prompt from opening when running compiled .exe

  23. 23

    Missing file in compiled py2exe app selenium

  24. 24

    How to stop program from exiting itself out?

  25. 25

    How to stop runnable from within program

  26. 26

    How to stop program from exiting itself out?

  27. 27

    How to stop runnable from within program

  28. 28

    Pandas with py2exe: ImportError: C extension: dist not built

  29. 29

    Python, pygame, py2exe

HotTag

Archive