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
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.
https://github.com/taseenuddin/Kobe-Quiz/tree/main
Here are my files, there is no .kv file. My .py file runs on virtual env and pycharm with no problems. My code is pretty atrocious, first time really app developing on python, I just wanted it to work. And yes all dist files and images and music folders were moved to the root directory of my app. Went through tons of fixes and multiple videos but still the exe is not running. And it always says failed to execute script main.py and unable to recreate a playbin.
Here is all of my project files. https://drive.google.com/file/d/1l9oKipKLYnylAMrwmgvAmy_y_o0lfN3H/view?usp=sharing
I caught the error in slow motion using my phone pretty blurry though.
https://drive.google.com/file/d/1D_TwNKxjhMTU1tbTuk05VUGwUP9sZdYy/view?usp=sharing
If anyone can compile the file into a setup format or help me get the exe working that would be an extreme blessing. I have 3 days until my app is due for my ap csp class and I am quite literally shitting myself because I've been trying to find my issue for the last two days and I can't reach my Professor over the spring break.
edit: Btw I am using Python 3.7.1 other versions had issues with Kivy
I have created python desktop software. Now I want to market that as a product. But my problem is, anyone can decompile my exe file and they will get the actual code.
So is there any way to encrypt my code and convert it to exe before deployment. I have tried different ways.
But nothing is working. Is there any way to do that?.Thanks in advance
This link has most of the info you need.
But since links are discouraged here:
There is py2exe, which compiles your code into an .exe file, but afaik it's not difficult to reverse-engineer the code from the exe file.
You can of course make your code more difficult to understand. Rename your classes, functions to be non-sensical (e.g. rename print(s) to delete(s) or to a()) people will have a difficult time then.
You can also avoid all of that by using SaaS (Software as a Service), where you can host your code online on a server and get paid by people using it.
Or consider open-sourcing it :)
You can install pyinstaller per pip install pyinstaller (make sure to also add it to your environment variables) and then open shell in the folder where your file is (shift+right-click somewhere where no file is and "open PowerShell here") and the do "pyinstaller --onefile YOUR_FILE".
If there will be created a dist folder, take out the exe file and delete the build folder and the .spec I think it is.
And there you go with your standalone exe File.
I have used several tools (pyinstaller, cx_Freeze, py2exe) to convert my .py file to .exe file. But with each one of these, the resultant .exe file closes as soon as it runs. Here is a screenshot of the exe file created form pyinstaller.
I have looked at several answers on SO and other platforms but haven't been able to find a solution. Any help would be greatly appreciated.
My apologies for not being able to type these traccebacks out here as I had to take a quick screenshot as the window closed in a second.
The .py file runs fine on its own; there's no issue with the code.
I had this problem about a year ago with pyinstaller and this 2 methods helped me:
Adding import pkg_resources.py2_warn to my script
Using --onedir instead of --onefile
You can also do it using cmd:
pip install pyinstaller
cd followed by the location where your Python script is stored
so an example is:
cd C:\Users\Ron\Desktop\MyPython
then:
pyinstaller --onefile pythonScriptName.py
instead of pythonscriptname.py, put in your python file name.
When you do this there should be a new file called dist in your directory. Wait for a few mins and there should be an .exe file in there.
Here's a temporay solution: I removed all imports related to the googleapiclient for google docs. The .py file gets compiled properly after that.
More Context: There seems to be some issue in this particular library library that causes issues. I have tested the given solutions, they don't seem to work for me. I'll update this answer if I find a "permanent" solution.
I'm trying to run pyinstaller in python exe file in order to someone without python can use pyinstaller but no idea how to do it.
I tried import PyInstaller with other needed modules and convert this script to exe but I got error "The 'PyInstaller' distribution was not found and is required by the application". I also tried to pack PyInstaller exe file but didn't worked too. Python 3.6.5
Any ideas how to do it?
Unfortunately, what you're describing is not possible with PyInstaller. I submitted an issue on GitHub, and this is what one of the developers said:
Nope, this won't work.
PyInstaller internally uses a lot of sub-processes where it is assumed that sys.executable points to a python interpreter (e.g., here); this is not true in a frozen application, where it points to the frozen executable, which ends up in effectively endless recursion.
Even if this was not a problem, the frozen application includes only a subset of python environment, so it cannot be used to freeze an arbitrary script (not to mention the issue of 3rd party packages).
So whatever use case you have for this, it cannot be supported by PyInstaller.
check the requirements for the Pyinstaller from this link initially
https://pythonhosted.org/PyInstaller/requirements.html
Then install Pyinstaller by,
pip install pyinstaller
To create .exe file use this command for basically,
pyinstaller your_script.py
To run the created .exe
METHOD 1
Do double click the .exe file in your directory.
METHOD 2
In your cmd prompt load in to your current directory or project directory then do
: .\dist\your_script.exe
because the create .exe files are saved in dist folder inside to the project folder with the name of your script file names only.