Update app.py
Browse files
app.py
CHANGED
@@ -343,11 +343,14 @@ Add this to your requirements.txt and redeploy the space."""
|
|
343 |
cmd.extend([
|
344 |
"--mingw64", # Use MinGW-w64 for cross-compilation
|
345 |
"--windows-disable-console", # Disable console window for GUI apps
|
|
|
|
|
346 |
])
|
347 |
# Note: --mingw64 flag tells Nuitka to use MinGW-w64 for Windows cross-compilation
|
348 |
if log_queue:
|
349 |
-
log_queue.put("Using MinGW-w64 for Windows cross-compilation\n")
|
350 |
-
log_queue.put("Note: Cross-compiling from Linux to Windows using proper MinGW-w64 toolchain\n")
|
|
|
351 |
|
352 |
# Run compilation
|
353 |
if progress_callback:
|
@@ -453,7 +456,10 @@ Add this to your requirements.txt and redeploy the space."""
|
|
453 |
except:
|
454 |
linking_info = "βΉοΈ Compiled binary created successfully"
|
455 |
else:
|
456 |
-
|
|
|
|
|
|
|
457 |
|
458 |
# Rename to desired extension
|
459 |
if output_extension in ['.bin', '.sh', '.exe'] and not binary_path.endswith(output_extension):
|
@@ -485,7 +491,7 @@ Add this to your requirements.txt and redeploy the space."""
|
|
485 |
- **Compiled with Python**: {current_python}
|
486 |
- **Static Libpython Available**: {static_status}
|
487 |
- **Linking**: {linking_info}
|
488 |
-
- **Target Platform**: {'Windows (.exe) via MinGW-w64' if output_extension == '.exe' else 'Linux'}
|
489 |
|
490 |
## Environment Results:
|
491 |
**System Packages**: {packages_result}
|
@@ -497,19 +503,22 @@ Add this to your requirements.txt and redeploy the space."""
|
|
497 |
## π Portability Notes:
|
498 |
- This binary was compiled with maximum compatibility settings
|
499 |
- Using --onefile for single-file distribution
|
500 |
-
- {'Cross-compiled using MinGW-w64 toolchain
|
501 |
{f'- Console window disabled for Windows GUI applications' if output_extension == '.exe' else ''}
|
|
|
502 |
|
503 |
## π Usage Instructions:
|
504 |
```bash
|
505 |
-
{f'# For Windows:' if output_extension == '.exe' else f'chmod +x {binary_basename}'}
|
506 |
{f'# Download to Windows machine and run:' if output_extension == '.exe' else ''}
|
507 |
{f'{binary_basename}' if output_extension == '.exe' else f'./{binary_basename}'}
|
508 |
```
|
509 |
|
510 |
## β οΈ Cross-Compilation Notes:
|
511 |
-
{f'''- Compiled from Linux to Windows using MinGW-w64
|
|
|
512 |
- Tested with wine if available: `wine {binary_basename}`
|
|
|
513 |
- Some Windows-specific libraries may need additional setup
|
514 |
- GUI frameworks may require special handling''' if output_extension == '.exe' else 'Native Linux compilation with maximum compatibility'}
|
515 |
|
@@ -525,7 +534,7 @@ Add this to your requirements.txt and redeploy the space."""
|
|
525 |
if log_queue:
|
526 |
log_queue.put("β
Compilation completed successfully!\n")
|
527 |
if output_extension == ".exe":
|
528 |
-
log_queue.put("π· You can test the Windows executable with: wine " + binary_basename + "\n")
|
529 |
|
530 |
return result_summary, binary_path, compile_output, True
|
531 |
else:
|
@@ -535,7 +544,7 @@ Add this to your requirements.txt and redeploy the space."""
|
|
535 |
## Error Details:
|
536 |
- **Exit Code**: {process.returncode}
|
537 |
- **Mode Attempted**: {mode_name}
|
538 |
-
- **Target**: {'Windows (.exe) via MinGW-w64' if output_extension == '.exe' else 'Linux'}
|
539 |
|
540 |
## Environment Results:
|
541 |
**System Packages**: {packages_result}
|
@@ -553,6 +562,7 @@ Add this to your requirements.txt and redeploy the space."""
|
|
553 |
4. Review the compilation logs above
|
554 |
{f"5. For Windows cross-compilation, ensure MinGW-w64 is properly installed" if output_extension == '.exe' else ''}
|
555 |
{f"6. Some packages may not support Windows cross-compilation" if output_extension == '.exe' else ''}
|
|
|
556 |
|
557 |
## Missing Dependencies:
|
558 |
{', '.join(missing_deps) if missing_deps else 'None detected'}
|
@@ -561,7 +571,8 @@ Add this to your requirements.txt and redeploy the space."""
|
|
561 |
- **Nuitka Version**: {nuitka_version}
|
562 |
- **Python Version**: {current_python}
|
563 |
- **Platform**: {platform.platform()}
|
564 |
-
{f"- **MinGW-w64**: {'Available' if not check_mingw_installation() else 'Missing components'}" if output_extension == '.exe' else ''}
|
|
|
565 |
if progress_callback:
|
566 |
progress_callback(1.0, "Compilation failed β")
|
567 |
|
@@ -593,7 +604,8 @@ Add this to your requirements.txt and redeploy the space."""
|
|
593 |
2. Verify your code syntax
|
594 |
3. Check available disk space
|
595 |
4. Try with simpler code first
|
596 |
-
{f"5. Ensure MinGW-w64 is installed for Windows cross-compilation" if output_extension == '.exe' else ''}
|
|
|
597 |
if progress_callback:
|
598 |
progress_callback(1.0, "Error occurred β")
|
599 |
|
@@ -613,7 +625,7 @@ def run_compiled_binary(binary_path):
|
|
613 |
# Try to run with wine first
|
614 |
wine_result = subprocess.run(["which", "wine"], capture_output=True)
|
615 |
if wine_result.returncode == 0:
|
616 |
-
return f"""π· **Running Windows executable with Wine**
|
617 |
|
618 |
## Execution:
|
619 |
```bash
|
@@ -633,6 +645,7 @@ To run on Windows:
|
|
633 |
|
634 |
## Note:
|
635 |
- Wine is available on this system for basic testing
|
|
|
636 |
- Full compatibility requires running on actual Windows
|
637 |
- Some features may not work correctly in wine"""
|
638 |
else:
|
@@ -640,7 +653,7 @@ To run on Windows:
|
|
640 |
|
641 |
## To run this binary:
|
642 |
1. Download the .exe file
|
643 |
-
2. Transfer it to a Windows machine
|
644 |
3. Run it by double-clicking or from command prompt
|
645 |
|
646 |
```cmd
|
@@ -649,6 +662,11 @@ cd /path/to/downloaded/file
|
|
649 |
{os.path.basename(binary_path)}
|
650 |
```
|
651 |
|
|
|
|
|
|
|
|
|
|
|
652 |
## Alternative:
|
653 |
Install wine to test Windows executables on Linux:
|
654 |
```bash
|
@@ -692,7 +710,7 @@ wine {os.path.basename(binary_path)}
|
|
692 |
# Create Gradio interface
|
693 |
with gr.Blocks(title="Nuitka Python Compiler with MinGW-w64", theme=gr.themes.Soft()) as app:
|
694 |
gr.Markdown("# π Nuitka Python Compiler (MinGW-w64 Cross-Compilation)")
|
695 |
-
gr.Markdown("Convert your Python code into portable executables using Nuitka, with proper MinGW-w64 support for Windows cross-compilation.")
|
696 |
|
697 |
# Check environment status
|
698 |
has_static = check_static_libpython()
|
@@ -711,15 +729,15 @@ with gr.Blocks(title="Nuitka Python Compiler with MinGW-w64", theme=gr.themes.So
|
|
711 |
gr.Markdown(f"β οΈ **MinGW-w64 Components Missing:** {', '.join(mingw_missing)}")
|
712 |
gr.Markdown("π **For Windows .exe generation**, MinGW-w64 should be pre-installed in the environment.")
|
713 |
else:
|
714 |
-
gr.Markdown("β
**MinGW-w64 Available!** Windows cross-compilation supported.")
|
715 |
|
716 |
if [dep for dep in missing_deps if dep != "nuitka" and dep != "mingw-w64"]:
|
717 |
gr.Markdown(f"β οΈ **Other missing dependencies:** {', '.join([dep for dep in missing_deps if dep != 'nuitka' and dep != 'mingw-w64'])}")
|
718 |
|
719 |
# MinGW-w64 information
|
720 |
gr.Markdown("""
|
721 |
-
> βΉοΈ **MinGW-w64 Cross-Compilation**: Using proper MinGW-w64 toolchain for Windows .exe generation.
|
722 |
-
> This follows the official Nuitka documentation
|
723 |
""")
|
724 |
|
725 |
with gr.Tabs():
|
@@ -803,13 +821,16 @@ input('Press Enter to exit...')""",
|
|
803 |
if mingw_missing:
|
804 |
gr.Markdown(f"β οΈ **MinGW-w64**: Missing ({', '.join(mingw_missing)})")
|
805 |
else:
|
806 |
-
gr.Markdown("β
**MinGW-w64**: Available for Windows cross-compilation")
|
807 |
|
808 |
if check_static_libpython():
|
809 |
gr.Markdown("π **Static libpython will be used for Linux targets!**")
|
810 |
else:
|
811 |
gr.Markdown("π§ **Using portable compilation flags**")
|
812 |
|
|
|
|
|
|
|
813 |
compile_btn = gr.Button("π Compile with Nuitka", variant="primary")
|
814 |
|
815 |
# Progress Bar Section
|
@@ -841,10 +862,10 @@ input('Press Enter to exit...')""",
|
|
841 |
run_btn = gr.Button("π§ͺ Test Run Binary", variant="secondary")
|
842 |
run_output = gr.Markdown(label="Execution Output")
|
843 |
|
844 |
-
# Variables to store state
|
845 |
current_binary_path = gr.State(None)
|
846 |
compilation_success = gr.State(False)
|
847 |
-
log_queue = gr.State(None)
|
848 |
|
849 |
def update_progress_display(progress, status):
|
850 |
"""Update the progress bar display"""
|
@@ -896,10 +917,10 @@ input('Press Enter to exit...')""",
|
|
896 |
# Progress simulation with log updates
|
897 |
progress_steps = [
|
898 |
(0.1, "Checking Nuitka installation..."),
|
899 |
-
(0.15, "Checking MinGW-w64 for Windows targets..." if extension == ".exe" else "Checking environment..."),
|
900 |
(0.2, "Setting up environment..."),
|
901 |
(0.3, "Installing requirements..."),
|
902 |
-
(0.4, f"Starting {'Windows cross-' if extension == '.exe' else ''}compilation..."),
|
903 |
(0.5, "Processing imports..."),
|
904 |
(0.6, "Optimizing code..."),
|
905 |
(0.7, f"Creating {extension} binary..."),
|
@@ -947,7 +968,7 @@ input('Press Enter to exit...')""",
|
|
947 |
# Final progress update
|
948 |
final_status = "β
Compilation successful!" if success else "β Compilation failed"
|
949 |
if success and extension == ".exe":
|
950 |
-
final_status += " (Windows .exe created)"
|
951 |
|
952 |
yield (
|
953 |
gr.update(visible=True), # progress_section
|
@@ -1045,13 +1066,14 @@ input('Press Enter to exit...')""",
|
|
1045 |
|
1046 |
with gr.TabItem("π How to Use"):
|
1047 |
gr.Markdown("""
|
1048 |
-
## π― MinGW-w64 Cross-Compilation
|
1049 |
|
1050 |
-
**Proper Windows .exe Generation**
|
1051 |
|
1052 |
-
This app now uses the **correct method** for generating Windows .exe files from Linux:
|
1053 |
- **MinGW-w64 toolchain** for cross-compilation
|
1054 |
- **`--mingw64` flag** in Nuitka
|
|
|
1055 |
- **`--windows-disable-console`** for GUI applications
|
1056 |
- **Proper cross-compilation setup** as per Nuitka documentation
|
1057 |
|
@@ -1060,6 +1082,7 @@ input('Press Enter to exit...')""",
|
|
1060 |
- Visual progress bar with cross-compilation status
|
1061 |
- Automatic MinGW-w64 detection
|
1062 |
- Wine testing support for .exe files
|
|
|
1063 |
|
1064 |
## π Usage Instructions
|
1065 |
|
@@ -1071,13 +1094,13 @@ input('Press Enter to exit...')""",
|
|
1071 |
### 2. Choose Target Platform
|
1072 |
- **Linux (.bin)**: Native Linux executable (fastest compilation)
|
1073 |
- **Linux (.sh)**: Shell script format
|
1074 |
-
- **Windows (.exe)**: Cross-compiled using MinGW-w64 (proper method)
|
1075 |
|
1076 |
### 3. Compile
|
1077 |
- Click "Compile with Nuitka"
|
1078 |
- Watch the real-time logs showing MinGW-w64 usage
|
1079 |
- Monitor the progress bar for cross-compilation status
|
1080 |
-
- Download the resulting binary
|
1081 |
|
1082 |
### 4. Run Your Binary
|
1083 |
|
@@ -1088,7 +1111,7 @@ input('Press Enter to exit...')""",
|
|
1088 |
./compiled_program.bin
|
1089 |
```
|
1090 |
|
1091 |
-
#### For Windows executables:
|
1092 |
```cmd
|
1093 |
# Download the .exe file to Windows
|
1094 |
compiled_program.exe
|
@@ -1106,7 +1129,7 @@ input('Press Enter to exit...')""",
|
|
1106 |
|
1107 |
## π§ MinGW-w64 Requirements
|
1108 |
|
1109 |
-
**For Windows cross-compilation, the following should be pre-installed:**
|
1110 |
```bash
|
1111 |
# Ubuntu/Debian
|
1112 |
apt install mingw-w64 gcc-mingw-w64 g++-mingw-w64
|
@@ -1120,32 +1143,35 @@ input('Press Enter to exit...')""",
|
|
1120 |
**Windows .exe from Linux (MinGW-w64 method):**
|
1121 |
- β
Uses proper MinGW-w64 cross-compiler
|
1122 |
- β
Follows official Nuitka documentation
|
1123 |
-
- β
Produces native Windows executables
|
|
|
1124 |
- β οΈ Some Python packages may not cross-compile
|
1125 |
- β οΈ Windows-specific APIs may need special handling
|
1126 |
- β
Can be tested with wine on Linux
|
|
|
1127 |
|
1128 |
-
## π
|
1129 |
|
1130 |
-
|
|
1131 |
-
|
1132 |
-
|
|
1133 |
-
|
|
1134 |
-
|
|
1135 |
""")
|
1136 |
|
1137 |
with gr.TabItem("βΉοΈ About"):
|
1138 |
gr.Markdown(f"""
|
1139 |
## π§ MinGW-w64 Cross-Compilation Technology
|
1140 |
|
1141 |
-
**Proper Implementation:**
|
1142 |
|
1143 |
1. **MinGW-w64 Toolchain**: Uses the correct cross-compiler for Windows
|
1144 |
2. **Nuitka Integration**: Proper `--mingw64` flag usage
|
1145 |
-
3. **
|
1146 |
-
4. **
|
1147 |
-
5. **
|
1148 |
-
6. **
|
|
|
1149 |
|
1150 |
## β
Improvements in This Version
|
1151 |
|
@@ -1153,10 +1179,12 @@ input('Press Enter to exit...')""",
|
|
1153 |
|
1154 |
- β
Proper MinGW-w64 implementation
|
1155 |
- β
Follows official Nuitka documentation
|
|
|
1156 |
- β
Real-time MinGW-w64 status in logs
|
1157 |
- β
Automatic MinGW-w64 component detection
|
1158 |
- β
Wine testing instructions
|
1159 |
- β
Better error handling for cross-compilation
|
|
|
1160 |
|
1161 |
## βοΈ Environment Status
|
1162 |
|
@@ -1169,6 +1197,7 @@ input('Press Enter to exit...')""",
|
|
1169 |
Static Libpython: {'β
Available' if check_static_libpython() else 'β Not Available'}
|
1170 |
Environment: Hugging Face Spaces
|
1171 |
Cross-Compilation: Proper MinGW-w64 support
|
|
|
1172 |
```
|
1173 |
|
1174 |
## π Best Practices
|
@@ -1180,7 +1209,8 @@ input('Press Enter to exit...')""",
|
|
1180 |
3. β
Check MinGW-w64 status before compiling .exe
|
1181 |
4. β
Use real-time logs to monitor progress
|
1182 |
5. β
Test .exe files with wine if available
|
1183 |
-
6. β
Verify
|
|
|
1184 |
|
1185 |
**Package compatibility:**
|
1186 |
|
@@ -1188,6 +1218,7 @@ input('Press Enter to exit...')""",
|
|
1188 |
2. β οΈ Avoid packages with C extensions when cross-compiling
|
1189 |
3. β οΈ GUI frameworks may need special handling
|
1190 |
4. β οΈ Windows-specific packages won't work in cross-compilation
|
|
|
1191 |
|
1192 |
## π§ Troubleshooting
|
1193 |
|
@@ -1196,6 +1227,7 @@ input('Press Enter to exit...')""",
|
|
1196 |
- **Missing MinGW-w64**: Install required packages in Docker image
|
1197 |
- **Cross-compilation fails**: Check package compatibility
|
1198 |
- **Large .exe files**: Normal for standalone Windows executables
|
|
|
1199 |
- **Runtime errors**: Test with different Nuitka flags
|
1200 |
- **Wine issues**: Wine testing is optional, real Windows testing preferred
|
1201 |
|
@@ -1205,25 +1237,32 @@ input('Press Enter to exit...')""",
|
|
1205 |
|
1206 |
1. Nuitka converts Python to C code
|
1207 |
2. MinGW-w64 cross-compiles C to Windows PE format
|
1208 |
-
3.
|
1209 |
-
4.
|
1210 |
-
5.
|
|
|
1211 |
|
1212 |
**Command structure:**
|
1213 |
```bash
|
1214 |
python -m nuitka \\
|
1215 |
--mingw64 \\
|
|
|
1216 |
--onefile \\
|
1217 |
--windows-disable-console \\
|
1218 |
--show-progress \\
|
1219 |
your_script.py
|
1220 |
```
|
1221 |
|
1222 |
-
|
|
|
|
|
|
|
|
|
|
|
1223 |
""")
|
1224 |
|
1225 |
gr.Markdown("---")
|
1226 |
-
gr.Markdown("π€ Created by Claude 3.7 Sonnet | π Powered by Nuitka + MinGW-w64 | βοΈ Proper cross-compilation | π Real-time logs")
|
1227 |
|
1228 |
if __name__ == "__main__":
|
1229 |
# Create necessary directories on startup
|
|
|
343 |
cmd.extend([
|
344 |
"--mingw64", # Use MinGW-w64 for cross-compilation
|
345 |
"--windows-disable-console", # Disable console window for GUI apps
|
346 |
+
"--target-arch=x64", # Explicitly target 64-bit architecture
|
347 |
+
"--msvc=14.3", # Use MSVC compatibility mode
|
348 |
])
|
349 |
# Note: --mingw64 flag tells Nuitka to use MinGW-w64 for Windows cross-compilation
|
350 |
if log_queue:
|
351 |
+
log_queue.put("Using MinGW-w64 for Windows 64-bit cross-compilation\n")
|
352 |
+
log_queue.put("Note: Cross-compiling from Linux to Windows x64 using proper MinGW-w64 toolchain\n")
|
353 |
+
log_queue.put("Target architecture: x64 (64-bit)\n")
|
354 |
|
355 |
# Run compilation
|
356 |
if progress_callback:
|
|
|
456 |
except:
|
457 |
linking_info = "βΉοΈ Compiled binary created successfully"
|
458 |
else:
|
459 |
+
# For Windows, check architecture
|
460 |
+
linking_info = "π¦ Windows x64 executable (cross-compiled with MinGW-w64)"
|
461 |
+
if log_queue:
|
462 |
+
log_queue.put("Binary architecture: 64-bit (x64)\n")
|
463 |
|
464 |
# Rename to desired extension
|
465 |
if output_extension in ['.bin', '.sh', '.exe'] and not binary_path.endswith(output_extension):
|
|
|
491 |
- **Compiled with Python**: {current_python}
|
492 |
- **Static Libpython Available**: {static_status}
|
493 |
- **Linking**: {linking_info}
|
494 |
+
- **Target Platform**: {'Windows x64 (.exe) via MinGW-w64' if output_extension == '.exe' else 'Linux'}
|
495 |
|
496 |
## Environment Results:
|
497 |
**System Packages**: {packages_result}
|
|
|
503 |
## π Portability Notes:
|
504 |
- This binary was compiled with maximum compatibility settings
|
505 |
- Using --onefile for single-file distribution
|
506 |
+
- {'Cross-compiled specifically for Windows 64-bit (x64) using MinGW-w64 toolchain' if output_extension == '.exe' else 'Should work on most compatible Linux systems'}
|
507 |
{f'- Console window disabled for Windows GUI applications' if output_extension == '.exe' else ''}
|
508 |
+
- {'Explicitly targets x64 architecture for maximum Windows compatibility' if output_extension == '.exe' else ''}
|
509 |
|
510 |
## π Usage Instructions:
|
511 |
```bash
|
512 |
+
{f'# For Windows (64-bit):' if output_extension == '.exe' else f'chmod +x {binary_basename}'}
|
513 |
{f'# Download to Windows machine and run:' if output_extension == '.exe' else ''}
|
514 |
{f'{binary_basename}' if output_extension == '.exe' else f'./{binary_basename}'}
|
515 |
```
|
516 |
|
517 |
## β οΈ Cross-Compilation Notes:
|
518 |
+
{f'''- Compiled from Linux to Windows x64 using MinGW-w64
|
519 |
+
- Uses --target-arch=x64 for explicit 64-bit compilation
|
520 |
- Tested with wine if available: `wine {binary_basename}`
|
521 |
+
- Compatible with Windows 7 64-bit and later
|
522 |
- Some Windows-specific libraries may need additional setup
|
523 |
- GUI frameworks may require special handling''' if output_extension == '.exe' else 'Native Linux compilation with maximum compatibility'}
|
524 |
|
|
|
534 |
if log_queue:
|
535 |
log_queue.put("β
Compilation completed successfully!\n")
|
536 |
if output_extension == ".exe":
|
537 |
+
log_queue.put("π· You can test the Windows x64 executable with: wine " + binary_basename + "\n")
|
538 |
|
539 |
return result_summary, binary_path, compile_output, True
|
540 |
else:
|
|
|
544 |
## Error Details:
|
545 |
- **Exit Code**: {process.returncode}
|
546 |
- **Mode Attempted**: {mode_name}
|
547 |
+
- **Target**: {'Windows x64 (.exe) via MinGW-w64' if output_extension == '.exe' else 'Linux'}
|
548 |
|
549 |
## Environment Results:
|
550 |
**System Packages**: {packages_result}
|
|
|
562 |
4. Review the compilation logs above
|
563 |
{f"5. For Windows cross-compilation, ensure MinGW-w64 is properly installed" if output_extension == '.exe' else ''}
|
564 |
{f"6. Some packages may not support Windows cross-compilation" if output_extension == '.exe' else ''}
|
565 |
+
{f"7. For 64-bit Windows, ensure all dependencies support x64 architecture" if output_extension == '.exe' else ''}
|
566 |
|
567 |
## Missing Dependencies:
|
568 |
{', '.join(missing_deps) if missing_deps else 'None detected'}
|
|
|
571 |
- **Nuitka Version**: {nuitka_version}
|
572 |
- **Python Version**: {current_python}
|
573 |
- **Platform**: {platform.platform()}
|
574 |
+
{f"- **MinGW-w64**: {'Available' if not check_mingw_installation() else 'Missing components'}" if output_extension == '.exe' else ''}
|
575 |
+
{f"- **Target Architecture**: x64 (64-bit)" if output_extension == '.exe' else ''}"""
|
576 |
if progress_callback:
|
577 |
progress_callback(1.0, "Compilation failed β")
|
578 |
|
|
|
604 |
2. Verify your code syntax
|
605 |
3. Check available disk space
|
606 |
4. Try with simpler code first
|
607 |
+
{f"5. Ensure MinGW-w64 is installed for Windows cross-compilation" if output_extension == '.exe' else ''}
|
608 |
+
{f"6. For Windows 64-bit, ensure proper x64 toolchain" if output_extension == '.exe' else ''}"""
|
609 |
if progress_callback:
|
610 |
progress_callback(1.0, "Error occurred β")
|
611 |
|
|
|
625 |
# Try to run with wine first
|
626 |
wine_result = subprocess.run(["which", "wine"], capture_output=True)
|
627 |
if wine_result.returncode == 0:
|
628 |
+
return f"""π· **Running Windows x64 executable with Wine**
|
629 |
|
630 |
## Execution:
|
631 |
```bash
|
|
|
645 |
|
646 |
## Note:
|
647 |
- Wine is available on this system for basic testing
|
648 |
+
- This executable is compiled for Windows 64-bit (x64)
|
649 |
- Full compatibility requires running on actual Windows
|
650 |
- Some features may not work correctly in wine"""
|
651 |
else:
|
|
|
653 |
|
654 |
## To run this binary:
|
655 |
1. Download the .exe file
|
656 |
+
2. Transfer it to a Windows machine (64-bit required)
|
657 |
3. Run it by double-clicking or from command prompt
|
658 |
|
659 |
```cmd
|
|
|
662 |
{os.path.basename(binary_path)}
|
663 |
```
|
664 |
|
665 |
+
## Note:
|
666 |
+
- This executable is compiled for Windows 64-bit (x64)
|
667 |
+
- Compatible with Windows 7 64-bit and later
|
668 |
+
- Will not work on 32-bit Windows systems
|
669 |
+
|
670 |
## Alternative:
|
671 |
Install wine to test Windows executables on Linux:
|
672 |
```bash
|
|
|
710 |
# Create Gradio interface
|
711 |
with gr.Blocks(title="Nuitka Python Compiler with MinGW-w64", theme=gr.themes.Soft()) as app:
|
712 |
gr.Markdown("# π Nuitka Python Compiler (MinGW-w64 Cross-Compilation)")
|
713 |
+
gr.Markdown("Convert your Python code into portable executables using Nuitka, with proper MinGW-w64 support for Windows 64-bit cross-compilation.")
|
714 |
|
715 |
# Check environment status
|
716 |
has_static = check_static_libpython()
|
|
|
729 |
gr.Markdown(f"β οΈ **MinGW-w64 Components Missing:** {', '.join(mingw_missing)}")
|
730 |
gr.Markdown("π **For Windows .exe generation**, MinGW-w64 should be pre-installed in the environment.")
|
731 |
else:
|
732 |
+
gr.Markdown("β
**MinGW-w64 Available!** Windows 64-bit cross-compilation supported.")
|
733 |
|
734 |
if [dep for dep in missing_deps if dep != "nuitka" and dep != "mingw-w64"]:
|
735 |
gr.Markdown(f"β οΈ **Other missing dependencies:** {', '.join([dep for dep in missing_deps if dep != 'nuitka' and dep != 'mingw-w64'])}")
|
736 |
|
737 |
# MinGW-w64 information
|
738 |
gr.Markdown("""
|
739 |
+
> βΉοΈ **MinGW-w64 Cross-Compilation**: Using proper MinGW-w64 toolchain for Windows 64-bit .exe generation.
|
740 |
+
> This follows the official Nuitka documentation and explicitly targets x64 architecture.
|
741 |
""")
|
742 |
|
743 |
with gr.Tabs():
|
|
|
821 |
if mingw_missing:
|
822 |
gr.Markdown(f"β οΈ **MinGW-w64**: Missing ({', '.join(mingw_missing)})")
|
823 |
else:
|
824 |
+
gr.Markdown("β
**MinGW-w64**: Available for Windows 64-bit cross-compilation")
|
825 |
|
826 |
if check_static_libpython():
|
827 |
gr.Markdown("π **Static libpython will be used for Linux targets!**")
|
828 |
else:
|
829 |
gr.Markdown("π§ **Using portable compilation flags**")
|
830 |
|
831 |
+
# Add architecture notice
|
832 |
+
gr.Markdown("ποΈ **Windows Target**: x64 (64-bit) architecture")
|
833 |
+
|
834 |
compile_btn = gr.Button("π Compile with Nuitka", variant="primary")
|
835 |
|
836 |
# Progress Bar Section
|
|
|
862 |
run_btn = gr.Button("π§ͺ Test Run Binary", variant="secondary")
|
863 |
run_output = gr.Markdown(label="Execution Output")
|
864 |
|
865 |
+
# Variables to store state
|
866 |
current_binary_path = gr.State(None)
|
867 |
compilation_success = gr.State(False)
|
868 |
+
log_queue = gr.State(None)
|
869 |
|
870 |
def update_progress_display(progress, status):
|
871 |
"""Update the progress bar display"""
|
|
|
917 |
# Progress simulation with log updates
|
918 |
progress_steps = [
|
919 |
(0.1, "Checking Nuitka installation..."),
|
920 |
+
(0.15, "Checking MinGW-w64 for Windows x64 targets..." if extension == ".exe" else "Checking environment..."),
|
921 |
(0.2, "Setting up environment..."),
|
922 |
(0.3, "Installing requirements..."),
|
923 |
+
(0.4, f"Starting {'Windows x64 cross-' if extension == '.exe' else ''}compilation..."),
|
924 |
(0.5, "Processing imports..."),
|
925 |
(0.6, "Optimizing code..."),
|
926 |
(0.7, f"Creating {extension} binary..."),
|
|
|
968 |
# Final progress update
|
969 |
final_status = "β
Compilation successful!" if success else "β Compilation failed"
|
970 |
if success and extension == ".exe":
|
971 |
+
final_status += " (Windows x64 .exe created)"
|
972 |
|
973 |
yield (
|
974 |
gr.update(visible=True), # progress_section
|
|
|
1066 |
|
1067 |
with gr.TabItem("π How to Use"):
|
1068 |
gr.Markdown("""
|
1069 |
+
## π― MinGW-w64 Cross-Compilation to Windows 64-bit
|
1070 |
|
1071 |
+
**Proper Windows x64 .exe Generation**
|
1072 |
|
1073 |
+
This app now uses the **correct method** for generating 64-bit Windows .exe files from Linux:
|
1074 |
- **MinGW-w64 toolchain** for cross-compilation
|
1075 |
- **`--mingw64` flag** in Nuitka
|
1076 |
+
- **`--target-arch=x64`** for explicit 64-bit compilation
|
1077 |
- **`--windows-disable-console`** for GUI applications
|
1078 |
- **Proper cross-compilation setup** as per Nuitka documentation
|
1079 |
|
|
|
1082 |
- Visual progress bar with cross-compilation status
|
1083 |
- Automatic MinGW-w64 detection
|
1084 |
- Wine testing support for .exe files
|
1085 |
+
- **Explicit 64-bit architecture targeting**
|
1086 |
|
1087 |
## π Usage Instructions
|
1088 |
|
|
|
1094 |
### 2. Choose Target Platform
|
1095 |
- **Linux (.bin)**: Native Linux executable (fastest compilation)
|
1096 |
- **Linux (.sh)**: Shell script format
|
1097 |
+
- **Windows (.exe)**: Cross-compiled using MinGW-w64 (64-bit, proper method)
|
1098 |
|
1099 |
### 3. Compile
|
1100 |
- Click "Compile with Nuitka"
|
1101 |
- Watch the real-time logs showing MinGW-w64 usage
|
1102 |
- Monitor the progress bar for cross-compilation status
|
1103 |
+
- Download the resulting 64-bit binary
|
1104 |
|
1105 |
### 4. Run Your Binary
|
1106 |
|
|
|
1111 |
./compiled_program.bin
|
1112 |
```
|
1113 |
|
1114 |
+
#### For Windows executables (64-bit):
|
1115 |
```cmd
|
1116 |
# Download the .exe file to Windows
|
1117 |
compiled_program.exe
|
|
|
1129 |
|
1130 |
## π§ MinGW-w64 Requirements
|
1131 |
|
1132 |
+
**For Windows 64-bit cross-compilation, the following should be pre-installed:**
|
1133 |
```bash
|
1134 |
# Ubuntu/Debian
|
1135 |
apt install mingw-w64 gcc-mingw-w64 g++-mingw-w64
|
|
|
1143 |
**Windows .exe from Linux (MinGW-w64 method):**
|
1144 |
- β
Uses proper MinGW-w64 cross-compiler
|
1145 |
- β
Follows official Nuitka documentation
|
1146 |
+
- β
Produces native Windows 64-bit executables
|
1147 |
+
- β
Explicitly targets x64 architecture
|
1148 |
- β οΈ Some Python packages may not cross-compile
|
1149 |
- β οΈ Windows-specific APIs may need special handling
|
1150 |
- β
Can be tested with wine on Linux
|
1151 |
+
- β
Compatible with Windows 7 64-bit and later
|
1152 |
|
1153 |
+
## π Architecture Support
|
1154 |
|
1155 |
+
| Target | Architecture | Compatibility | Notes |
|
1156 |
+
|--------|-------------|---------------|-------|
|
1157 |
+
| Linux | x64 | Native | Best performance |
|
1158 |
+
| Windows | x64 (64-bit) | Excellent | Proper MinGW-w64 cross-compilation |
|
1159 |
+
| Windows | x86 (32-bit) | Not supported | Use x64 instead |
|
1160 |
""")
|
1161 |
|
1162 |
with gr.TabItem("βΉοΈ About"):
|
1163 |
gr.Markdown(f"""
|
1164 |
## π§ MinGW-w64 Cross-Compilation Technology
|
1165 |
|
1166 |
+
**Proper 64-bit Implementation:**
|
1167 |
|
1168 |
1. **MinGW-w64 Toolchain**: Uses the correct cross-compiler for Windows
|
1169 |
2. **Nuitka Integration**: Proper `--mingw64` flag usage
|
1170 |
+
3. **Architecture Targeting**: Explicit `--target-arch=x64` for 64-bit
|
1171 |
+
4. **Real-time Monitoring**: Watch MinGW-w64 compilation in real-time
|
1172 |
+
5. **Wine Testing**: Optional testing of Windows executables on Linux
|
1173 |
+
6. **Automatic Detection**: Checks for required MinGW-w64 components
|
1174 |
+
7. **Proper Flags**: Uses `--windows-disable-console` for GUI apps
|
1175 |
|
1176 |
## β
Improvements in This Version
|
1177 |
|
|
|
1179 |
|
1180 |
- β
Proper MinGW-w64 implementation
|
1181 |
- β
Follows official Nuitka documentation
|
1182 |
+
- β
**Explicit 64-bit architecture targeting**
|
1183 |
- β
Real-time MinGW-w64 status in logs
|
1184 |
- β
Automatic MinGW-w64 component detection
|
1185 |
- β
Wine testing instructions
|
1186 |
- β
Better error handling for cross-compilation
|
1187 |
+
- β
**Architecture verification in output**
|
1188 |
|
1189 |
## βοΈ Environment Status
|
1190 |
|
|
|
1197 |
Static Libpython: {'β
Available' if check_static_libpython() else 'β Not Available'}
|
1198 |
Environment: Hugging Face Spaces
|
1199 |
Cross-Compilation: Proper MinGW-w64 support
|
1200 |
+
Target Architecture: x64 (64-bit) for Windows
|
1201 |
```
|
1202 |
|
1203 |
## π Best Practices
|
|
|
1209 |
3. β
Check MinGW-w64 status before compiling .exe
|
1210 |
4. β
Use real-time logs to monitor progress
|
1211 |
5. β
Test .exe files with wine if available
|
1212 |
+
6. β
**Verify 64-bit architecture in compilation logs**
|
1213 |
+
7. β
Test on actual Windows 64-bit systems
|
1214 |
|
1215 |
**Package compatibility:**
|
1216 |
|
|
|
1218 |
2. β οΈ Avoid packages with C extensions when cross-compiling
|
1219 |
3. β οΈ GUI frameworks may need special handling
|
1220 |
4. β οΈ Windows-specific packages won't work in cross-compilation
|
1221 |
+
5. β
**Ensure all dependencies support 64-bit architecture**
|
1222 |
|
1223 |
## π§ Troubleshooting
|
1224 |
|
|
|
1227 |
- **Missing MinGW-w64**: Install required packages in Docker image
|
1228 |
- **Cross-compilation fails**: Check package compatibility
|
1229 |
- **Large .exe files**: Normal for standalone Windows executables
|
1230 |
+
- **32-bit/64-bit mismatch**: Script now explicitly targets x64
|
1231 |
- **Runtime errors**: Test with different Nuitka flags
|
1232 |
- **Wine issues**: Wine testing is optional, real Windows testing preferred
|
1233 |
|
|
|
1237 |
|
1238 |
1. Nuitka converts Python to C code
|
1239 |
2. MinGW-w64 cross-compiles C to Windows PE format
|
1240 |
+
3. **Explicitly targets x64 (64-bit) architecture**
|
1241 |
+
4. Static linking reduces Windows dependencies
|
1242 |
+
5. Result is a native Windows 64-bit executable
|
1243 |
+
6. Optional Wine testing for basic validation
|
1244 |
|
1245 |
**Command structure:**
|
1246 |
```bash
|
1247 |
python -m nuitka \\
|
1248 |
--mingw64 \\
|
1249 |
+
--target-arch=x64 \\
|
1250 |
--onefile \\
|
1251 |
--windows-disable-console \\
|
1252 |
--show-progress \\
|
1253 |
your_script.py
|
1254 |
```
|
1255 |
|
1256 |
+
**Key flags for 64-bit compilation:**
|
1257 |
+
- `--mingw64`: Use MinGW-w64 toolchain
|
1258 |
+
- `--target-arch=x64`: Explicitly target 64-bit architecture
|
1259 |
+
- `--msvc=14.3`: MSVC compatibility mode
|
1260 |
+
|
1261 |
+
This ensures **proper 64-bit Windows compatibility**.
|
1262 |
""")
|
1263 |
|
1264 |
gr.Markdown("---")
|
1265 |
+
gr.Markdown("π€ Created by Claude 3.7 Sonnet | π Powered by Nuitka + MinGW-w64 | βοΈ Proper x64 cross-compilation | π Real-time logs")
|
1266 |
|
1267 |
if __name__ == "__main__":
|
1268 |
# Create necessary directories on startup
|