Is there anyway the pyc file can be extracted from an Application bundle? I'm referring to an application bundle that was created by using py2app on python code.
The pyc files are stored in a zipfile in the Resources folder. The name of the zip file depends on the Python version, for 2.7 it is .app/Contents/Resources/python2.7/site-packages.zip.
That zip file is a regular zipfile that can be manipulated with the usual tools.
Related
I have a c++ file and a python file.
I can turn both of these to .exe files. But I can't turn them into .app files.
I am using the pyinstaller module for python files.
How can I turn the files into .app files?
As per PyInstaller's documentation, you can use it also to build a mac application. However, you would have to build it from Mac OS.
https://pyinstaller.readthedocs.io/en/stable/usage.html#building-mac-os-x-app-bundles
A rookie question here:
I have a PY code and compiled it to create a .pyc. I would want to use this pyc file instead of PY.
I am running the PY file using external program. When the PY exists in the folder everything works perfect. However when I remove the PY file and simply use the pyc I get error:
IOError: [Errno 2] No such file or directory: 'E:/data/test/tech.py'
Whereas I have a tech.pyc lying around in the same folder.Any ideas what could be the issue here?
Normally, python is not compiled. The .pyc files are only a performance optimization that improve loading times.
Python is looking for the .py file because it always checks that first. If a .pyc file is newer than its corresponding .py file, it will then use the .pyc file. If the .py file is newer it will create a new .pyc file.
This might be a weird requirement but it's what I've run into. I Googled but yield nothing.
I'm coding an application who's using a lot of constant attributes / values recorded in an XML file (they'll not change so a static file), things work fine until I generated an egg file for it.
When the logic reaches the XML accessing part, I got one complaint like this:
/home/Workspace/my_proj/dist/mps-1.2.0_M2-py2.6.egg/mps/par/client/syntax/syntax.xml
Actually I've bundled the XML file in the path above but seems Python doesn't know how to access it.
The code to access the XML is as...
file_handler = open(path_to_the_file)
lines = file_handler.read().splitlines()
Any idea?
egg files are zipfiles, so you must access "stuff" inside them with the zipfile module of the Python standard libraries, not with the built-in open function!
If you want to access the contents inside the .egg file you can simply rename it and change extension from .egg to .zip and than unzip it.
Which will create a folder and the contents will be same as they were when it was a .egg file
for example brewer2mpl-1.4.1-py3.6.egg
After Renaming brewer2mpl-1.4.1-py3.6.zip
Now if we open it, it'll get easily unzipped and the content will be put in a folder with same name in the same directory.
(tested on macOS Sierra)
The less command on *nix systems can peek inside zip files. Therefore less some.egg will list the contents of a .egg file too.
Just run unzip file.egg
You can install unzip on Debian/Ubuntu with
sudo apt install unzip
or on macOS by installing Homebrew then
brew install unzip
Access file from inside egg file
Yes, It is possible to read the files from inside egg file.
Egg file: mps-1.2.0_M2-py2.6.egg structure for module level example:
In driverfile.py:
import xml.etree.ElementTree
import mps.par.client as syntaxpath
import os
path = os.path.dirname(syntaxpath.__file__)
element = xml.etree.ElementTree.parse(path+'\\syntax\\syntax.xml').getroot()
print(element)
Read xml file from inside an eggfile:
PYTHONPATH=mps-1.2.0_M2-py2.6.egg python driverfile.py
i think by default eggs packing file under python won't add your xml inside to the pack
I'm using cx_Freeze to freeze my python program. On running cx_Freeze, a bunch of PYD files are created, a whole bunch of PYC files are put into a archive named library.zip and a few DLL files are there too.
Could someone tell me the difference between the PYC and the PYD files?
What's the reason for the PYD files not in the library.zip?
Is it possible to put the PYD files into the archive as well?
Thanks.
Disclaimer: I haven't used cx_Freeze in awhile......
.PYD files are DLL machine-code files that contain specific python-required functions.
.PYC files are .py files that have been compiled into bytecode.
so PYDs are machine code and PYCs are bytecode
Now as for why the PYDs aren't in the .zip....I'd imagine it's because those .PYDs are needed by the python interpreter to run the program. What cx_Freeze does is basically this:
compile all .py files and throw the .pyc files in a zip
put all needed .pyd files in the zip
create a stub .py file and put it in the output directory
copy the python.exe and rename to myprogram.exe
copy all .pyd files needed to open the .zip and run the contents
So you're not actually compiling your python file, you're instead renaming the interpeter and freezing all the source files.
I hope this helps.
I'm using cx_freeze to freeze a Python script for distribution to other windows systems. I did everything as instructed and cx_freeze generated a build\exe.win32-2.6 folder in the folder containing my sources. This directory now contains a a bunch of PYD files, a library.zip file, the python DLL file and the main executable. Which of these files would I need to distribute? Any help, guys?
Thanks in advance.
You need all of them.