Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python, PyInstaller error: no module named "Encodings" and system codec missing

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!

like image 661
Zesa Rex Avatar asked Feb 14 '17 11:02

Zesa Rex


1 Answers

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.
like image 159
A.Sherif Avatar answered Sep 21 '22 07:09

A.Sherif