Django server couldn't connect after I used Pyinstaller to compile into executable. #8699
Replies: 2 comments · 6 replies
-
We're not going to be able to help you at all based on no minimal reproducer and no error message. |
Beta Was this translation helpful? Give feedback.
All reactions
-
There is no particular error message displayed, I have updated the question to show the server_gui.py script. |
Beta Was this translation helpful? Give feedback.
All reactions
-
At a (very cursory) glance, you are trying to spawn a subprocess using If you want to use embedded python interpreter of the frozen application to run arbitrary script, you will need to detect such invocation in your entry-point script (the most fool-proof way would be to add a command-line argument, but you could also just check if |
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you, I will look into it and if this solves the problem, I'll inform you of the development. |
Beta Was this translation helpful? Give feedback.
All reactions
-
I have updated my code to use exec(), however, I am still facing the same issue where the server connects only when I run it from the terminal. The thing is I don't get any special error message when I run the executable, it just loads and fails every connection attempts Here is how I addressed the issue, I might still be doing it wrong: I updated the start_server method to set a --run_server enviromen variable and then look for that in the main function to know which one to use to run the start_waitress.py script just as the below: def start_server(self):
def run_main_application(): def main():
if name == 'main': Here is the full code again: """ This module defines a GUI application to manage a server. The application provides Dependencies: Classes: Methods:
Functions: import subprocess def is_admin(): def run_as_admin(): def is_valid_ip_address(ip_address):
class ServerGUI(ctk.CTk):
def add_firewall_rule_windows(port):
def add_firewall_rule_linux(port):
def add_firewall_rule_macos(port):
def ping_server(ip_address):
def run_main_application(): def main():
if name == 'main': The .spec file: -- mode: python ; coding: utf-8 --import os if getattr(sys, 'frozen', False): logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s', filename=log_file_path, filemode='a') block_cipher = None spec_file_dir = os.path.abspath('.') with open(requirements_path) as f: customtkinter_datas, customtkinter_binaries, customtkinter_hiddenimports = collect_all('customtkinter') installed_packages = [dist.project_name.replace('-', '_') for dist in pkg_resources.working_set] logging.debug(f"Installed packages: {installed_packages}") invalid_imports = ['pyinstaller_hooks_contrib'] logging.debug(f"Valid hidden imports: {valid_hiddenimports}") datas = [ hiddenimports = customtkinter_hiddenimports + required_packages + valid_hiddenimports + [ a = Analysis( exe = EXE( coll = COLLECT( The start_waitress.py script: import logging def run_server():
def is_server_responding(ip, port): if name == 'main': I really need help on what to do and if I have complicated it due to my own ignorance. |
Beta Was this translation helpful? Give feedback.
All reactions
-
Without seeing any code or error message, our guess is as good as yours.
Try building with console enabled, run from command prompt, and see if you get any warnings or other messages that will give you the hint on what is (not) going on.
So if I understand correctly, your frozen application is just a GUI wrapper that manages the django application. How exactly is the django application launched, then? Does |
Beta Was this translation helpful? Give feedback.
All reactions
-
No, what I did was that I have a script that runs the waitress in a file situated in the same folder as the app and manage.py using a subprocess. I have updated the question to show my server_gui.py code. There was no particular error displayed, the app was created successfully but the server won't connect. This wasn't an issue when I run it from the terminal. |
Beta Was this translation helpful? Give feedback.
All reactions
-
See the comment in above thread. |
Beta Was this translation helpful? Give feedback.
-
I am building a School Management system using Django==5.0.6. The architecture of the project is that I used a Tkinter GUI to build the interface to interact with the Django server to run offline, this interface enables users to use buttons to trigger starting and terminating the server. This Tkinter app is the entry script in my app.spec file. I'm using waitress to server.
The code runs perfectly well when I run it from the terminal but won't work once I compile it with Pyinstaller which makes me confused.
Here is my .spec script:
here is the server.gui script:
What could be the problem?
Beta Was this translation helpful? Give feedback.
All reactions