how to tranfrom python3 program into exe file totally? [duplicate] - python

This question already has answers here:
Python 3 project into exe?
(3 answers)
Closed 9 years ago.
I have heard py2exe,but it doesn't support python3 now.So I found cxfreeze,but there is an problem that the extension lib are in a zip file,but one extension must use a txt file.The extension would figure out the txt file address,which in the zip file.Windows throw out an error of 'FileNotFoundError'.The problem nearly drive me mad.It can't open file that compressed in zip.I am begging for your help...

Reposting as an answer:
Programs that load data files may need to be modified a bit if they're looking for the data files adjacent to Python modules, because cx_Freeze puts the Python modules into a zip file. Depending on your use case, you could load the data from the zip file (using the zipfile module), or load it from a regular file alongside the exe. The cx_Freeze FAQ has an example of how to do the latter.
Another option, especially for small pieces of data, is to embed it in Python code so it's in a frozen module. Qt's resource system works like this.

Related

Is there a way to run Python code without downloading Python? [duplicate]

This question already has answers here:
How can I convert a .py to .exe for Python?
(8 answers)
Closed 1 year ago.
My internship has asked me to make my code executable for people who do not have Python downloaded. I can run parts of it on online Python compilers, but it uses different libraries that are not supported on those compilers. My program opens a .csv file specified by the user and filters it and writes the new data to a new .csv file. To implement the code online, I think I would need to learn JavaScript? Is there any other alternative? I appreciate any guidance provided!
You can create a standalone executable that includes your python script + all necessary files to run it. The users then just run ".exe" file without need to download and setup python environment. A great library to do it is cx-freeze
There is many online python runner. Example https://www.programiz.com/python-programming/online-compiler/

Opening PYD files with 7zip [duplicate]

This question already has answers here:
how to edit dll archives?
(1 answer)
Is it possible to decompile a .dll/.pyd file to extract Python Source Code?
(2 answers)
Closed 2 years ago.
I'm trying to get the source code of a python program and have come to realize that is it likely Cython due to a ton of *.pyd files in the library.zip. I don't have experience with these; however I have noticed I can open this .pyd file in 7zip giving me the following files:
my question is can any of these be decompiled into a python source? I cannot find anything regarding actually opening the PYD file with 7zip - there is a general thread about decompiling however it never mentions anywhere about the files found when you open it with 7zip.

extract 7z file using python 3 [duplicate]

This question already has answers here:
Python3: lzma unpack .7z file
(3 answers)
Closed 3 years ago.
I was trying to decompress a 7z file using python, but I can't seem to figure it out. I figured I could use the lzma module in python 3, but I can't seem to figure it out:
I thought it would work like the zipfile package:
import lzma
with lzma.open('data.7z') as f:
f.extractall(r"<output path>")
but after reading the documents, it doesn't seems to. So here is my question: How can you extract a 7z file using the standard package? I don't want to call subprocess to extract the files using 7-zip because I can't guarantee that users have this software installed.
I've searched the internets and stack oerflow and noticed all the answers almost go back to using subprocessing which I would like to avoid like the plague.
Though there are similar questions on stackoverflow, the answers all still depend on 7-zip or the 7zip SDK. I do not want to use the 7-zip sdk/exe for extraction because that assumes the users have the software installed.
Here is the properties from the 7z file:
What about trying this?:
from pyunpack import Archive
Archive('data.7z').extractall("<output path>")

File extension validation with python [duplicate]

This question already has answers here:
How to check type of files without extensions? [duplicate]
(10 answers)
Closed 9 years ago.
I want to check if a given file's extension is correct or not. For example, someone give me a file with an extension .zip but actually it may be an executable.
Using mimetypes I could not determine a file's real type. As far as I see, mimetypes needs an extension.
I can map the output of unix file command with some extensions. Even if you change the extension, you cannot deceive file command. However, this solution needs a subprocess.
I thought, there may be a more pythonic solution of this problem. Does anyone know?
Searching the name of the C library (libmagic) used for the file command, nets 3 interesting python packages on PyPI:
libmagic (bitbucket repo)
python-magic (you can find some documentation in the github repo)
filemagic (github repo)
Ultimately, there is no absolute way of knowing. For several reasons:
Some file format use simple identifiers, but others don't.
For those that don't, the only way is analyzing the behavior of a program able to able the format. If the program can successfully open the file, then it belongs to it.
But if not, the file could belong to hundreds of formats you don't have a program to open with.
I'm afraid you will need to be content with a partial answer like the ones you already have.

Distributing an executable zip file with __main__.py, how to access extra data? [duplicate]

This question already has answers here:
python: can executable zip files include data files?
(4 answers)
Closed 7 years ago.
I'm doing a little program and I want to distribute it using this recipe:
single directory with __main__.py in it
zip this directory and adding a shebang on it #!/usr/bin/env python
making it executable
The problem is that in this package I have also extra files (I'm using pygtk toolkit and I need images and ui xml files). When I try to access these files I have the error that the resource is unavailable (the path that I'm trying to open is something like file.zip/gui/gui.ui ).
How can I handle this situation?
I figured out by myself, It's sufficient to use pkgutil.get_data to access the data inside a package.

Categories

Resources