I'm trying to use pyinstaller with python version 2.7 to make a standalone file that will run a small app I made using tkinter, but I'm having trouble following the documentation. I found this, but it's for python 2.5 and windows
http://www.pyinstaller.org/export/v2.0/project/doc/Manual.html?format=raw#spec-files
I made two folders on my desktop, one for pyinstaller and one containing my files.
In terminal I changed the directory to the pyinstaller folder. Then I typed the following:
python pyinstaller.py /Users/.../Desktop/BuildFolder/menu.py
//buildfolder contains my files, menu.py is the file I run to start the app
When this runs, I get a message staing something along the lines of "The output directory and all of its contents will be removed. Proceed y/n?" Upon selecing yes, It then creates the directory
/Users/.../Desktop/pyinstaller-2.0/menu
Inside that menu folder, there's a .SPEC file. So, I run the following in terminal
python pyinstaller.py /Users/.../Desktop/BuildFolder/menu/menu.spec
After this runs, I found a .PKG file in that folder but it's not labeled anything like menu.py . I can't figure out what to do next, and I'm not sure if I'm supposed to run other files.
I am not sure ( haven't tried this yet ), but maybe you have to run Build.py while working with .SPEC file?
Related
I've seen this post about a similar problem but I dont understand the solution. And I am using python 3 the other person is using python2
Link to post: Making a standalone .exe file of a python script
I made a python exe that uses multiple files.
When all the files are in one directory the exe works.
Now i put some order in my directory.
E.G. making a source folder where my sources are
making a script folder where my scripts are
Using an IDE the scripts still run, so the relations aren't wrong.
my directories look like this:
"main
main.py
sources
sources.py
buttons.py
scripts
scripts.py"
I converted main.py to exe with pyinstaller
I made an error. Went to far up the tree to find the spoken of files.
I want to create a single executable from my Python project which uses tkinter. A user should be able to download and run it without needing Python installed. What can I use to build a self-contained executable from a Python project?
my question is somewhat similar to this one but I didn't find what I was looking for there.
I have a folder which looks like this:
-project/
-script.py
-res/
-image1.jpg
-image2.jpg
-image3.jpg
In my script.py I am using the images from the res folder in my tkinter UI and I want to create an executable out of this script. what would be the best way to tackle this problem?
You can try using PyInstaller
PyInstaller - How to convert to .exe
1. Installation
The pyinstaller module makes you able to create a standalone exe file for pc from a python script, so that you can use it on other computers than do not have python or your python version.
To install pyinstaller: pip install
2. Create an exe
After you installed pyinstaller, go in the folder where your python script to be transformed in exe is and type in the command line (go in the address bar on top of the window and type cmd). Then type :
pyinstaller yourscript.py
where your script is the name of your file.
You will find a folder called “dist” where there is a folder called yourscript (if the name of your script was this) where there are many files and the exe file that will allow you to run the script also on other computer. You just have to copy the whole folder.
3. What to do if there are images
If you use images, that are in the same folder, for example, you can copy manually into the folder made by pyinstaller or you can run this command to make it do it for you:
pyinstaller –add-data “*.png;.” yourscript.py
This way you will see that in the folder where your exe is there are also the png files (all of them, if you want just one do not put the asterisc, but the whole name of the file.
External links - PyInstaller
Use a bundler like Pyinstaller.
Pyinstaller website
Include images in Pyinstaller
Note: If you are having issues with tkinter and pyinstaller take a look at this: Problems with Pyinstaller with tkinter app on python 3.5
I developed my code using PyCharm and am using PyInstaller to create a desktop .exe application. I am able to create the application, however, my current method requires navigating multiple directories, and to copy/paste some file dependencies. The whole reason to use PyInstaller was to make it more user-friendly, and easy to access the file dependencies. My question is, how should my code be organized so that a general user can easily access the file dependencies, and developer not need to copy/paste the dependency?
Below is my generalized current approach and the result.
To develop using PyCharm, edit:
/projectFolder/main.py,
/projectFolder/helper.py,
/projectFolder/data.xlsx
To create application using PyInstaller:
in command prompt, /projectFolder/venv/Scripts, execute pyinstaller ../../main.py
This creates projectFolder/venv/Scripts/dist/main/main.exe, among many more files (generated by PyInstaller) that the user shouldn't interact with or even see.
At this point, I need to copy/paste /projectFolder/data.xlsx into /projectFolder/venv/Scripts/dist/main for the .exe application to function.
The executable is now ready to be used.
I am looking for a better approach, where the user will see only the relevant files, main.exe and data.xlsx (since this will be modified, periodically). Also, I'd like data.xlsx need not be copy/pasted.
Again, how should I organize my code / package the distribution in order to simplify things for the user?
You can add files or even a folder to install with PyInstaller by using the command --add-data. The documentation explains the format for the file / folder to add but in your case it should be:
pyinstaller --add-data "data.xlsx;." main.py
Now your 'data.xlsx' will automatically copied and pasted into the folder with your .exe file.
PyInstaller also has a feature to compress all your files into one single .exe (including added data) and then when you run your program, it creates a temporary folder in your OS temp folder, usually C:\Users\USERNAME\AppData\Local\Temp\ that starts with _MEIxxxxx where the xxxx is a randomly generated number so your exe programs wont interfer with each other if more than one is running at a time. The folder is automatically deleted upon successful exit of the program.
The code to have only one file instead of a folder:
pyinstaller --onefile --add-data "data.xlsx;." main.py
There are 2 issues with having one file instead of a folder. The first isn't too big of a problem, but everytime your program crashes or doesn't close properly, the temp folder _MEIxxxxx where all your program was unloaded to wont get deleted, potentially clogging up their system. A simple fix would be to add some extra code into your program that checks if there is already a _MEIxxxxx folder with an older date/time in their temp folder and delete it.
The second is that if your program requires to read / write to a file, the code will check in the current directory of the exe, not the temp folder that is created. A workaround to this would be to write some extra code that looks for the a folder that starts with _MEI in their temp and uses that as the path. If it finds more than one folder with _MEI it should take the most recent (and hopefully delete the older ones)
Another cool feature is adding the --runtime-tmpdir command to your pyinstaller which allows you to specify the where you want your _MEIxxxxx to unload, potentially making it easier to check where the data and files you need to run the program.
pyinstaller --onefile --runtime-tmpdir "C:\TemporaryFolder" --add-data "data.xlsx;." main.py
Unfortunately, if you specify a folder or a path that doesn't exit your program wont work at all, so I would recommend creating a separate setup.exe that creates that folder for them and that should be run before running the main.exe file. Afterwards they can delete the setup file and their program should be running.
I am a total noob when it comes to this, but I have been tasked to package several Python files into one .exe file.
I tried doing this with PyInstaller and I realized that I wasn't able to import opencv at first. Sure enough, I pasted a copy of cv2.pyd into the site packages folder and that was corrected. I tried building it again but it still doesn't work.
The command I use is: pyinstaller --onedir C:\Users\ -- Directory of Python file The file I'm using is the main one, that makes the program run. I thought PyInstaller would have scanned this file and find the other imported files.
I'm not sure how to add the other files. The documentation on the PyInstaller website isn't super clear to me.
More Info: Application consists of a GUI with 5 Python files in total
Application packages but doesn't run (Command Window blips and goes away)
Any suggestions?
Thanks a million - Matt
I have watched numerous tutorials on how to run Python files using the windows command line (CMD.exe), but in all of the tutorials the video makers were accessing PythonXX from Program Files and also their Python files from Program Files. I use Pycharm and have my single Project Folder in my Documents library. If possible I would like to run those files from the project folder. If not, though, is there any way to relocate a Pycharm Project Folder and Pycharm will still recognize it as where I store my files?
Thanks!
EDIT:
YES, I am aware that I can run my Python Files in Pycharm, but I would like to use windows CMD for full screen and so I can watch over it while I code.
To get to a directory with cmd simply hold shift while right-clicking the Documents folder. You should get an option
Open command window here
To run python files, enter into cmd:
python filename.py
Modify this command to include arguments if necessary.