KEMBAR78
Create Exe | PDF | Command Line Interface | Software Development
0% found this document useful (0 votes)
12 views2 pages

Create Exe

This document outlines the steps to create a .exe file from a Python script using PyInstaller, including installation and command usage. It also provides troubleshooting tips for handling missing dependencies and errors, as well as alternatives for compatibility issues with certain Python versions. Additionally, it advises on running the .exe with administrative privileges if necessary.

Uploaded by

ethicalishu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Create Exe

This document outlines the steps to create a .exe file from a Python script using PyInstaller, including installation and command usage. It also provides troubleshooting tips for handling missing dependencies and errors, as well as alternatives for compatibility issues with certain Python versions. Additionally, it advises on running the .exe with administrative privileges if necessary.

Uploaded by

ethicalishu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Steps to Create a .

exe from a Python Script

#>pyinstaller --onefile --icon=icon.ico --name=KeyLogger-x64-1.2.0.0


keylogger_act.py

1. Install PyInstaller:
- Open Command Prompt or PowerShell.
- Run the following command to install PyInstaller:
pip install pyinstaller

2. Create .exe Using PyInstaller:


- Navigate to the directory where your Python script is located.
- Run the following command to create the .exe:
pyinstaller --onefile your_script.py
- This will generate a dist folder containing your your_script.exe.

3. Run the .exe:


- Go to the dist folder and double-click the .exe to run it.
- If your script uses terminal-based input/output, make sure to add a pause at
the end of the script to keep the terminal window open:
input("Press Enter to exit...")

Steps for Handling Missing Dependencies (e.g., keyboard module)

1. Install Required Modules:


- If your script uses external modules (e.g., keyboard), make sure to install
them in your environment:
pip install keyboard

2. Rebuild .exe with Hidden Imports:


- If PyInstaller does not automatically detect a module, specify it manually
using --hidden-import:
pyinstaller --onefile --hidden-import=keyboard your_script.py

3. Add Missing Modules to .spec File:


- If issues persist, modify the .spec file that PyInstaller generates during the
build process. Add missing imports under the hiddenimports section and rebuild:
Example of adding keyboard to .spec file:
a = Analysis(['your_script.py'],
pathex=['C:\Path\To\Your\Script'],
hiddenimports=['keyboard'],
binaries=[],
datas=[])

- Rebuild the .exe:


pyinstaller your_script.spec

Troubleshooting

1. Module Not Found Error:


- If you get errors like ModuleNotFoundError, make sure the module is installed:
pip install module_name

2. Running .exe on Another Machine:


- If running the .exe on another machine causes issues, make sure the required
libraries are bundled in the .exe. You can use --onefile to bundle everything into
one executable file.

3. Using Python 3.12:


- If you're using Python 3.12 and encounter issues with some libraries (like
keyboard), consider downgrading to Python 3.8 or 3.9. To downgrade, download an
older version of Python from the Python releases page.

4. Alternative for keyboard Module:


- If the keyboard module is causing compatibility issues with Python 3.12,
consider switching to the pynput library. Here's how to use it:
pip install pynput
- Example code with pynput:
from pynput.keyboard import Listener
def on_press(key):
if key == 'esc':
return False
with Listener(on_press=on_press) as listener:
listener.join()

5. Run as Administrator:
- On some systems, you might need to run the .exe with administrative
privileges, especially if using keyboard interaction modules.
- Right-click the .exe file and select Run as Administrator.

You might also like