Update app.py
Browse files
app.py
CHANGED
@@ -344,14 +344,12 @@ Add this to your requirements.txt and redeploy the space."""
|
|
344 |
cmd.extend([
|
345 |
"--mingw64", # Use MinGW-w64 for cross-compilation
|
346 |
"--windows-disable-console", # Disable console window for GUI apps
|
347 |
-
"--target-arch=x64", # Explicitly target 64-bit architecture
|
348 |
-
"--msvc=14.3", # Use MSVC compatibility mode
|
349 |
])
|
350 |
# Note: --mingw64 flag tells Nuitka to use MinGW-w64 for Windows cross-compilation
|
351 |
if log_queue:
|
352 |
-
log_queue.put("Using MinGW-w64 for Windows
|
353 |
-
log_queue.put("Note: Cross-compiling from Linux to Windows
|
354 |
-
log_queue.put("Target
|
355 |
|
356 |
# Run compilation
|
357 |
if progress_callback:
|
@@ -457,10 +455,10 @@ Add this to your requirements.txt and redeploy the space."""
|
|
457 |
except:
|
458 |
linking_info = "βΉοΈ Compiled binary created successfully"
|
459 |
else:
|
460 |
-
# For Windows
|
461 |
-
linking_info = "π¦ Windows
|
462 |
if log_queue:
|
463 |
-
log_queue.put("Binary
|
464 |
|
465 |
# Rename to desired extension
|
466 |
if output_extension in ['.bin', '.sh', '.exe'] and not binary_path.endswith(output_extension):
|
@@ -489,7 +487,7 @@ Add this to your requirements.txt and redeploy the space."""
|
|
489 |
- **Compiled with Python**: {current_python}
|
490 |
- **Static Libpython Available**: {static_status}
|
491 |
- **Linking**: {linking_info}
|
492 |
-
- **Target Platform**: {'Windows
|
493 |
|
494 |
## Environment Results:
|
495 |
**System Packages**: {packages_result}
|
@@ -501,22 +499,22 @@ Add this to your requirements.txt and redeploy the space."""
|
|
501 |
## π Portability Notes:
|
502 |
- This binary was compiled with maximum compatibility settings
|
503 |
- Using --onefile for single-file distribution
|
504 |
-
- {'Cross-compiled
|
505 |
{f'- Console window disabled for Windows GUI applications' if output_extension == '.exe' else ''}
|
506 |
-
- {'
|
507 |
|
508 |
## π Usage Instructions:
|
509 |
```bash
|
510 |
-
{f'# For Windows
|
511 |
{f'# Download to Windows machine and run:' if output_extension == '.exe' else ''}
|
512 |
{f'{binary_basename}' if output_extension == '.exe' else f'./{binary_basename}'}
|
513 |
```
|
514 |
|
515 |
## β οΈ Cross-Compilation Notes:
|
516 |
-
{f'''- Compiled from Linux to Windows
|
517 |
-
-
|
518 |
- Tested with wine if available: `wine {binary_basename}`
|
519 |
-
- Compatible with Windows
|
520 |
- Some Windows-specific libraries may need additional setup
|
521 |
- GUI frameworks may require special handling''' if output_extension == '.exe' else 'Native Linux compilation with maximum compatibility'}
|
522 |
|
@@ -532,7 +530,7 @@ Add this to your requirements.txt and redeploy the space."""
|
|
532 |
if log_queue:
|
533 |
log_queue.put("β
Compilation completed successfully!\n")
|
534 |
if output_extension == ".exe":
|
535 |
-
log_queue.put("π· You can test the Windows
|
536 |
|
537 |
return result_summary, binary_path, compile_output, True
|
538 |
else:
|
@@ -542,7 +540,7 @@ Add this to your requirements.txt and redeploy the space."""
|
|
542 |
## Error Details:
|
543 |
- **Exit Code**: {process.returncode}
|
544 |
- **Mode Attempted**: {mode_name}
|
545 |
-
- **Target**: {'Windows
|
546 |
|
547 |
## Environment Results:
|
548 |
**System Packages**: {packages_result}
|
@@ -560,7 +558,7 @@ Add this to your requirements.txt and redeploy the space."""
|
|
560 |
4. Review the compilation logs above
|
561 |
{f"5. For Windows cross-compilation, ensure MinGW-w64 is properly installed" if output_extension == '.exe' else ''}
|
562 |
{f"6. Some packages may not support Windows cross-compilation" if output_extension == '.exe' else ''}
|
563 |
-
{f"7.
|
564 |
|
565 |
## Missing Dependencies:
|
566 |
{', '.join(missing_deps) if missing_deps else 'None detected'}
|
@@ -570,7 +568,7 @@ Add this to your requirements.txt and redeploy the space."""
|
|
570 |
- **Python Version**: {current_python}
|
571 |
- **Platform**: {platform.platform()}
|
572 |
{f"- **MinGW-w64**: {'Available' if not check_mingw_installation() else 'Missing components'}" if output_extension == '.exe' else ''}
|
573 |
-
{f"- **Target Architecture**: x64 (
|
574 |
if progress_callback:
|
575 |
progress_callback(1.0, "Compilation failed β")
|
576 |
|
@@ -603,7 +601,7 @@ Add this to your requirements.txt and redeploy the space."""
|
|
603 |
3. Check available disk space
|
604 |
4. Try with simpler code first
|
605 |
{f"5. Ensure MinGW-w64 is installed for Windows cross-compilation" if output_extension == '.exe' else ''}
|
606 |
-
{f"6.
|
607 |
if progress_callback:
|
608 |
progress_callback(1.0, "Error occurred β")
|
609 |
|
@@ -623,7 +621,7 @@ def run_compiled_binary(binary_path):
|
|
623 |
# Try to run with wine first
|
624 |
wine_result = subprocess.run(["which", "wine"], capture_output=True)
|
625 |
if wine_result.returncode == 0:
|
626 |
-
return f"""π· **Running Windows
|
627 |
|
628 |
## Execution:
|
629 |
```bash
|
@@ -643,7 +641,7 @@ To run on Windows:
|
|
643 |
|
644 |
## Note:
|
645 |
- Wine is available on this system for basic testing
|
646 |
-
- This executable is compiled for Windows 64-bit (
|
647 |
- Full compatibility requires running on actual Windows
|
648 |
- Some features may not work correctly in wine"""
|
649 |
else:
|
@@ -651,7 +649,7 @@ To run on Windows:
|
|
651 |
|
652 |
## To run this binary:
|
653 |
1. Download the .exe file
|
654 |
-
2. Transfer it to a Windows machine
|
655 |
3. Run it by double-clicking or from command prompt
|
656 |
|
657 |
```cmd
|
@@ -661,9 +659,8 @@ cd /path/to/downloaded/file
|
|
661 |
```
|
662 |
|
663 |
## Note:
|
664 |
-
- This executable is compiled for Windows 64-bit (
|
665 |
-
- Compatible with Windows
|
666 |
-
- Will not work on 32-bit Windows systems
|
667 |
|
668 |
## Alternative:
|
669 |
Install wine to test Windows executables on Linux:
|
@@ -708,7 +705,7 @@ wine {os.path.basename(binary_path)}
|
|
708 |
# Create Gradio interface
|
709 |
with gr.Blocks(title="Nuitka Python Compiler with MinGW-w64", theme=gr.themes.Soft()) as app:
|
710 |
gr.Markdown("# π Nuitka Python Compiler (MinGW-w64 Cross-Compilation)")
|
711 |
-
gr.Markdown("Convert your Python code into portable executables using Nuitka, with
|
712 |
|
713 |
# Check environment status
|
714 |
has_static = check_static_libpython()
|
@@ -727,15 +724,15 @@ with gr.Blocks(title="Nuitka Python Compiler with MinGW-w64", theme=gr.themes.So
|
|
727 |
gr.Markdown(f"β οΈ **MinGW-w64 Components Missing:** {', '.join(mingw_missing)}")
|
728 |
gr.Markdown("π **For Windows .exe generation**, MinGW-w64 should be pre-installed in the environment.")
|
729 |
else:
|
730 |
-
gr.Markdown("β
**MinGW-w64 Available!** Windows
|
731 |
|
732 |
if [dep for dep in missing_deps if dep != "nuitka" and dep != "mingw-w64"]:
|
733 |
gr.Markdown(f"β οΈ **Other missing dependencies:** {', '.join([dep for dep in missing_deps if dep != 'nuitka' and dep != 'mingw-w64'])}")
|
734 |
|
735 |
# MinGW-w64 information
|
736 |
gr.Markdown("""
|
737 |
-
> βΉοΈ **MinGW-w64 Cross-Compilation**: Using
|
738 |
-
>
|
739 |
""")
|
740 |
|
741 |
with gr.Tabs():
|
@@ -819,7 +816,7 @@ input('Press Enter to exit...')""",
|
|
819 |
if mingw_missing:
|
820 |
gr.Markdown(f"β οΈ **MinGW-w64**: Missing ({', '.join(mingw_missing)})")
|
821 |
else:
|
822 |
-
gr.Markdown("β
**MinGW-w64**: Available for Windows
|
823 |
|
824 |
if check_static_libpython():
|
825 |
gr.Markdown("π **Static libpython will be used for Linux targets!**")
|
@@ -827,7 +824,7 @@ input('Press Enter to exit...')""",
|
|
827 |
gr.Markdown("π§ **Using portable compilation flags**")
|
828 |
|
829 |
# Add architecture notice
|
830 |
-
gr.Markdown("ποΈ **Windows Target**:
|
831 |
|
832 |
compile_btn = gr.Button("π Compile with Nuitka", variant="primary")
|
833 |
|
@@ -915,10 +912,10 @@ input('Press Enter to exit...')""",
|
|
915 |
# Progress simulation with log updates
|
916 |
progress_steps = [
|
917 |
(0.1, "Checking Nuitka installation..."),
|
918 |
-
(0.15, "Checking MinGW-w64 for Windows
|
919 |
(0.2, "Setting up environment..."),
|
920 |
(0.3, "Installing requirements..."),
|
921 |
-
(0.4, f"Starting {'Windows
|
922 |
(0.5, "Processing imports..."),
|
923 |
(0.6, "Optimizing code..."),
|
924 |
(0.7, f"Creating {extension} binary..."),
|
@@ -966,7 +963,7 @@ input('Press Enter to exit...')""",
|
|
966 |
# Final progress update
|
967 |
final_status = "β
Compilation successful!" if success else "β Compilation failed"
|
968 |
if success and extension == ".exe":
|
969 |
-
final_status += " (Windows
|
970 |
|
971 |
yield (
|
972 |
gr.update(visible=True), # progress_section
|
@@ -1064,23 +1061,22 @@ input('Press Enter to exit...')""",
|
|
1064 |
|
1065 |
with gr.TabItem("π How to Use"):
|
1066 |
gr.Markdown("""
|
1067 |
-
## π― MinGW-w64 Cross-Compilation to Windows
|
1068 |
|
1069 |
-
**Proper Windows
|
1070 |
|
1071 |
-
This app
|
1072 |
- **MinGW-w64 toolchain** for cross-compilation
|
1073 |
- **`--mingw64` flag** in Nuitka
|
1074 |
-
- **`--target-arch=x64`** for explicit 64-bit compilation
|
1075 |
- **`--windows-disable-console`** for GUI applications
|
1076 |
-
- **
|
1077 |
|
1078 |
**Features:**
|
1079 |
- Real-time compilation logs
|
1080 |
- Visual progress bar with cross-compilation status
|
1081 |
- Automatic MinGW-w64 detection
|
1082 |
- Wine testing support for .exe files
|
1083 |
-
- **
|
1084 |
|
1085 |
## π Usage Instructions
|
1086 |
|
@@ -1092,13 +1088,13 @@ input('Press Enter to exit...')""",
|
|
1092 |
### 2. Choose Target Platform
|
1093 |
- **Linux (.bin)**: Native Linux executable (fastest compilation)
|
1094 |
- **Linux (.sh)**: Shell script format
|
1095 |
-
- **Windows (.exe)**: Cross-compiled using MinGW-w64
|
1096 |
|
1097 |
### 3. Compile
|
1098 |
- Click "Compile with Nuitka"
|
1099 |
- Watch the real-time logs showing MinGW-w64 usage
|
1100 |
- Monitor the progress bar for cross-compilation status
|
1101 |
-
- Download the resulting
|
1102 |
|
1103 |
### 4. Run Your Binary
|
1104 |
|
@@ -1109,7 +1105,7 @@ input('Press Enter to exit...')""",
|
|
1109 |
./compiled_program.bin
|
1110 |
```
|
1111 |
|
1112 |
-
#### For Windows executables
|
1113 |
```cmd
|
1114 |
# Download the .exe file to Windows
|
1115 |
compiled_program.exe
|
@@ -1127,7 +1123,7 @@ input('Press Enter to exit...')""",
|
|
1127 |
|
1128 |
## π§ MinGW-w64 Requirements
|
1129 |
|
1130 |
-
**For Windows
|
1131 |
```bash
|
1132 |
# Ubuntu/Debian
|
1133 |
apt install mingw-w64 gcc-mingw-w64 g++-mingw-w64
|
@@ -1139,50 +1135,45 @@ input('Press Enter to exit...')""",
|
|
1139 |
## β οΈ Cross-Compilation Notes
|
1140 |
|
1141 |
**Windows .exe from Linux (MinGW-w64 method):**
|
1142 |
-
- β
Uses
|
1143 |
-
- β
|
1144 |
-
- β
Produces native Windows 64-bit executables
|
1145 |
-
- β
Explicitly targets x64 architecture
|
1146 |
- β οΈ Some Python packages may not cross-compile
|
1147 |
- β οΈ Windows-specific APIs may need special handling
|
1148 |
- β
Can be tested with wine on Linux
|
1149 |
-
- β
Compatible with Windows
|
1150 |
|
1151 |
## π Architecture Support
|
1152 |
|
1153 |
| Target | Architecture | Compatibility | Notes |
|
1154 |
|--------|-------------|---------------|-------|
|
1155 |
| Linux | x64 | Native | Best performance |
|
1156 |
-
| Windows | x64 (64-bit) | Excellent |
|
1157 |
-
| Windows | x86 (32-bit) | Not
|
1158 |
""")
|
1159 |
|
1160 |
with gr.TabItem("βΉοΈ About"):
|
1161 |
gr.Markdown(f"""
|
1162 |
## π§ MinGW-w64 Cross-Compilation Technology
|
1163 |
|
1164 |
-
**
|
1165 |
|
1166 |
-
1. **MinGW-w64 Toolchain**: Uses the
|
1167 |
-
2. **Nuitka Integration**:
|
1168 |
-
3. **Architecture
|
1169 |
4. **Real-time Monitoring**: Watch MinGW-w64 compilation in real-time
|
1170 |
5. **Wine Testing**: Optional testing of Windows executables on Linux
|
1171 |
6. **Automatic Detection**: Checks for required MinGW-w64 components
|
1172 |
-
7. **Proper Flags**: Uses `--windows-disable-console` for GUI apps
|
1173 |
|
1174 |
-
## β
|
1175 |
|
1176 |
-
**
|
1177 |
|
1178 |
- β
Proper MinGW-w64 implementation
|
1179 |
-
- β
Follows official Nuitka documentation
|
1180 |
-
- β
**Explicit 64-bit architecture targeting**
|
1181 |
- β
Real-time MinGW-w64 status in logs
|
1182 |
- β
Automatic MinGW-w64 component detection
|
1183 |
- β
Wine testing instructions
|
1184 |
- β
Better error handling for cross-compilation
|
1185 |
-
- β
**
|
1186 |
|
1187 |
## βοΈ Environment Status
|
1188 |
|
@@ -1194,8 +1185,8 @@ input('Press Enter to exit...')""",
|
|
1194 |
MinGW-w64 Status: {'β
Available' if not check_mingw_installation() else f'β Missing: {", ".join(check_mingw_installation())}'}
|
1195 |
Static Libpython: {'β
Available' if check_static_libpython() else 'β Not Available'}
|
1196 |
Environment: Hugging Face Spaces
|
1197 |
-
Cross-Compilation:
|
1198 |
-
Target Architecture:
|
1199 |
```
|
1200 |
|
1201 |
## π Best Practices
|
@@ -1207,8 +1198,7 @@ input('Press Enter to exit...')""",
|
|
1207 |
3. β
Check MinGW-w64 status before compiling .exe
|
1208 |
4. β
Use real-time logs to monitor progress
|
1209 |
5. β
Test .exe files with wine if available
|
1210 |
-
6. β
|
1211 |
-
7. β
Test on actual Windows 64-bit systems
|
1212 |
|
1213 |
**Package compatibility:**
|
1214 |
|
@@ -1216,7 +1206,6 @@ input('Press Enter to exit...')""",
|
|
1216 |
2. β οΈ Avoid packages with C extensions when cross-compiling
|
1217 |
3. β οΈ GUI frameworks may need special handling
|
1218 |
4. β οΈ Windows-specific packages won't work in cross-compilation
|
1219 |
-
5. β
**Ensure all dependencies support 64-bit architecture**
|
1220 |
|
1221 |
## π§ Troubleshooting
|
1222 |
|
@@ -1225,7 +1214,6 @@ input('Press Enter to exit...')""",
|
|
1225 |
- **Missing MinGW-w64**: Install required packages in Docker image
|
1226 |
- **Cross-compilation fails**: Check package compatibility
|
1227 |
- **Large .exe files**: Normal for standalone Windows executables
|
1228 |
-
- **32-bit/64-bit mismatch**: Script now explicitly targets x64
|
1229 |
- **Runtime errors**: Test with different Nuitka flags
|
1230 |
- **Wine issues**: Wine testing is optional, real Windows testing preferred
|
1231 |
|
@@ -1235,32 +1223,30 @@ input('Press Enter to exit...')""",
|
|
1235 |
|
1236 |
1. Nuitka converts Python to C code
|
1237 |
2. MinGW-w64 cross-compiles C to Windows PE format
|
1238 |
-
3. **
|
1239 |
4. Static linking reduces Windows dependencies
|
1240 |
-
5. Result is a native Windows
|
1241 |
6. Optional Wine testing for basic validation
|
1242 |
|
1243 |
**Command structure:**
|
1244 |
```bash
|
1245 |
python -m nuitka \\
|
1246 |
--mingw64 \\
|
1247 |
-
--target-arch=x64 \\
|
1248 |
--onefile \\
|
1249 |
--windows-disable-console \\
|
1250 |
--show-progress \\
|
1251 |
your_script.py
|
1252 |
```
|
1253 |
|
1254 |
-
**Key flags
|
1255 |
- `--mingw64`: Use MinGW-w64 toolchain
|
1256 |
-
- `--
|
1257 |
-
- `--msvc=14.3`: MSVC compatibility mode
|
1258 |
|
1259 |
-
|
1260 |
""")
|
1261 |
|
1262 |
gr.Markdown("---")
|
1263 |
-
gr.Markdown("π€ Created by Claude 3.7 Sonnet | π Powered by Nuitka + MinGW-w64 | βοΈ
|
1264 |
|
1265 |
if __name__ == "__main__":
|
1266 |
# Create necessary directories on startup
|
|
|
344 |
cmd.extend([
|
345 |
"--mingw64", # Use MinGW-w64 for cross-compilation
|
346 |
"--windows-disable-console", # Disable console window for GUI apps
|
|
|
|
|
347 |
])
|
348 |
# Note: --mingw64 flag tells Nuitka to use MinGW-w64 for Windows cross-compilation
|
349 |
if log_queue:
|
350 |
+
log_queue.put("Using MinGW-w64 for Windows cross-compilation\n")
|
351 |
+
log_queue.put("Note: Cross-compiling from Linux to Windows using MinGW-w64 toolchain\n")
|
352 |
+
log_queue.put("Target: Windows 64-bit (MinGW-w64 default)\n")
|
353 |
|
354 |
# Run compilation
|
355 |
if progress_callback:
|
|
|
455 |
except:
|
456 |
linking_info = "βΉοΈ Compiled binary created successfully"
|
457 |
else:
|
458 |
+
# For Windows
|
459 |
+
linking_info = "π¦ Windows executable (cross-compiled with MinGW-w64)"
|
460 |
if log_queue:
|
461 |
+
log_queue.put("Binary: Windows x64 format (MinGW-w64 default)\n")
|
462 |
|
463 |
# Rename to desired extension
|
464 |
if output_extension in ['.bin', '.sh', '.exe'] and not binary_path.endswith(output_extension):
|
|
|
487 |
- **Compiled with Python**: {current_python}
|
488 |
- **Static Libpython Available**: {static_status}
|
489 |
- **Linking**: {linking_info}
|
490 |
+
- **Target Platform**: {'Windows (via MinGW-w64)' if output_extension == '.exe' else 'Linux'}
|
491 |
|
492 |
## Environment Results:
|
493 |
**System Packages**: {packages_result}
|
|
|
499 |
## π Portability Notes:
|
500 |
- This binary was compiled with maximum compatibility settings
|
501 |
- Using --onefile for single-file distribution
|
502 |
+
- {'Cross-compiled for Windows using MinGW-w64 toolchain' if output_extension == '.exe' else 'Should work on most compatible Linux systems'}
|
503 |
{f'- Console window disabled for Windows GUI applications' if output_extension == '.exe' else ''}
|
504 |
+
- {'MinGW-w64 produces 64-bit Windows executables by default' if output_extension == '.exe' else ''}
|
505 |
|
506 |
## π Usage Instructions:
|
507 |
```bash
|
508 |
+
{f'# For Windows:' if output_extension == '.exe' else f'chmod +x {binary_basename}'}
|
509 |
{f'# Download to Windows machine and run:' if output_extension == '.exe' else ''}
|
510 |
{f'{binary_basename}' if output_extension == '.exe' else f'./{binary_basename}'}
|
511 |
```
|
512 |
|
513 |
## β οΈ Cross-Compilation Notes:
|
514 |
+
{f'''- Compiled from Linux to Windows using MinGW-w64
|
515 |
+
- MinGW-w64 creates 64-bit executables by default
|
516 |
- Tested with wine if available: `wine {binary_basename}`
|
517 |
+
- Compatible with Windows 64-bit systems
|
518 |
- Some Windows-specific libraries may need additional setup
|
519 |
- GUI frameworks may require special handling''' if output_extension == '.exe' else 'Native Linux compilation with maximum compatibility'}
|
520 |
|
|
|
530 |
if log_queue:
|
531 |
log_queue.put("β
Compilation completed successfully!\n")
|
532 |
if output_extension == ".exe":
|
533 |
+
log_queue.put("π· You can test the Windows executable with: wine " + binary_basename + "\n")
|
534 |
|
535 |
return result_summary, binary_path, compile_output, True
|
536 |
else:
|
|
|
540 |
## Error Details:
|
541 |
- **Exit Code**: {process.returncode}
|
542 |
- **Mode Attempted**: {mode_name}
|
543 |
+
- **Target**: {'Windows (via MinGW-w64)' if output_extension == '.exe' else 'Linux'}
|
544 |
|
545 |
## Environment Results:
|
546 |
**System Packages**: {packages_result}
|
|
|
558 |
4. Review the compilation logs above
|
559 |
{f"5. For Windows cross-compilation, ensure MinGW-w64 is properly installed" if output_extension == '.exe' else ''}
|
560 |
{f"6. Some packages may not support Windows cross-compilation" if output_extension == '.exe' else ''}
|
561 |
+
{f"7. MinGW-w64 creates 64-bit executables by default" if output_extension == '.exe' else ''}
|
562 |
|
563 |
## Missing Dependencies:
|
564 |
{', '.join(missing_deps) if missing_deps else 'None detected'}
|
|
|
568 |
- **Python Version**: {current_python}
|
569 |
- **Platform**: {platform.platform()}
|
570 |
{f"- **MinGW-w64**: {'Available' if not check_mingw_installation() else 'Missing components'}" if output_extension == '.exe' else ''}
|
571 |
+
{f"- **Target Architecture**: x64 (MinGW-w64 default)" if output_extension == '.exe' else ''}"""
|
572 |
if progress_callback:
|
573 |
progress_callback(1.0, "Compilation failed β")
|
574 |
|
|
|
601 |
3. Check available disk space
|
602 |
4. Try with simpler code first
|
603 |
{f"5. Ensure MinGW-w64 is installed for Windows cross-compilation" if output_extension == '.exe' else ''}
|
604 |
+
{f"6. MinGW-w64 produces 64-bit Windows executables by default" if output_extension == '.exe' else ''}"""
|
605 |
if progress_callback:
|
606 |
progress_callback(1.0, "Error occurred β")
|
607 |
|
|
|
621 |
# Try to run with wine first
|
622 |
wine_result = subprocess.run(["which", "wine"], capture_output=True)
|
623 |
if wine_result.returncode == 0:
|
624 |
+
return f"""π· **Running Windows executable with Wine**
|
625 |
|
626 |
## Execution:
|
627 |
```bash
|
|
|
641 |
|
642 |
## Note:
|
643 |
- Wine is available on this system for basic testing
|
644 |
+
- This executable is compiled for Windows 64-bit (MinGW-w64 default)
|
645 |
- Full compatibility requires running on actual Windows
|
646 |
- Some features may not work correctly in wine"""
|
647 |
else:
|
|
|
649 |
|
650 |
## To run this binary:
|
651 |
1. Download the .exe file
|
652 |
+
2. Transfer it to a Windows machine
|
653 |
3. Run it by double-clicking or from command prompt
|
654 |
|
655 |
```cmd
|
|
|
659 |
```
|
660 |
|
661 |
## Note:
|
662 |
+
- This executable is compiled for Windows 64-bit (MinGW-w64 default)
|
663 |
+
- Compatible with most Windows 64-bit systems
|
|
|
664 |
|
665 |
## Alternative:
|
666 |
Install wine to test Windows executables on Linux:
|
|
|
705 |
# Create Gradio interface
|
706 |
with gr.Blocks(title="Nuitka Python Compiler with MinGW-w64", theme=gr.themes.Soft()) as app:
|
707 |
gr.Markdown("# π Nuitka Python Compiler (MinGW-w64 Cross-Compilation)")
|
708 |
+
gr.Markdown("Convert your Python code into portable executables using Nuitka, with MinGW-w64 support for Windows cross-compilation.")
|
709 |
|
710 |
# Check environment status
|
711 |
has_static = check_static_libpython()
|
|
|
724 |
gr.Markdown(f"β οΈ **MinGW-w64 Components Missing:** {', '.join(mingw_missing)}")
|
725 |
gr.Markdown("π **For Windows .exe generation**, MinGW-w64 should be pre-installed in the environment.")
|
726 |
else:
|
727 |
+
gr.Markdown("β
**MinGW-w64 Available!** Windows cross-compilation supported.")
|
728 |
|
729 |
if [dep for dep in missing_deps if dep != "nuitka" and dep != "mingw-w64"]:
|
730 |
gr.Markdown(f"β οΈ **Other missing dependencies:** {', '.join([dep for dep in missing_deps if dep != 'nuitka' and dep != 'mingw-w64'])}")
|
731 |
|
732 |
# MinGW-w64 information
|
733 |
gr.Markdown("""
|
734 |
+
> βΉοΈ **MinGW-w64 Cross-Compilation**: Using MinGW-w64 toolchain for Windows .exe generation.
|
735 |
+
> MinGW-w64 produces 64-bit Windows executables by default.
|
736 |
""")
|
737 |
|
738 |
with gr.Tabs():
|
|
|
816 |
if mingw_missing:
|
817 |
gr.Markdown(f"β οΈ **MinGW-w64**: Missing ({', '.join(mingw_missing)})")
|
818 |
else:
|
819 |
+
gr.Markdown("β
**MinGW-w64**: Available for Windows cross-compilation")
|
820 |
|
821 |
if check_static_libpython():
|
822 |
gr.Markdown("π **Static libpython will be used for Linux targets!**")
|
|
|
824 |
gr.Markdown("π§ **Using portable compilation flags**")
|
825 |
|
826 |
# Add architecture notice
|
827 |
+
gr.Markdown("ποΈ **Windows Target**: MinGW-w64 produces 64-bit executables by default")
|
828 |
|
829 |
compile_btn = gr.Button("π Compile with Nuitka", variant="primary")
|
830 |
|
|
|
912 |
# Progress simulation with log updates
|
913 |
progress_steps = [
|
914 |
(0.1, "Checking Nuitka installation..."),
|
915 |
+
(0.15, "Checking MinGW-w64 for Windows targets..." if extension == ".exe" else "Checking environment..."),
|
916 |
(0.2, "Setting up environment..."),
|
917 |
(0.3, "Installing requirements..."),
|
918 |
+
(0.4, f"Starting {'Windows cross-' if extension == '.exe' else ''}compilation..."),
|
919 |
(0.5, "Processing imports..."),
|
920 |
(0.6, "Optimizing code..."),
|
921 |
(0.7, f"Creating {extension} binary..."),
|
|
|
963 |
# Final progress update
|
964 |
final_status = "β
Compilation successful!" if success else "β Compilation failed"
|
965 |
if success and extension == ".exe":
|
966 |
+
final_status += " (Windows .exe created)"
|
967 |
|
968 |
yield (
|
969 |
gr.update(visible=True), # progress_section
|
|
|
1061 |
|
1062 |
with gr.TabItem("π How to Use"):
|
1063 |
gr.Markdown("""
|
1064 |
+
## π― MinGW-w64 Cross-Compilation to Windows
|
1065 |
|
1066 |
+
**Proper Windows .exe Generation**
|
1067 |
|
1068 |
+
This app uses MinGW-w64 for generating Windows .exe files from Linux:
|
1069 |
- **MinGW-w64 toolchain** for cross-compilation
|
1070 |
- **`--mingw64` flag** in Nuitka
|
|
|
1071 |
- **`--windows-disable-console`** for GUI applications
|
1072 |
+
- **MinGW-w64 produces 64-bit binaries by default**
|
1073 |
|
1074 |
**Features:**
|
1075 |
- Real-time compilation logs
|
1076 |
- Visual progress bar with cross-compilation status
|
1077 |
- Automatic MinGW-w64 detection
|
1078 |
- Wine testing support for .exe files
|
1079 |
+
- **64-bit Windows compatibility**
|
1080 |
|
1081 |
## π Usage Instructions
|
1082 |
|
|
|
1088 |
### 2. Choose Target Platform
|
1089 |
- **Linux (.bin)**: Native Linux executable (fastest compilation)
|
1090 |
- **Linux (.sh)**: Shell script format
|
1091 |
+
- **Windows (.exe)**: Cross-compiled using MinGW-w64
|
1092 |
|
1093 |
### 3. Compile
|
1094 |
- Click "Compile with Nuitka"
|
1095 |
- Watch the real-time logs showing MinGW-w64 usage
|
1096 |
- Monitor the progress bar for cross-compilation status
|
1097 |
+
- Download the resulting binary
|
1098 |
|
1099 |
### 4. Run Your Binary
|
1100 |
|
|
|
1105 |
./compiled_program.bin
|
1106 |
```
|
1107 |
|
1108 |
+
#### For Windows executables:
|
1109 |
```cmd
|
1110 |
# Download the .exe file to Windows
|
1111 |
compiled_program.exe
|
|
|
1123 |
|
1124 |
## π§ MinGW-w64 Requirements
|
1125 |
|
1126 |
+
**For Windows cross-compilation, the following should be pre-installed:**
|
1127 |
```bash
|
1128 |
# Ubuntu/Debian
|
1129 |
apt install mingw-w64 gcc-mingw-w64 g++-mingw-w64
|
|
|
1135 |
## β οΈ Cross-Compilation Notes
|
1136 |
|
1137 |
**Windows .exe from Linux (MinGW-w64 method):**
|
1138 |
+
- β
Uses MinGW-w64 cross-compiler
|
1139 |
+
- β
Produces Windows 64-bit executables by default
|
|
|
|
|
1140 |
- β οΈ Some Python packages may not cross-compile
|
1141 |
- β οΈ Windows-specific APIs may need special handling
|
1142 |
- β
Can be tested with wine on Linux
|
1143 |
+
- β
Compatible with most Windows 64-bit systems
|
1144 |
|
1145 |
## π Architecture Support
|
1146 |
|
1147 |
| Target | Architecture | Compatibility | Notes |
|
1148 |
|--------|-------------|---------------|-------|
|
1149 |
| Linux | x64 | Native | Best performance |
|
1150 |
+
| Windows | x64 (64-bit) | Excellent | MinGW-w64 default |
|
1151 |
+
| Windows | x86 (32-bit) | Not by default | MinGW-w64 creates 64-bit |
|
1152 |
""")
|
1153 |
|
1154 |
with gr.TabItem("βΉοΈ About"):
|
1155 |
gr.Markdown(f"""
|
1156 |
## π§ MinGW-w64 Cross-Compilation Technology
|
1157 |
|
1158 |
+
**Implementation:**
|
1159 |
|
1160 |
+
1. **MinGW-w64 Toolchain**: Uses the cross-compiler for Windows
|
1161 |
+
2. **Nuitka Integration**: Uses `--mingw64` flag
|
1162 |
+
3. **Architecture**: MinGW-w64 produces 64-bit executables by default
|
1163 |
4. **Real-time Monitoring**: Watch MinGW-w64 compilation in real-time
|
1164 |
5. **Wine Testing**: Optional testing of Windows executables on Linux
|
1165 |
6. **Automatic Detection**: Checks for required MinGW-w64 components
|
|
|
1166 |
|
1167 |
+
## β
Features
|
1168 |
|
1169 |
+
**Cross-compilation support:**
|
1170 |
|
1171 |
- β
Proper MinGW-w64 implementation
|
|
|
|
|
1172 |
- β
Real-time MinGW-w64 status in logs
|
1173 |
- β
Automatic MinGW-w64 component detection
|
1174 |
- β
Wine testing instructions
|
1175 |
- β
Better error handling for cross-compilation
|
1176 |
+
- β
**64-bit Windows binaries by default**
|
1177 |
|
1178 |
## βοΈ Environment Status
|
1179 |
|
|
|
1185 |
MinGW-w64 Status: {'β
Available' if not check_mingw_installation() else f'β Missing: {", ".join(check_mingw_installation())}'}
|
1186 |
Static Libpython: {'β
Available' if check_static_libpython() else 'β Not Available'}
|
1187 |
Environment: Hugging Face Spaces
|
1188 |
+
Cross-Compilation: MinGW-w64 support
|
1189 |
+
Target Architecture: 64-bit (MinGW-w64 default)
|
1190 |
```
|
1191 |
|
1192 |
## π Best Practices
|
|
|
1198 |
3. β
Check MinGW-w64 status before compiling .exe
|
1199 |
4. β
Use real-time logs to monitor progress
|
1200 |
5. β
Test .exe files with wine if available
|
1201 |
+
6. β
Test on actual Windows systems
|
|
|
1202 |
|
1203 |
**Package compatibility:**
|
1204 |
|
|
|
1206 |
2. β οΈ Avoid packages with C extensions when cross-compiling
|
1207 |
3. β οΈ GUI frameworks may need special handling
|
1208 |
4. β οΈ Windows-specific packages won't work in cross-compilation
|
|
|
1209 |
|
1210 |
## π§ Troubleshooting
|
1211 |
|
|
|
1214 |
- **Missing MinGW-w64**: Install required packages in Docker image
|
1215 |
- **Cross-compilation fails**: Check package compatibility
|
1216 |
- **Large .exe files**: Normal for standalone Windows executables
|
|
|
1217 |
- **Runtime errors**: Test with different Nuitka flags
|
1218 |
- **Wine issues**: Wine testing is optional, real Windows testing preferred
|
1219 |
|
|
|
1223 |
|
1224 |
1. Nuitka converts Python to C code
|
1225 |
2. MinGW-w64 cross-compiles C to Windows PE format
|
1226 |
+
3. **Default output is 64-bit Windows executable**
|
1227 |
4. Static linking reduces Windows dependencies
|
1228 |
+
5. Result is a native Windows executable
|
1229 |
6. Optional Wine testing for basic validation
|
1230 |
|
1231 |
**Command structure:**
|
1232 |
```bash
|
1233 |
python -m nuitka \\
|
1234 |
--mingw64 \\
|
|
|
1235 |
--onefile \\
|
1236 |
--windows-disable-console \\
|
1237 |
--show-progress \\
|
1238 |
your_script.py
|
1239 |
```
|
1240 |
|
1241 |
+
**Key flags:**
|
1242 |
- `--mingw64`: Use MinGW-w64 toolchain
|
1243 |
+
- `--windows-disable-console`: For GUI apps
|
|
|
1244 |
|
1245 |
+
MinGW-w64 **produces 64-bit Windows executables by default**.
|
1246 |
""")
|
1247 |
|
1248 |
gr.Markdown("---")
|
1249 |
+
gr.Markdown("π€ Created by Claude 3.7 Sonnet | π Powered by Nuitka + MinGW-w64 | βοΈ 64-bit cross-compilation")
|
1250 |
|
1251 |
if __name__ == "__main__":
|
1252 |
# Create necessary directories on startup
|