I've been trying to convert a .py file to a .exe file for 2 days now with no luck. I've gotten the farthest with pyinstaller but went I launch the .exe it closes (import errors). In the warning file it has errors such as
missing module named _scproxy - imported by urllib.request
If you need the entire list I can give it to you but it's over 300 lines. I've tried the following with pyinstaller with no luck
Creating a single file exe
Creating a single directory exe
Removing all path altering code
Creating a exe with the noupx option
Putting just the files I need in a directory and creating it (I had other related files that I thought it might be messing up on)
I am using the following
Windows 7 pro
Python 3.6 Anaconda 5.2.0
VS code (is this relevant?)
My .py file basically runs a pre-made sklearn classifier. The classifier for the .py is in the same directory exported and imported using pickle (file name is clf.pickle). Any help would be appreciated and if you need more info please ask. Thanks.
Related
Im using ACRCloud to recognize an audio file, I've build a GUI using tkinter and I'm freezing the code as an .exe file using PyInstaller. However, I'm getting this error when I'm running the .exe file:
ModuleNotFoundError: No module named 'acrcloud_extr_tool'
If I run it directly from the script, there's no error and it runs fine. Some help, please? I'm just starting out.
From my experience using pyinstaller, I need to add a parameter to the build command, so that pyinstaller knows where to look for modules. If you are building from a command prompt, the line may read something like this:
pyinstaller "yourFileName.py"
However, you can add other commands to this that specify how the exe is built - whether it has a custom icon, is console based or the console is hidden, etc. Additionally, you can add a list of paths, telling pyinstaller where to look for your modules and that's done like this:
pyinstaller -p C:\theFolderWhereYourCustomModulesAreSaved:C:\Users\yourName\AppData\Local\Programs\Python\Python36-32\Lib\site-packages "yourFileName.py"
Notice there are no quotation marks around these file paths AND that they are separated by a colon. The path to your Python site packages may be a bit different than mine, but I left in all the same path info with the exception of my username, so edit that as needed for your own machine. Also, the first 'fake' path I have shown in the example would be if you have written some of your own modules and are importing them into your project. For example, if your main project is saved in C:\myProject but you have modules you've written that are imported into your program like this:
import myCustomModule
and THOSE modules are saved in C:\myProject\myModules, then you would change that command to look like this:
pyinstaller -p C:\myProject\myModules:C:\Users\yourName\AppData\Local\Programs\Python\Python36-32\Lib\site-packages "yourFileName.py"
Hopefully this solves your problem.
I solved it. Turns out due to it being a binary file (of .pyd extension), it had to be added explicitly in the .spec file (read the pyinstaller documentation). I did it and it ran like a charm.
I know people have asked similar question but here I know the issue and manual fix as well but trying to make it fix automatically ..
I am converting a simple Python code to .exe using pyinstaller.
1st approach-
pyinstaller.exe test.py
test.py includes library docx . When the dist folder is created it is missing the docx library from the folder, however I can see lxml is there . I have to manually copy the docx library folder from my Python Lib to the created dist then only the .exe is executing correctly otherwise its throwing error of missing docx.default from template ..
I tried below way as well to create a single file but same issue.
pyinstaller --onefile test.py
Need yours suggestion or fix. Also, if this all can be fixed in a single file that will be great using 2nd approach
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 used pyinstaller to create a single .exe for windows using a single .py file and it worked fine. now i have gotten a bit more complex and have created multiple .py files stored in folders beneath my main.py. i've read through the pyinstaller guides , yet something doesn't seem to be working on my part..
my folder structure in windows is as follows, i'm just using a simple example for illustration :
app_root\main.py
app_root\__init__.py
\library\__init__.py
\library\app_ext1.py
\library\app_ext2.py
\library\test\__init__.py
\library\test\app3.py
in main.py i am importing code from
from library.app_ext1 import get_info
from library.app_ext2 import get_data
from library.test.app3 import get_test
so i run pyinstaller to my main.py using my .spec file.
in the .spec file i have
hiddenimports=['library']
pyinstaller finishes no errors and creates my single .exe, but when i run my single .exe i get the following error
C:\Users\user1\Desktop\1_file\dist>main.exe
Traceback (most recent call last):
File "app_root\main.py", line 2, in <module>
ImportError: No module named 'library'
Failed to execute script main
i wrote a test script just using a single .py file and it was doing some simple work with openpyxl (a python excel library) so in my test .py file i had "import openpyxl" , so in my spec file i used
hiddenimports=['openpyxl']
that worked fine but openpyxl is python lib that was installed using pip , i guess i'm not fully understanding how to import my own modules/scripts that i have created and stored in a folder structure beneath my main .py script file that i'm referencing between my .py script files as in my example above.
how can i make pyinstaller recognize my .py scripts i'm importing?
ok not sure why , but i just created a new folder in windows , copied all my .py files using same folder structure as before and then it worked. the only thing missing was all the Pycharm folders like .git, .idea, and pycache
i did notice in troubleshooting that if i renamed library to something else like "test" and updated my import lines it would still reference module "library" when i executed the .exe that was built.
i knew i was doing all this correctly but seems there might have been something in one of the other folders that py charm puts in there.
so i am just going to copy all my files to new folder each time and delete any folders/files i see other than the .py required.
In my case I replaced from library.app_ext1 import get_info to from your_newly_created_folder_name.library.app_ext1 and it worked :D
I noticed app_root name must be changed with new created folder name. just created a new folder, copy all .py files and keep folder structure. I hope you no one else will waste his time like me on this anymore
I am struggling a lot trying to create a .exe for my Gui originaly coded with opensuse. I am trying to make the .exe for windows (under XP). cx_freeze seems to work better for my case. The build folder is created properly but when I try to run .exe I have the following error :
"proj data directory not found. Expecting it at C:\Python\build\exe.win32-2.7\library.zip\mpl_toolkits\basemap\data "
So do you know how I could do my setup.py in order to copy the folder mpl_toolkits\basemap\data to library.zip?
Here I posted my working solution for the same issue: https://stackoverflow.com/a/26519937/2741329
My fix requires 2 changes:
- Adding the files to include in the cx_freeze setup script
- Adding an OS environment variable in the user script
A similar issue with the same fix was also adressed here by simply adding in the setup file a list of tuple for include_files as [("C:\\Python31\\Lib\\site-packages\\PyQt4\\mpl-data", "mpl-data")]
This is not enough for Basemap since cx_freeze put by default its scripts into a zipped file.