I want to make an executable file which will extract multiple files into a specific location.
I've read about the 'extractall()' function, and using unzip, but how do I contain the multiple files inside the executable python file, so each time the user double click the exe file, it will extract these files into the hard coded location?
Be aware that your archive will be (in most part) platform-specific -- it may not work on Windows if you make it on a Unix-like machine and vice versa, etc.
I would recommend that you check this pymakeself which is a pypi https://pypi.python.org/pypi/pymakeself
In fact, you may find the following codes immediately relevant.
Self Extracting Archiver (Python recipe): http://code.activestate.com/recipes/577485-self-extracting-archiver/
Build a compressed self-extracting executable script on UNIX (Python recipe): http://code.activestate.com/recipes/497000-build-a-compressed-self-extracting-executable-scri/
Related
I've made a nsis installer for my application and want to change one of the files inside the installer .exe. Is there a way to open the installer and change one of the files inside, similar to ZipFile?
The reason for doing this is I want to add a unique token so I can later identify which user has downloaded the app. Generating a new installer from scratch with the token inside would be too slow.
No, you cannot change files inside the installer.
What you can do however is to append some text to the end of the exe on the server and then read it in the installer.
If you have a lot of data, you can append it in a .cab file and use the CabX plug-in (CabX::FromSelf).
I am working on a python project that depends on some other files. It all works fine while testing. However, I want the program to run on start up. The working directory for programs that run on start up seems to be C:Windows\system32. When installing a program, it usually asks where to install it and no matter where you put it, if it runs on start up, it knows where its files are located. How do they achieve that? Also, how to achieve the same thing in python?
First of all, what do you mean by "their files"? Windows applications can store "their files" in multiple places (including but not limited to %CommonProgramFiles%, %ProgramData% and %AppData%).
That being said, the common location for simple applications and scripts is to use the same directory as the .exe (or script).
In Python there seems to be multiple ways to find this path, this seems to work nicely:
import os
print(os.path.abspath(os.path.dirname(__file__)))
See also:
How do I get the path of the Python script I am running in?
How do I get the path and name of the file that is currently executing?
If you plan to consume local files that contain raw data or processed data, defining a default directory or a set of directories can simplify your implementation, for example:
Place your data files under a specific set of folders in C:\ or place your files under the F:\ folder, that can be a part of your on premisses file system
Based on where your Python application is located, you'll need to use relative paths or a library to help you to locate these files.
Here are some examples:
os.path
pathlib
I'm unfamiliar with the terminology used for linking files into executables as they are compiled.
I want to write a Python script that extracts .icos from Windows executables that are viewable when you make file associations inside Folder Options. These are simply linked into the executable file upon compilation.
Then the script would sort the .ico files into individual folders based on their origin (it's supposed to extract all from subfolders/recursively) and even tell the difference between recently installed files and files that were left there previously.
Is there a library available that does such? Would I have to use a Python "Windows unlinker" or could I have it scan through RC resources too? Would there at least be a .DLL I can access with Python that does so?
I don't mean to compile code and interpreter as an exe as it is 99% questions there. I mean to build a static single python.exe to be able to execute any script by giving it as argument any *.py file.
I mean the same situation as it is with nodeJS when you download only single executable.
Or if it is not possible to single exe, maybe to just a few files instead of huge default package such as is with for example Sublime text where all python engine is in python33.dll and python3.3.zip all about 5mb, but there is no python exe to run code externally that is not as a plugin.
On Windows you need three files. You question lists two of them. The third is python.exe. On Windows the interpreter must be built separately from the actual executable so that C modules can access the functions within the interpreter.
The DLL must be built from the Python source so that all the C modules that come with Python can be built into it instead of being contained in the .pyd files that come with Python. The zip file is composed of all the Python modules in the standard library; see the zipimport documentation for more information about the import process.
The setuptools installer for Windows 7 x86 is named an exe file, but can be opened as a zip file. When I peek into it, there are two top level folders: PURELIB and SCRIPTS. What are these, and how is it that when I double click on this exe, Windows runs it for me, although it's a zip file? That is, how does Windows know what to run inside this zip/exe? Thanks.
It's a self-extracting archive.
A self-extracting archive is a computer application which contains a
file archive, as well as programming to extract this information. Such
file archives do not require a second executable file or program to
extract from the archive, as archive files usually require. The files
in an archive can thus be extracted by anyone, whether they possess
the appropriate decompression program or not, as long as the program
can run on their computer platform.
It is an executable, it's just that your extraction software knows to look for self-extracting archives, and treats it as a normal archive.
What are these, and how is it that when I double click on this exe,
Windows runs it for me, although it's a zip file?
From http://zziplib.sourceforge.net/sfx-make.html
The basic scheme goes like this: the final file will have an EXE
starting at offset null, followed by the data entries of a ZIP
archive. The last part of the ZIP archive is the ZIP central-directory
which ends at the end of the file.
The magic is possible because exe format allows any data to be appended to the executable and zip format allows any data to be prepended to the archive.