Obfuscating a Python script using PyArmor and running it on another machine involves several key steps. Below is a guide to help you through the process:
Step 1: Install PyArmor
First, make sure you have PyArmor installed on your machine. You can install it via pip:
pip install pyarmor
Step 2: Obfuscate Your Python Script
Once you have PyArmor installed, you can obfuscate your Python script. Here's how to do it:
-
Navigate to the directory where your Python script is located.
-
Run the following command to obfuscate your script:
pyarmor pack your_script.py
This command will obfuscate your_script.py and create a dist folder containing the obfuscated files.
Step 3: Prepare the Environment
Once your script has been obfuscated, you need to prepare it for transfer to the other machine:
- Copy the obfuscated files: Copy the entire
dist directory (and optionally any required dependencies).
- License File: If you are using the licensed version of PyArmor, make sure to copy the license file (
pytransform.so or pytransform.dll, depending on the platform) and any necessary runtime files.
Step 4: Transfer Files to the Target Machine
Transfer the dist directory along with any required PyArmor runtime files to the target machine. You can use methods like USB drives, cloud storage, or any file transfer method that suits you.
Step 5: Install Python on the Target Machine
Ensure that Python is installed on the target machine. If Python is not installed, you can download and install it from the official Python website.
Step 6: Run the Obfuscated Script
After transferring the necessary files, you can run the obfuscated script on the target machine:
-
Open a command line or terminal on the target machine.
-
Navigate to the dist directory where the obfuscated script is located.
-
Execute the obfuscated script using Python:
python your_script.py
Step 7: (Optional) Package Dependencies
If your script has dependencies that aren't available on the target machine, you may need to package these dependencies with your obfuscated script. You can use tools like pip to install any necessary packages on the target machine.
Note on Licensing
If you are planning to distribute the obfuscated script, remember that you must ensure compliance with PyArmor's licensing terms. Additionally, if your script is using the licensed features of PyArmor, you may need to include the license file along with your distributed application.
Conclusion
That’s it! You have successfully obfuscated your Python script with PyArmor and set it up to run on another machine. Make sure to test the obfuscated script on the new machine to confirm everything works as expected.