I have created a python application that I build into a Unix executable using Pyinstaller. The application runs fine until I attempt to code sign it. After code signing, I get the following error when attempting to run the executable:
rosetta error: /var/db/oah/526469a4f4887ee6ca553807c3196c9533da7ef706c684764b83169e8658f8e2/ba3f613b849de777b4a89fdb1760c3c2343ac52546e2629e28f83fbf530a8f27/libffi.8.dylib.aot: unable to mmap __TEXT: 1
Is it possible to code sign dylib files such as this?
Steps to reproduce the error:
Create conda environment with python v3.9
Activate environment and conda install numpy and pyinstaller
Create python script that imports numpy. Doesn't matter what the python script does, can just be one line as long as it imports numpy.
Use pyinstaller to build a distribution for the python file, with code signing like so:
pyinstaller -y --clean --codesign-identity='<apple-id>' --osx-entitlements-file='<path-to-entitlements.plist-file>' <name-of-python-script>
Run the Unix executable that is produced inside the dist folder.
Related
I have to run a shell script on a Centos Linux machine that calls a python file. Inside the python file, there is the following code snippet:
from lib.rclone import Rclone
rclone = Rclone()
if shutil.which("rclone") == None:
print("Rclone executable is missing, install it")`
The problem is that I am not supposed to install any code (including rclone) on the machine. Therefore, whenever I call the shell script, it ends up with the error message. I don't know how can I successfully run it?
The program you are running requires rclone. Since you cannot install it, you cannot run it. Simple as that.
You can try to release the script as a .exe file.
By using pyinstaller (https://pyinstaller.org/) you don't have to install any libs or py package on the target machine, you can even choose to release it as a single executable.
I have made my own Executable from a python script which I want to run on a computer that does not have Python installed on it. My only problem is there are packages I have included which are not default python packages (e.g. pynput). Otherwise, the Executable would run fine without Python installed. Is there a way to include Python packages with my executable? Can I put the packages in the same folder as the script and import them from there? If so, would I then be able to transport them along with my Executable? I have already googled a solution but I cannot find anything on it.
use following method :
pip install pyinstaller
pyinstaller is a package for generating executable files for python and can be ran from command line or terminal
in the same directory of your pyhton file run following command
pyinstaller --onefile nameofyourfile.py
after its done if you check your folder there should be a dist folder
inside that you can find an executable to your python file which has no dependencies to other packages
This is what I get after running the code on cmd:
conda info
I get:
conda version
3.19.3
conda build version
1.19.0
python version:
2.7.11.final.0
Now when I run the code on cmd:
python -V
I get:
python 2.7.11::anaconda 2.5.0(64 bit)
Now when I run a code in .ipynb it works fine, but when I run the code in a .py file it says:
no module named pandas.
What is the source of the problem?
Do I need to install the libraries again for running the .py file?
Anaconda creates a separate folder (C:/Anaconda). Python is installed to C:/Python27. If you are running IDLE (default Python editor) you will need to move it to C:/Anaconda. I suggest moving all the contents of C:/Python27 to C:/Anaconda, merging any common folders.
This answer assumes you are running a python file open in an editor. If this is not the case, try typing python filename.py into the command prompt instead of double-clicking the file.
I can install a python script as an exe file into "scripts" folder on windows.
How can I just create an exe launcher for a script without installing it?
Using 64-bit python, can I create an exe that will work with 32-bit python?
Instead of using setuptools, you can use py2exe to create your executable files.
Just read the tutorial page to understand how to create them.
Install it by typing in your terminal:
pip install py2exe
Create your .exe script (hello.py)
print "hello world!"
Create your setup config script (setup.py)
from distutils.core import setup
import py2exe
setup(console=['hello.py'])
Run your setup script by typing in your terminal
python setup.py py2exe
After that, 2 folders will be created inside the scripts folder.
They'll be called 'dist' and 'build' folder.
Inside the 'dist' folder you'll find an executable of your script.
In our example, we compiled the hello.py file, correct? So, inside the dist folder we should find a hello.exe file.
Q: Also, using 64-bit python, can I create an exe that will work with
32-bit python?
A: No! You'll have to install a 32-bit python and compile using the
32-bit version.
Hint: create a virtual machine to compile your 32-bit programs.
Also you can take a look at:
YT Tutorial
PythonCentral Tutorial
PythonTips Tutorial
StackOverflow Question
I have a Python script I developed within a virtualenv on Windows (Python 2.7).
I would now like to compile it into a single EXE using Py2exe.
I've read and read the docs and stackoverflow, and yet I can't find a simple answer: How do I do this? I tried just installing py2exe (via the downloadable installer), but of course that doesn't work because it uses the system-level python, which doesn't have the dependencies for my script installed. It needs to use the virtualenv - but there doesn't seem to be such an option.
I did manage to get bbfreeze to work, but it outputs a dist folder crammed with files, and I just want a simple EXE file (one file) for my simple script, and I understand Py2Exe can do this.
tl;dr: How do I run Py2Exe within the context of a virtualenv so it correctly imports dependencies?
You can do that this way:
Activate your virtualenv and then ...
easy_install py2exe-0.6.9.win32-py2.7.exe
Installing py2exe into your virtual env should be straightforward. You'll need Visual Studio 2008, the express version should work. Launch a 2008 Command Prompt and Activate your virtual env. Change into the directory that contains the py2exe source and run python setup.py install. You can verify that py2exe is in the correct environment by attempting to import it from an interactive shell. I tested myself earlier today (had to install virtualenv). It works exactly as expected.