I am using Python 3.3.3 and I have been trying to build a .exe from a simple .py script.
My script looks like this:
import encodings
print('Test')
and executes correctly.
When I try to build it with PyInstaller with this command:
pyinstaller --onefile Testmodul.py
and try to open my .exe it shows up with this error:
Fatal Python error: Py_Initialize: unable to load the file system codec, ImportError: No module named 'encodings'
I already tried importing the 'encodings' module in my testscript but it is still not working, I have also tried py2exe and it is also not working at all.
Is there anything I do wrong? Do I have to setup something in my PATH? the correct path to "C:\Python33" is included in there already.
EDIT: To everyone with this problem: I gave up, and after a fresh install of windows and python and all the other stuff, I tried it again, the same way as before and it worked without a problem.. It is worth a try if you are really desperate!
This is probably because pyinstaller did not include the module in the first place. Try one of the following solutions.
1) Specify the path to your module during compilation:
pyinstaller --onefile --paths=/path/to/module Testscript.py
2) Specify the path from the .spec file:
run this command first(in pyinstaller's directory):
python Makespec.py --onefile /path/to/yourscript.py
now you have the .spec file. open it in your text editor, and add the path to your modules to the pathex.
pathex=['C:\\path\\to\\module']
then, build your program:
python Build.py /path/to/yourscript.spec
3) Use hidden imports:
pyinstaller --onefile --hidden-import=modulename Testscript.py
you can also specify hidden-import in the .spec file.
Add hook file with name hook-encodings.py to C:\Python\Lib\site-packages\PyInstaller\hooks location and add following line of code to collect encodings module in hook file
from PyInstaller.utils.hooks import collect_submodules
hiddenimports = collect_submodules('encodings')
this may work,
this answer might help you Pyinstaller Error for Djnago project "ImportError: No module named 'django.contrib.admin.apps'"
Which windows version are you using (7 or 10) ?
This issue seems to be relative to user privilege ... and assuming it is similar to this issue, you may first try to run your exe file with administrator privilege, and if it is failling again, try to run "Pyinstaller" from a cmd.exe running with administrator right.
Related
I'm somewhat new to python, so it would be nice if this was explained simply, if you can.
I'm trying to make a py file (main.py) into a exe file. I've followed this tutorial (https://www.geeksforgeeks.org/convert-python-script-to-exe-file/) as well as a youtube one, which did the same thing. My project has several modules. The conversion works, but if I try to open it, it tells me: (ModuleNotFoundError: No module named 'requests'). I would assume it does this for the rest of them if it gets the chance to. I don't know how to fix this and it would be nice if I could have a exe file so I could share programs with friends that don't have python installed. (I'm using pyinstaller for the process, same as the tutorial)
requests is a 3rd party library. I assume when you created the .exe, you did not "assembled" together your script with its dependencies.
According to the linked tutorial, you should check the pyinstaller's config and try to give pyinstaller the missing packages and somehow compile it with them, e.g.
For any missing package:
pyinstaller --hidden-import 'package_name' --onefile 'filename.py'
Just install requests:
pip install requests
Then you'll be able to bundle the script into an exe, provided there aren't any other missing dependencies.
According to your question either the requests module isn't installed or pyinstaller can't find the module!
If module isn't Installed then open up your terminal/Command Prompt and execute the follow command:
pip install requests
But if module is installed then what you can do is manually specify Pyinstaller which module to include also
so to compile it to exe use this command
pyinstaller --hidden-import 'requests' --onefile 'main.py'
Here the option --hidden-import means it will import the module requests also and --onefile means it you will get a single Exe file which will contain everything
Note! if you use --onefile this can effect your time taken to start your program!
Thanks
Edit:
According to the tutorial it shows you to open "PowerShell" but I recommend you to use "CMD" for this purpose!
I am trying to compile a python script into an executable using pyinstaller --onefile. However, one necessary package, geemap, doesn't seem to be included, despite being an import in the script.
Is it possible to force-add custom packages?
Every time I run the .pyc file on a clean PC, it says:
ModuleNotFoundError: No Module named 'geemap'
You could try:
pyinstaller --onefile --hidden-import=geemap
This should force-add the package.
So I have a program and whenever I start it from the command line it works totally fine. What I need now is an Executable and therefor I tried to do it with pyinstaller, which analyzes normally automatically which modules have been imported and it works fine with all of the modules except for autoit. The way I import it looks like that:
import autoit
So I tried to make an executable by following command:
pyinstaller --onefile ./rocketupload.py
Which gave me this Error (Excuse me, that I have to make a screenshot, but the window was open for a second and closed immediately afterwards, so I was not able to copy and paste it here):
I was able to create a functioning exe by copying the autoit dll to the path mentioned in the Error, but that is just a temporary solution, since I want the executable to be running not only on my PC.
I've also tried this one without succes:
pyinstaller --hidden-import=autoit --onefile --paths c:\users\semjo\appdata\local\programs\python\python37\lib\site-packages\autoit\lib .\rocketupload.py
So the problem here is that the autoit module does not get copied from pyinstaller so It cannot run the executable as inteded. But I dont know how to solve it, so that the exe can run as intended. Hope you can help me here, tried to find a solution for hours now...
I had also encountered the same problem and i solved it by implementing the follows:-
Re-installed the pyinstaller module using the latest installer available in github i.e. pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
Re-created the executable package by running the command i.e. pyinstaller --hidden-import=selenium --hidden-import=autoit your [python_file.py]
Copied the installed module i.e. autoit's folder from my PC's directory (C:\Users\\AppData\Local\Programs\Python\Python37\Lib\site-packages) and pasted it inside the [python_file] folder in dist folder which was generated by pyinstaller.
To test the solution, i re-run the generated .exe file in command prompt. Hope this help.
hiddenimports = [ "autoit.init", "autoit.autoit", "autoit.control",
"autoit.process", "autoit.win" ]
datas = [
[
"C:\\Python27\\lib\\site-packages\\autoit\\lib\\AutoItX3_x64.dll",
"autoit\\lib"
]
]
https://raveendran.wordpress.com/2012/06/15/how-to-installregister-autoitx3-dll/
Do this two process your issue will resolve. It resolved me.
Good day, I've been trying to turn a .py script to a .exe, I've run the following command: "python pyinstaller.py EyeBreak.py" in cmd and got an error: ImportError: no module named wintypes, looking at the questions on SO I downloaded the .dll file and placed it in the same folder as pyinstaller, but i still get the same error. How can I fix this? Is there a better way to turn a .py to a .exe?
Here is my code if relevant: https://github.com/Faresalghazy/EyeBreak/blob/master/eyebreak.py
I compiled a simple python module using py2exe. It works fine for me when I run the executable through the cmd window, but when I give it to someone without Python installed, they get the following error message:
LoadLibrary(pythondll) failedThe specified module could not be found. C:\PYTHON27.DLL
How do I resolve this issue?
Py2exe doesn't actually create one single executable. You have to include the dlls and other files in the folder.