Advertisement
efxtv

3 ways to convert python.py to exe file for Windows and Linux

Nov 21st, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | Cybersecurity | 0 0
  1. Ways to Convert Python Scripts to .Exe Files
  2.  
  3. Note: Install Python from https://www.python.org/downloads/windows/
  4.  
  5. Method 1: Using PyInstaller
  6.  
  7. Step 1: Install PyInstaller
  8. $ pip install pyinstaller
  9.  
  10. Step 2: Navigate to your script’s directory
  11. $ cd path\to\your\script
  12.  
  13. Step 3: Run PyInstaller
  14. $ pyinstaller --onefile your_script.py
  15.  
  16. Step 4: Locate the executable
  17. $ path\to\your\script\dist\your_script.exe
  18.  
  19. Method 2: Using Auto PY to EXE
  20.  
  21. Step 1: Install Auto PY to EXE
  22. $ pip install auto-py-to-exe
  23.  
  24. Step 2: Run Auto PY to EXE
  25. $ auto-py-to-exe
  26.  
  27. Step 3: Configure the settings
  28. - The Auto PY to EXE GUI will open. In the GUI, you’ll see various options and settings.
  29. - Click on the Browse button and select your Python script file.
  30. - Adjust other settings as needed, such as adding additional files or modules, selecting an output directory, and setting other options based on your requirements.
  31.  
  32. Step 4: Select the Compilation Mode
  33. - Choose the compilation mode based on whether you want a single executable file or a folder with the executable and supporting files.
  34.  
  35. Step 5: Click “Convert .py to .exe
  36.  
  37. Step 6: Find the output
  38. - Once the conversion is complete, you will find the generated .exe file in the specified output directory.
  39.  
  40. Method 3: Using cx_Freeze
  41.  
  42. Step 1: Install cx_Freeze
  43. $ pip install cx_Freeze
  44.  
  45. Step 2: Create a setup script
  46. - Create a setup script (e.g., `setup.py`)
  47.  
  48. from cx_Freeze import setup, Executable
  49.  
  50.    setup(
  51.  
  52.        name="YourAppName",
  53.  
  54.        version="1.0",
  55.  
  56.        description="Your application description",
  57.  
  58.        executables=[Executable("your_script.py")],
  59.  
  60.    )   
  61.    
  62. Step 3: Run the setup script
  63. $ python setup.py build
  64.  
  65. Step 4: Locate the executable
  66. After running the `build` command, you can find the executable in the `build` directory.
  67.  
  68. Source here https://www.analyticsvidhya.com/blog/2024/01/ways-to-convert-python-scripts-to-exe-files/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement