Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding #835

Closed
LaurentBerder opened this issue Dec 17, 2020 · 20 comments

Comments

@LaurentBerder
Copy link

Hi,

I'm working under Windows 10 in Python 3.9.0 (native, no Anaconda or anything), with cx_Freeze 6.4.2

Whenever I use cx_Freeze, the processes goes through without issues, but I can't run the exe, with this error:

Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = (not set)
  program name = 'G:\src\Application\build\exe.win-amd64-3.9\my_app.exe'
  isolated = 0
  environment = 0
  user site = 1
  import site = 0
  sys._base_executable = 'G:\\src\\Application\\build\\exe.win-amd64-3.9\\my_app.exe'
  sys.base_prefix = ''
  sys.base_exec_prefix = ''
  sys.platlibdir = 'lib'
  sys.executable = 'G:\\src\\Application\\build\\exe.win-amd64-3.9\\my_app.exe'
  sys.prefix = ''
  sys.exec_prefix = ''
  sys.path = [
    'G:\\src\\Application\\build\\exe.win-amd64-3.9\\lib\\library.zip',
    'G:\\src\\Application\\build\\exe.win-amd64-3.9\\lib',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00001330 (most recent call first):
<no Python frame>

This is the content of my setup.py file:

from cx_Freeze import setup, Executable

exe = Executable(
   script = "application_demo.py", # the name of your main python script goes here 
   initScript = None,
   base = None, # if creating a GUI instead of a console app, type "Win32GUI"
   targetName = "my_app.exe"
)

setup(
    name="Autonomie",
    version="1.0",
    description="Assistance à l'autonomie",
    executables = [exe],
    options = {"build_exe": {"packages": ['PyQt5', 'pyqtlet', 'pandas', 'numpy'],
                             "includes": ['os', 'sys', 'encodings', 'requests', 'random']
                             }}
)

The G:/ drive is a my Google Drive (synched with Drive File Stream).

It seems (right of the bat) like PYTHONHOME and PYTHONPATH do not get found, but I'm not sure whether I should specify this myself.

What's causing this, and how could I solve it?

@LaurentBerder
Copy link
Author

LaurentBerder commented Dec 17, 2020

@marcelotduarte suggested to me the problem might be with the G: drive, so I tried copying my whole folder on the desktop (on my C: drive), and re-running cx_Freeze then running the application, but it caused the same issue.

@marcelotduarte
Copy link
Owner

Can you copy the source to C: (local drive) only to test. I suspect that is a network issue (not with your network, but in the frozen app).
Maybe only copying the executable to C it runs....

@LaurentBerder
Copy link
Author

Can you copy the source to C: (local drive) only to test. I suspect that is a network issue (not with your network, but in the frozen app).
Maybe only copying the executable to C it runs....

You're really fast! I thought I'd beat you to that with my previous comment...

@marcelotduarte
Copy link
Owner

Take a look at #767, it is about pyside2 but has some comments...
Can you test the sample of PyQt5 if it runs on your system?
https://github.com/marcelotduarte/cx_Freeze/tree/master/cx_Freeze/samples/PyQt5

@LaurentBerder
Copy link
Author

Take a look at #767, it is about pyside2 but has some comments...
Can you test the sample of PyQt5 if it runs on your system?
https://github.com/marcelotduarte/cx_Freeze/tree/master/cx_Freeze/samples/PyQt5

The sample PyQt5 does the same results:

Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00003f5c (most recent call first):
<no Python frame>

I'm not sure I understand what part of #767 you mean I should follow. Is it the copying of DLLs?

@marcelotduarte
Copy link
Owner

I haven't tested this pyqt5 sample on windows with py39 yet, then I'll take a look to see if I can find anything ....

I'm not sure I understand what part of #767 you mean I should follow. Is it the copying of DLLs?

about network shares.
Sometimes I saw this error in linux was when the person had compiled the python from the sources and there was a missing link or shared library. Now on windows, I have to investigate ...

@LaurentBerder
Copy link
Author

LaurentBerder commented Dec 17, 2020

OK, thanks for your time.
It's the first time I'm using cx_Freeze, was expecting it to work straight away. I felt dumb that it didn't.

about network shares.
Sometimes I saw this error in linux was when the person had compiled the python from the sources and there was a missing link or shared library. Now on windows, I have to investigate ...

I haven't done any compiling from source, and I'm not either using a virtualenv (working off my main python).

@klensy
Copy link
Contributor

klensy commented Dec 18, 2020

Looking at sys.path, it's looks like not default path, maybe python 3.9 issue. Can you try build with python 3.8 on local disk (without network share)?

@LaurentBerder
Copy link
Author

Had to do it on another computer (only had the one version of python installed on that one).
I'm now running on Windows 10, python 3.7.1.

Now the issue I get when I launch the app after freezing it is
ModuleNotFoundError: No module named 'PyQt5.QtWebEngineWidgets'
Even though the module exists in my python.
I tried including QtWebEngine in the "packages" of the options' "build_exe", but then the freezing doesn't work (ImportError No module named PyQtWebEngine)

@LaurentBerder
Copy link
Author

I will say that with python 3.7, the freezing process takes much longer, it's copying all of my python packages, which seems more adequate than the quick process that it did on 3.9.

@klensy
Copy link
Contributor

klensy commented Dec 18, 2020

Remove initScript = None, and replace base = "Win32GUI"
With your setup.py, i can build and run sample pyqt5 without errors, with python 3.8

What's your package versions? I've used this.

certifi==2020.12.5
chardet==4.0.0
cx-Freeze==6.4.2
idna==2.10
importlib-metadata==3.3.0
numpy==1.19.4
pandas==1.1.5
PyQt5==5.15.2
PyQt5-sip==12.8.1
pyqtlet==0.3.3
python-dateutil==2.8.1
pytz==2020.4
requests==2.25.1
six==1.15.0
urllib3==1.26.2
zipp==3.4.0

@LaurentBerder
Copy link
Author

LaurentBerder commented Dec 18, 2020

Well, I installed the same versions as you, and now I get an error during the freezing process.

RuntimeError: The current Numpy installation ('C:\\Programs\\Python\\Python37\\lib\\site-packages\\numpy\\__init__.py') fails to pass a sanity check due to a bug in the windows runtime. See this issue for more information: https://tinyurl.com/y3dm3h86

@klensy
Copy link
Contributor

klensy commented Dec 20, 2020

@LaurentBerder
As you can see from provided in error url, you can try to use numpy==1.19.3

@marcelotduarte
Copy link
Owner

The sample PyQt5 does the same results:

@LaurentBerder I do a test with the sample in py 3.9.1 in a VM/Win10 and has no issues.
I tested too in GA and you can see the results:
https://github.com/marcelotduarte/freeze-test/runs/1583428256?check_suite_focus=true

Please note:

@marcelotduarte
Copy link
Owner

remmina_teste6-vm-win10_teste6_20201220-17233,299483

@marcelotduarte
Copy link
Owner

I know there are some problems with numpy. The recommended version that works very well is 1.18.2, that is:
pip install "numpy==1.18.2"

@LaurentBerder
Copy link
Author

Thanks for your work and your time @marcelotduarte and @klensy,
Just installing numpy 1.18.2 solved it all, it even works on my original config, using the G: drive.

thumbs usp

@mikoim
Copy link

mikoim commented Jun 1, 2021

I've met the same issue after upgrading cx-Freeze version 6.6. The exeutable file does not work on the folder which includes multi-byte character. But cx-Freeze version 6.5.3 works well.

Reproduction

  • Windows 10 Pro for Workstations (amd64)
  • Python 3.9.5 on Anaconda (I tested on the same version from python.org and also got the error.)
conda create -n cx python=3.9.5
conda activate cx
pip install -U cx-Freeze
cxfreeze -c hello.py

# rename build\exe.win-amd64-3.9 directory to "テスト"
cd build\テスト
.\hello.exe

hello.py

print("hello")

pip list
Package            Version
------------------ -------------------
certifi            2020.12.5
cx-Freeze          6.6
cx-Logging         3.0
importlib-metadata 4.4.0
pip                21.1.1
setuptools         52.0.0.post20210125
wheel              0.36.2
wincertstore       0.2
zipp               3.4.1
Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = (not set)
  program name = 'C:\build\\u30c6\u30b9\u30c8\hello.exe'
  isolated = 0
  environment = 0
  user site = 1
  import site = 0
  sys._base_executable = 'C:\\build\\\u30c6\u30b9\u30c8\\hello.exe'
  sys.base_prefix = ''
  sys.base_exec_prefix = ''
  sys.platlibdir = 'lib'
  sys.executable = 'C:\\build\\\u30c6\u30b9\u30c8\\hello.exe'
  sys.prefix = ''
  sys.exec_prefix = ''
  sys.path = [
    'C:\\build\\',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x000009e4 (most recent call first):
<no Python frame>

@marcelotduarte
Copy link
Owner

@MKOiM your issue isn't the same, but cx_Freeze 6.7b2 has just been released with a fix (#1077).
pip install cx-Freeze==6.7b2

@mikoim
Copy link

mikoim commented Jun 1, 2021

@marcelotduarte thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants