question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can Not Freeze App (pyinstaller, cx_freeze)

See original GitHub issue

Specification

  • Platform: Windows, Python
  • Version: Win 10 [64bit], Py 3.6.x [32bit]

Description

First of all thank you for this package.

[Problem] App runs great in python mode but gives errors in executable mode. Executable gets generated but it does not run. Used pyinstaller and cx_freeze. Couldn’t use py2exe because of Py 3.6. Spent a whole night but no joy.

Directory Structure:

/
    db/
    static/
    templates/
    main.py
    server.py # i changed the static and template to be default rather than `gui`
    setup.py

Below are the config and commands i used and errors.

cx_freeze

after making executable, when i run the .exe i get this error. i pasted Python.runtime.dll in to the lib folder in executable directory but no joy.

This is my setup.py file for cx_freeze

import os, sys
from cx_Freeze import setup, Executable

base = None
include_files = [
    "C:/Users/Ahmed Noor/AppData/Local/Programs/Python/Python36-32/Lib/site-packages/Python.Runtime.dll",
    "./static", "./templates", "./db"
]

if sys.platform == "win32":
    base = "Console"

setup(
    name = "Institution_Name",
    version = "0.1.0",
    description = "Student_Record_System",
    options = {
        "build_exe" : {
            'packages': ['encodings', 'asyncio', 'flask', 'cs50', 'sqlalchemy', 'jinja2', 'flask_compress', 'passlib', 'werkzeug', 'uuid', 'os', 'operator', 'win32gui', 'win32con', 'win32api', 'win32ui', 'ctypes',
                 'comtypes', 'webview', 'webbrowser'],
            'excludes':['tkinter'],
            "include_files" : include_files
            }
    },
    executables = [Executable("main.py", base=base, targetName="Institution_Name.exe", icon="static/img/system/logo.ico")]
)

This is the Error I get when running .exe,

INFO:werkzeug: * Running on http://127.0.0.1:5100/ (Press CTRL+C to quit)
INFO:werkzeug:127.0.0.1 - - [11/May/2018 22:00:01] "GET /check_if_app_is_running HTTP/1.1" 200 -
Traceback (most recent call last):
  File "C:\Users\Ahmed Noor\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
    module.run()
  File "C:\Users\Ahmed Noor\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
    exec(code, m.__dict__)
  File "main.py", line 42, in <module>
  File "C:\Users\Ahmed Noor\AppData\Local\Programs\Python\Python36-32\lib\site-packages\webview\__init__.py", line 176, in create_window
    _initialize_imports()
  File "C:\Users\Ahmed Noor\AppData\Local\Programs\Python\Python36-32\lib\site-packages\webview\__init__.py", line 101, in _initialize_imports
    import webview.winforms as gui
  File "C:\Users\Ahmed Noor\AppData\Local\Programs\Python\Python36-32\lib\site-packages\webview\winforms.py", line 18, in <module>
    import clr
SystemError: initialization of clr did not return an extension module

pyinstaller

When I make executable with pyinstaller, during the process WARNING Text keeps appearing something like WARNING: lib not found: api-ms-win-crt-<core, stdio, runtime etc.>-l1-1-0.dll dependency of <path/to/python.exe or path/to/python_dir/some_other_lib>

This is the command I use for pyinstaller,

pyinstaller main.py --hidden-import "clr" --name "SRS" --icon "static/img/system/logo.ico" --paths "static" --paths "templates" --paths "db" --path "server.py" --exclude-module "tkinter"

This is the problem I get when I run .exe,

INFO:werkzeug: * Running on http://127.0.0.1:5100/ (Press CTRL+C to quit)

But no window opens. If i open the address on a web browser, it says Internal Server Error

I end task all .exe instances from task manager and copy pasted the db, static, templates and server.py manually in the dist/<dist_dir> but got the following

INFO:werkzeug: * Running on http://127.0.0.1:5100/ (Press CTRL+C to quit)
INFO:werkzeug:127.0.0.1 - - [11/May/2018 23:27:31] "GET /check_if_app_is_running HTTP/1.1" 200 -
Traceback (most recent call last):
  File "main.py", line 42, in <module>
  File "site-packages\webview\__init__.py", line 176, in create_window
  File "site-packages\webview\__init__.py", line 101, in _initialize_imports
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "c:\users\ahmed noor\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\webview\winforms.py", line 37, in <module>
  File "site-packages\webview\util.py", line 144, in interop_dll_path
Exception: Cannot find WebBrowserInterop.dll
[10740] Failed to execute script main

Files

I will attach main.py, server.py and setup.py with this thread in files.zip. You can download the db/, static/ and templates/ directories from the following github repo, Github Repo: https://github.com/ahmednooor/SRS

.py Files: files.zip

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
ahmednooorcommented, May 12, 2018

Got it working with pyinstaller using the following command,

pyinstaller main.py ^
    --clean ^
    --windowed --noconsole ^
    --hidden-import "clr" --name "SRS" ^
    --icon "static/img/system/logo.ico" ^
    --paths "C:/Users/Ahmed Noor/AppData/Local/Programs/Python/Python36-32/" ^
    --add-data "static;./static/" ^
    --add-data "templates;./templates/" ^
    --add-data "db;./db/" ^
    --add-data "server.py;./" ^
    --add-data "C:\Users\Ahmed Noor\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\webview\lib\WebBrowserInterop.x64.dll;./" ^
    --add-data "C:\Users\Ahmed Noor\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\webview\lib\WebBrowserInterop.x86.dll;./" ^
    --exclude-module "tkinter"

Feel free to close this issue. Thank you.

1reaction
r0x0rcommented, May 12, 2018

I have never managed to get the onefile option working too, but I think another user succeeded. This issue should be addressed though. Creating a pyinstaller hook would be the first step. I will create a new ticket.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python: PYInstaller, CX_Freeze: Cannot create installer
When trying to run cx_freeze ( python setup.py build ) it creates a .exe that will only open a console and nothing else...
Read more >
Packaging and Optimizing Complex Python Application with ...
Here we are going to discuss how we can easily package (make an executable .exe from a complex python application). Let's start without...
Read more >
setup script — cx_Freeze 6.13.0 documentation
This command is a standard command which has been modified by cx_Freeze to ensure that packages are created with the proper architecture for...
Read more >
cefpython.GetModuleDirectory() return wrong path after freeze ...
I think, it's all about deployment mechanism. Some people use py2app, py2exe, cx_freeze, pyinstaller, etc. All of them can not build a proper...
Read more >
Freeze the Code - ugo_py_doc
http://cx-freeze.readthedocs.io · https://anthony-tuininga.github.io/cx_Freeze/ · Install cx_Freeze (works on Pyhon 2 & 3). The easiest way is with pip install ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found