Search code examples
python-3.xpython-requestscx-freeze

Comand promp closes instantly with cx_Freeze and requests module


Im trying to build a simple executable file from python using cx_Freeze, but the script uses request module. As many many other threads say, it seems to be a problem involving cx_freeze and requests module, something about the path of the files that requests need to run and cx_freeze changes or doesnt import when freezing.

The build process works just fine, but when the exe is created, if i try to open it, a comand promp shows for a fraction of a second and then closes, displaying something so quickly that i dont have time to read or even snapshot, but it doesnt have the structure of an error message.

I think the problem is probably the thing about paths, but i dont know how to solve it, and everything i've found in internet haven't worked for me.

Please help.

Here is a copy of the test file named "prueba2.py"

import requests
print("hi")
print(requests)
input()

and the setup.py

from cx_Freeze import setup, Executable
import sys
import os
import requests.certs
base = None
executables = [Executable("prueba2.py", base=base)]
packages = ["idna"]
options = {
    'build_exe': {
        'packages': packages,
        'include_files': [os.path.join(sys.base_prefix, 'DLLs','sqlite3.dll'),
         (requests.certs.where(), 'cacert.pem')]
    },
}
setup(
    name="<any name>",
    options=options,
    requires=["requests"],
    version="<any number>",
    description='<any description>',
    executables=executables
) 

Solution

  • It seems there are some dependencies for cx_freeze in new versions of the module

    try modifying the main file like this:

    import requests
    from multiprocessing import Queue
    print("hi")
    print(requests)
    input()
    

    and setup.py as :

    from cx_Freeze import setup, Executable
    import sys
    import os
    import requests.certs
    base = None
    executables = [Executable("prueba2.py", base=base)]
    packages = ["idna"]
    options = {
        'build_exe': {
            'packages': packages,
            'include_files': [os.path.join(sys.base_prefix, 'DLLs', 'sqlite3.dll'),
                              (requests.certs.where(), 'cacert.pem')]
        },
    }
    setup(
        name="name",
        options=options,
        requires=["requests"],
        version="1",
        description='test',
        executables=executables
    )