Python fatal python error initfsencoding unable to load the file system codec

What is the “Fatal Python error: Py_Initialize: unable to load the file system codec”? How to solve the problem in different operating systems?

This article discoursed by MiniTool Software gathers some information about “Fatal Python error: Py_Initialize: unable to load the file system codec” and “Fatal Python error: Initfsencoding: unable to load the file system codec”. Hope it can help you to some extent!

About “Fatal Python Error Unable to Load the File System Codec”

You may encounter A Fatal Python error: Py_Initialize: unable to load the file system codec problem when you try to make use of Python language for programming on your computer. For example, when you input:

#include <Python.h>

Int main (int, char**)

{

Py_Initialize ();

Py_Finalize ();

Return 0;

]

You may get the output:

Fatal Python error: Py_Initialize: unable to load the file system codec

LookupError: no codec search functions registered: can’t find encoding

As the error message indicates, the issue occurs during initializing Python in your program. The C or C++ compiler can’t load the Python system codec file, which is in charging of encoding and decoding the Python program. The possible causes are listed below.

  • The system cannot locate Python for it isn’t available in system/environment variables.
  • Python hasn’t been installed properly.
  • Two or more Python versions are available.

Next, let’s see the solutions for this error in different system environments.

Fix “Fatal Python Error: Unable to Load the File System Codec” in Windows 11/10

According to the possible reasons, you need to properly install the Python as well as set the Python path in system/environment variables.

1. Search for “edit the system environment variables” in Windows Search and open the matched result.

2. In the new popup named System Properties, click the Environment Variables…

system properties

3. In the next window, if there is any Python path under the User variables for xxx, just click on it and select Delete.

4. Then, choose Path under System variables and click the New button to add the Python path.

change environment variables

In this way, you are able to add the Python path to the environment variables.

Fix “Py_Initialize: Unable to Load the File System Codec” in MacOS

If you come across the same error in Apple Mac operating system (OS), the causes are the same as in the Windows environment. Yet, the solution for the Mac system is a little bit different. In macOS, you should find the .bash_profile or .bashrc file and add this command to the file.

export PYTHONHOME=“/Users/<user>/python3/”

export PYTHONPATH=“${PYTHONHOME}/bin”

Then, you can take advantage of the below command to set the variables.

source .bashrc

Fix “Fatal Python Error Py_Initialize Unable to Load the File System Codec” in Ubuntu/Debian

Also, you have a chance to receive this error code within the Linux-based Ubuntu or Debian operating system for the same reasons. Also, the fix is unlike. There, you have to open the terminal and perform the following command.

$ export PYTHONHOME=/usr/local/lib/python3.5/

$ export PYTHONPATH=/usr/local/lib/pathon3.5/

Fix “Fatal Python Error: Py_Initialize: Unable to Load the File System Codec” in Other OSes

The following are the commands to deal with the error in other operating systems.

# centOS

export PATH=$PATH:/usr/local/bin/python

this command line will append the “/sur/local/bin/python” path in the existing path.

# Anaconda

To handle the problem in the Anaconda system, you need to add the Anaconda path in the path variable.

where conda

where python

when you get the output, add that to the environmental variable of the system following the guide above according to your system.

# Jupyter Notebook

If you get the error, it may be due to that your local computer is not finding the path to Python as the jupyter notebook gets hosted on your local computer. To deal with this situation, you must specify the Python path in environment variables following the above instructions based on your own OS.

Fix “Fatal Python Error: Initfsencoding: Unable to Load the File System Codec”

Case 1

You may get this error when both Python 3 and Python 2 exist and one of the two fails to start.

#1 File error in Python3 path failed to start Python2

File “E:Python37Libsite.py”, line 177
file =sys.stderr)

SyntaxError: invalid syntax

#2 File error in Python2 path failed to start Python3

Fatal Python error: initfsencoding: Unable to load the file system codec
file “C:Python27Libencodings__init__. Py “, line 123
raise CodecRegistryError,
SyntaxError: invalid syntax
Current thread 0x000004dc (most recent call first):

# Solve the Errors

Those two cases in return the same. The reason is to set the environment variable PYTHONPATH, which is the Python search path. The default module will search from the PYTHONPATH while the environment variable is set to one version of the module paths resulting in another module version loading path error when trying to start, further leading launch failure.

Therefore, the environment variable needs to be configured when the custom module is no longer in C:PythonxxLib.

Case 2

Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module
named’encodings ‘ Current thread 0x00001080 (most recent call first)

Tip: The current thread of your error message may be different such as 0x00003c8c.

In Ubuntu operating system, you can downgrade Python using Anaconda or upgrade Anaconda to the latest version.

Also read

  • Audio Codec (Encoder + Decoder): How to Compare and Convert It?
  • Video Encoder and Video Codecs: How to Change Video Encoder?

Windows 11 Assistant Software Recommended

The new and powerful Windows 11 will bring you many benefits. At the same time, it will also bring you some unexpected damages such as data loss. Thus, it is strongly recommended that you back up your crucial files before or after upgrading to Win11 with a robust and reliable program like MiniTool ShadowMaker, which will assist you to protect your increasing data automatically on schedules!

Free Download

Read more

  • How to Record a Video with a Filter on PC/iPhone/Android/Online?
  • [Full Review] 240 FPS Video Definition/Samples/Cameras/Conversion
  • How to Tag People in Google Photos Manually & Remove Tags?
  • How to Transfer Photos from Camera to Computer Windows 11/10?
  • Fix Adobe Media Encoder Error Code: -1609629695 and Similar Issue

@ZhangYupengCHY

I get the following error when attempting to launch my apache server:

Current thread 0x00002464 (most recent call first):
[Sat Jun 19 16:29:38.535108 2021] [mpm_winnt:notice] [pid 5788:tid 828] AH00428: Parent: child process 14664 exited with status 3221226505 -- Restarting.
[Sat Jun 19 16:29:38.588966 2021] [mpm_winnt:notice] [pid 5788:tid 828] AH00455: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.0.3 mod_wsgi/4.9.0 Python/3.7 configured -- resuming normal operations
[Sat Jun 19 16:29:38.588966 2021] [mpm_winnt:notice] [pid 5788:tid 828] AH00456: Apache Lounge VS16 Server built: Feb 17 2021 13:11:14
[Sat Jun 19 16:29:38.588966 2021] [core:notice] [pid 5788:tid 828] AH00094: Command line: 'D:\xampp\apache\bin\httpd.exe -d D:/xampp/apache'
[Sat Jun 19 16:29:38.589963 2021] [mpm_winnt:notice] [pid 5788:tid 828] AH00418: Parent: Created child process 15192
Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

And my apache config is:

LoadFile "D:/python37/python37.dll"
LoadModule wsgi_module "D:/django-apache/venv2/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIScriptAlias / D:django-apachedemodemowsgi.py
WSGIPythonPath "D:/django-apache/venv2/Lib/site-packages"
<Directory D:django-apachedemodemo>
	<Files wsgi.py>
		Require all granted
	</Files>
</Directory>
Alias /media/ D:/django-apache/demo/static/
<Directory D:/django-apache/demo/static>   
	Require all granted  
</Directory>

Alias /static/ D:/django-apache/demo/static/
<Directory D:/django-apache/demo/static>   
	Require all granted  
</Directory>

WSGIApplicationGroup %{GLOBAL}

I already test the issue of #563 and #559.
Unfortunately the apache error log is always the same.

BTW mod_wsgi I used:

pip install --no-cache-dir -U https://github.com/GrahamDumpleton/mod_wsgi/archive/develop.zip

Im looking forward for your answer.
So much appricated.

@GrahamDumpleton

At the moment you should avoid using develop version from GitHub as some changes were made in last few days which are untested on Windows yet. Wouldn’t result in this error, but still best to avoid it. Use the latest official version of PyPi instead.

For a start, instead of:

WSGIPythonPath "D:/django-apache/venv2/Lib/site-packages"

use:

WSGIPythonHome "D:/django-apache/venv2"

The workaround of using WSGIPythonPath as talked about in old issues should not be needed with latest version on PyPi.

Also try to avoid using back slashes in Apache config. Always use forward slashes for path separators.

@ZhangYupengCHY

First thing first,I so appricated for your answer so quickly.
I did three things before

  1. reinstall the mod_wsgi by pip.
    2.changed the WSGIPythonPath «D:/django-apache/venv2/Lib/site-packages» to WSGIPythonHome «D:/django-apache/venv2»
    3.use forward slashes for path separators

And my apache config right now:

LoadFile "D:/python37/python37.dll"
LoadModule wsgi_module "D:/django-apache/venv2/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "D:/django-apache/venv2"

# WSGIPythonPath "D:/django-apache/demo"

WSGIScriptAlias / D:/django-apache/demo/demo/wsgi.py

<Directory D:/django-apache/demo/demo>
	<Files wsgi.py>
		Require all granted
	</Files>
</Directory>

Alias /media/ D:/django-apache/demo/static/
<Directory D:/django-apache/demo/static>   
	Require all granted  
</Directory>


Alias /static/ D:/django-apache/demo/static/
<Directory D:/django-apache/demo/static>   
	Require all granted  
</Directory>

WSGIApplicationGroup %{GLOBAL}

# LogLevel debug

And I restart the django and apache.
But apache error log is still the same.

@GrahamDumpleton

Are you running Apache manually from command line or as a system service? If a system service, does the user the system service runs as have permission to access the directory D:/django-apache?

@ZhangYupengCHY

I running it by XAMPP and apache run as a system service.

A minute ago,I used the python3.5 and XMAPP and all running good.And I want the django run by python3.7 so I changed the python3.5 to python 3.7 and reinstall the venv, and I can visit the web by django port and cant by apache port.
And my wsgi.py is

import os,sys

from django.core.wsgi import get_wsgi_application

sys.path.append('D:/django-apache/demo')
sys.path.append('D:/django-apache/demo/demo')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'demo.settings')

application = get_wsgi_application()

I just so confused where my config is wrong.

@GrahamDumpleton

Are you using standard Python distribution from the Python Software Foundation, or Anaconda Python?

Anaconda Python is known to have various problems which means some versions of it don’t work properly in embedded system like with how Apache/mod_wsgi works.

@ZhangYupengCHY

Im using the pycharm and install mod_wsgi by terminal with pip.
I will try some config.
So much much appricated for you to make sometime for answer my question which can caused by so many situations.

@GrahamDumpleton

Try creating a hello.wsgi file containing:

def application(environ, start_response):
    status = '200 OK'
    output = b'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

Then with the virtual environment activated, run in the same directory as the hello.wsgi file:

mod_wsgi-express start-server hello.wsgi

Try connecting to http://localhost:8000.

This will test using a hidden feature which is still experimental for Windows and shouldn’t normally be used as still has issues, but it runs Apache with a auto-generated configuration.

Note that it may not work at all since you are not using ApacheLounge distribution of Apache, which is what start-server on Windows expects to have. Also, you may have to use task manager to kill it when done with test as ctrl-c will not work depending on shell environment.

Anyway, this is just to test whether it works from command line rather than as system service, don’t rely on using this.

@ZhangYupengCHY

I will give a try and tall you what I test.
Anyway thank a lot again for your answer

—————— Original ——————
From: Graham Dumpleton ***@***.***&gt;
Date: Sat,Jun 19,2021 6:02 PM
To: GrahamDumpleton/mod_wsgi ***@***.***&gt;
Cc: Aaron Ramsey ***@***.***&gt;, Author ***@***.***&gt;
Subject: Re: [GrahamDumpleton/mod_wsgi] Fatal Python error: initfsencoding: unable to load the file system codec ModuleNotFoundError: No module named ‘encodings’ (#695)

Try creating a hello.wsgi file containing:
def application(environ, start_response): status = ‘200 OK’ output = b’Hello World!’ response_headers = [(‘Content-type’, ‘text/plain’), (‘Content-Length’, str(len(output)))] start_response(status, response_headers) return [output]
Then with the virtual environment activated, run in the same directory as the hello.wsgi file:
mod_wsgi-express start-server hello.wsgi
Try connecting to http://localhost:8000.

This will test using a hidden feature which is still experimental for Windows and shouldn’t normally be used as still has issues, but it runs Apache with a auto-generated configuration.

Note that it may not work at all since you are not using ApacheLounge distribution of Apache, which is what start-server on Windows expects to have. Also, you may have to use task manager to kill it when done with test as ctrl-c will not work depending on shell environment.

Anyway, this is just to test whether it works from command line rather than as system service, don’t rely on using this.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

@ZhangYupengCHY

When I run
mod_wsgi-express start-server hello.wsgi
in terminal.

`Server URL : http://localhost:8000/
Server Root : C:/Users/ADMINI1/AppData/Local/Temp/mod_wsgi-localhost-8000-Administrator
Server Conf : C:/Users/ADMINI1/AppData/Local/Temp/mod_wsgi-localhost-8000-Administrator/httpd.conf
Error Log File : C:/Users/ADMINI~1/AppData/Local/Temp/mod_wsgi-localhost-8000-Administrator/error_log (warn)
Operating Mode : daemon
Request Capacity : 5 (1 process * 5 threads)
Request Timeout : 60 (seconds)
Startup Timeout : 15 (seconds)
Queue Backlog : 100 (connections)
Queue Timeout : 45 (seconds)
Server Capacity : 20 (event/worker), 20 (prefork)
Server Backlog : 500 (connections)
Locale Setting : zh_CN.gbk

WARNING: The ability to use the start-server option on Windows
WARNING: is highly experimental and various things don’t quite
WARNING: work properly. If you understand a lot about using
WARNING: Python on Windows and Windows programming in general,
WARNING: and would like to help to get it working properly, then
WARNING: you can ask about Windows support for the start-server
WARNING: option on the mod_wsgi mailing list.
`

And I try connecting to http://localhost:8000.But could not connect.
Show «ERR_CONNECTION_REFUSED».

@GrahamDumpleton

And what was output to:

C:/Users/ADMINI~1/AppData/Local/Temp/mod_wsgi-localhost-8000-Administrator/error_log

@ZhangYupengCHY

error_log Output is
Current thread 0x000024d8 (most recent call first): [Mon Jun 21 09:25:39.918731 2021] [core:warn] [pid 7836:tid 1248] AH00098: pid file C:/Users/Administrator/AppData/Local/Temp/mod_wsgi-localhost-8000-Administrator/httpd.pid overwritten -- Unclean shutdown of previous Apache run? Fatal Python error: initfsencoding: unable to load the file system codec ModuleNotFoundError: No module named 'encodings'

BTW I change the python3.7,venv2(python3.7 virtual) to python 3.5,venv(python virtual) and different between the two virtual is mod_wsgi in python3.7 virtual is pip in pycharm Terminal and mod_wsgi in python3.5 virtual is whl.
And when I changed to python3.5 everything run perfect.

@GrahamDumpleton

Did you install Python for all users of the systems, or only your current user?

Especially when using system service to run Apache, the Python installation must be installed for all users.

@ZhangYupengCHY

Oky.I installing Python3.7.8(64-bit) right now and config the installed for all users and Its oky Now.
Thank you so much. It worked. Really appreciate you help with this.

Hello Geeks, I hope all are doing great. So in this article, we will see how we can solve the fatal python error: py_initialize: unable to load the file system codec. But before that, we will see some of the sample code and try to figure out why the error occurred. So, let’s get started.

Sample Code

#include <Python.h>

int main (int, char**)
{
  Py_Initialize ();
  Py_Finalize ();
  return 0;
}

Output:

Fatal Python error: Py_Initialize: unable to load the file system codec
LookupError: no codec search functions registered: can't find encoding

So, as the error raised, we can say that the problem lies within initializing Python in our program. The C/C++ compiler is unable to load the system codec file for Python. The codec file is responsible for encoding and decoding our python program, and if the compiler fails to do so, it raises the given error. Now there may be several reasons for the error to occur. Some of them are discussed below:

  • System unable to locate python as it is not available in system/environment variables.
  • There may be more than one python versions available.
  • Python is not properly installed in the system.

Solution: Changing Python Path In Environment Variables

Now, in all the above cases, the solution is that you need to properly install the Python and correctly set the path of Python in system/environment variables. To do that, do the following steps:

[ For Windows 10 ]

  • Open system by right clicking on windows icon.

System windows 10

  • Search env in search bar and select “Edit System Environement Variables”.

Search env

  • If any path exists for python, you can delete them by clicking the path and then selecting delete.
  • Else, Select path and click “New” to add “PythonPath” in the system variables.

Environment Variable Path

In this way, you can add the python path to the environmental variables.

“Other Commands Don’t Work After on_message” in Discord Bots

Fixing the Error in Ubuntu or Debian

You may also get the error while working on Debian or ubuntu. The reason mentioned above follows here too. However, the solution to fix the issue is quite simple in this case. You need to open the terminal and run the following command.

$ export PYTHONHOME=/usr/local/lib/python3.5/
$ export PYTHONPATH=/usr/local/lib/python3.5/

Fixing the Error in MacOS

However, the reason for the error remains the same for the macOS also, i.e., the system is unable to locate Python as it is not available in system/environment variables, or There may be more than one python version available. However, in macOS, the solution is slightly different than windows OS. In macOS, you have to find the .bashrc or .bash_profile file. In that file, you have to add the following command.

export PYTHONHOME="/Users/<user>/python3/"
export PYTHONPATH="${PYTHONHOME}/bin"

Once done, you can use the following command to set the variables.

Fixing the Error in centOS

In centOs, we can solve the issue by running the following command in its terminal.

export PATH=$PATH:/usr/local/bin/python

This will append the “/usr/local/bin/python” path in the existing path.

Fixing Error in Anaconda

However, you are using an anaconda, and while using it, you are getting the error. You need to add the anaconda path in the path variable. To do that, you need first to open the anaconda prompt and follow the given command.

Once you get the output, you need to add that to the environmental variable of your system. You can follow the above instructions based on Operating System you have.

Fixing the Error in JupyterNotebook

However, the scenarios change here a bit when it comes to getting the error while using a jupyter notebook. Here, the error occurred because your local computer is not finding the path to Python as the jupyter notebook gets hosted on your local computer. To fix the error, one must specify the python path in environmental variables. You can follow the above sections based on your operating system to do that.

[Resolved] NameError: Name _mysql is Not Defined

Can you embed Python with c++/C?

Yes, we can embed Python in C and C++ using Python.h library in C and C++.

Conclusion

So, today in this article, we have solved the Fatal python error: py_initialize: unable to load the file system codec. We have seen what the reasons for the error in the system are. Then we saw the steps to solve the error and set environment variables in our system.

I hope this article has helped you. Thank You.

Other Errors You Might Get

  • “Other Commands Don’t Work After on_message” in Discord Bots

    “Other Commands Don’t Work After on_message” in Discord Bots

    February 5, 2023

  • Botocore.Exceptions.NoCredentialsError: Unable to Locate Credentials

    Botocore.Exceptions.NoCredentialsError: Unable to Locate Credentials

    by Rahul Kumar YadavFebruary 5, 2023

  • [Resolved] NameError: Name _mysql is Not Defined

    [Resolved] NameError: Name _mysql is Not Defined

    by Rahul Kumar YadavFebruary 5, 2023

  • Best Ways to Implement Regex New Line in Python

    Best Ways to Implement Regex New Line in Python

    by Rahul Kumar YadavFebruary 5, 2023

BLENDER.ORG

  • Download

    Get the latest Blender, older versions, or experimental builds.

  • What’s New

    Stay up-to-date with the new features in the latest Blender releases.

RESOURCES

  • Blender Studio

    Access production assets and knowledge from the open movies.

  • Manual

    Documentation on the usage and features in Blender.

DEVELOPMENT

  • Developers Blog

    Latest development updates, by Blender developers.

  • Documentation

    Guidelines, release notes and development docs.

  • Benchmark

    A platform to collect and share results of the Blender Benchmark.

  • Blender Conference

    The yearly event that brings the community together.

DONATE

  • Development Fund

    Support core development with a monthly contribution.

  • One-time Donations

    Perform a single donation with more payment options available.

process

Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: steve.dower Nosy List: brett.cannon, eric.snow, hyu, lukasz.langa, miss-islington, ncoghlan, ned.deily, paul.moore, schlamar, serhiy.storchaka, steve.dower, tim.golden, vstinner, wwqgtxx, zach.ware

Priority: release blocker Keywords: 3.7regression, patch, patch, patch

Created on 2018-12-27 16:18 by hyu, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11329 merged steve.dower,
2018-12-27 20:26
PR 11329 merged steve.dower,
2018-12-27 20:26
PR 11331 merged miss-islington,
2018-12-27 20:44
PR 11331 merged miss-islington,
2018-12-27 20:44
PR 11331 merged miss-islington,
2018-12-27 20:44
PR 11465 merged steve.dower,
2019-01-08 02:58
PR 11465 merged steve.dower,
2019-01-08 02:58
PR 11467 merged miss-islington,
2019-01-08 10:38
PR 11467 merged miss-islington,
2019-01-08 10:38
PR 11467 merged miss-islington,
2019-01-08 10:38
Messages (32)
msg332595 — (view) Author: (hyu) Date: 2018-12-27 16:18
>python
Fatal Python error: initfsencoding: unable to load the file system codec
zipimport.ZipImportError: can't find module 'encodings'

There are two vcruntime140.dll with no binary diff.
 Date      Time     Attr     Size   Compressed   Name
------------------- ----- -------- ------------  ----------------
2018-12-10 22:06:34 .....    80128        45532  vcruntime140.dll
...
2018-12-10 22:06:34 .....    80128        45532  vcruntime140.dll

Repeated downloads. Checked both versions:
https://www.python.org/ftp/python/3.7.2/python-3.7.2-embed-amd64.zip
https://www.python.org/ftp/python/3.7.2/python-3.7.2-embed-win32.zip

Searched and read release and doc. Checked bugs since yesterday.
msg332610 — (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2018-12-27 19:08
Have you tried a proper install as well? Could you do that to rule out any problem on your machine?

Are you repackaging anything as part of your app, or are you just testing the package first and getting this error?

It looks like you're running from the directory you extracted to. Is there anything else in that directory or just the Python files?

When you say there are two vcruntime140.dll, you mean one in each package and they're the same? That might be a problem, but it wouldn't show up like this, so I don't think it's yours. I'm not in A position to check the files right now but I'll get to it later
msg332612 — (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2018-12-27 20:16
Okay, this looks like a zipimport issue. When I extract the "python37.zip" file containing the stdlib and reference the directory it works fine. But no matter what I do to the ZIP I can't get it to run.

It seems that zipimport either can't import .pyc files without a matching .py, or it can't import packages marked with __init__.pyc (I haven't gone deep enough, but adding encodings/__init__.py got me further).

This is a regression from 3.7.1.

Things to do:
* fix the regression (Serhiy?)
* add a regression test
* add a ".pyc-only stdlib in ZIP" test (I'll do this)
* remove the double vcruntime in ZIP issue (unrelated, so I'll just fix it)
msg332615 — (view) Author: (hyu) Date: 2018-12-27 20:33
Repeated on two clean install Windows hosts.
No (re)packaging, download and run/start python.
Repeated with versions 3.7.2, 3.7.1, and 3.6.8:

https://www.python.org/ftp/python/3.7.2/python-3.7.2-embed-amd64.zip
https://www.python.org/ftp/python/3.7.1/python-3.7.1-embed-amd64.zip
https://www.python.org/ftp/python/3.6.8/python-3.6.8-embed-amd64.zip

Windows Explorer properly extracted: tmppy372, tmppy371, tmppy368.
Python 3.6.8 and 3.7.1 properly started, executed import sys; sys.exit()
Python 3.7.2 failed to start.  Please suggest proper commands if you claim these are not proper Windows commands.

Worked extra to show both 3.6 and 3.7 regressions.  If you want to claim copying 3.6.8 vcruntime140.dll to 3.7.1 as (re)packaging, then ignore v3.7.1:260ec2c36a below.  

Windows Explorer shows and 7-zip lists two vcruntime140.dll in 3.7.2.  Please ignore 7-zip if you claim that is not proper or (re)package tool and I will attach Windows Explorer screen shot.


Microsoft Windows [Version 10.0.17763.195]
(c) 2018 Microsoft Corporation. All rights reserved.

C:>tmppy368python
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
>>> import sys; sys.exit()

C:>tmppy372python
Fatal Python error: initfsencoding: unable to load the file system codec
zipimport.ZipImportError: can't find module 'encodings'

Current thread 0x00002614 (most recent call first):

C:>copy tmppy368vcruntime140.dll tmppy371
        1 file(s) copied.

C:>tmppy371python
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32
>>> import sys; sys.exit()

C:>
msg332616 — (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2018-12-27 20:39
Thanks for the extra info, and for confirming that 3.6.8 isn't affected (I hadn't tried that you, so you saved me some work :) )

This is definitely a new zipimport regression in 3.7.2. Thanks for the report.
msg332618 — (view) Author: miss-islington (miss-islington) Date: 2018-12-27 20:44
New changeset 59c2aa25ffc864bf11bf3b3973828f00e268a992 by Miss Islington (bot) (Steve Dower) in branch 'master':
bpo-35596: Fix vcruntime140.dll being added to embeddable distro multiple times. (GH-11329)
https://github.com/python/cpython/commit/59c2aa25ffc864bf11bf3b3973828f00e268a992
msg332630 — (view) Author: miss-islington (miss-islington) Date: 2018-12-28 01:04
New changeset bbf695441af9def8a121ff3e245415d9fc0bab9a by Miss Islington (bot) in branch '3.7':
bpo-35596: Fix vcruntime140.dll being added to embeddable distro multiple times. (GH-11329)
https://github.com/python/cpython/commit/bbf695441af9def8a121ff3e245415d9fc0bab9a
msg332654 — (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-12-28 11:52
There were no changes in zipimport between 3.7.1 and 3.7.2, and there were just few looking unrelated changes in the import machinery. Maybe this is caused by some changes in the interpreter initialization code?
msg332660 — (view) Author: miss-islington (miss-islington) Date: 2018-12-28 14:22
New changeset bbf695441af9def8a121ff3e245415d9fc0bab9a by Miss Islington (bot) in branch '3.7':
bpo-35596: Fix vcruntime140.dll being added to embeddable distro multiple times. (GH-11329)
https://github.com/python/cpython/commit/bbf695441af9def8a121ff3e245415d9fc0bab9a
msg332664 — (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2018-12-28 15:02
Reviewing the diff at https://github.com/python/cpython/compare/v3.7.1...v3.7.2 the only item I've spotted that seems like it could even plausibly be related is the tweak at https://github.com/python/cpython/compare/v3.7.1...v3.7.2#diff-baf5eab51059d96fb8837152dab0d1a4

(Click the Files tab to get your browser to jump to the anchor in the second link)

That's a change to the function that emits the "Fatal Python error: initfsencoding: unable to load the file system codec" message.

That change means that embedding applications could potentially be hitting the codec name resolution at https://github.com/python/cpython/blob/3.7/Python/pylifecycle.c#L1643 with the filesystem encoding set as "ascii", rather than handling that case through the "get_locale_encoding()" branch, which does the initial codec name lookup with the filesystem encoding still set to NULL (and hence falling back to the locale encoding as the default).

However, the only way that new branch could trigger is if check_force_ascii() (at https://github.com/python/cpython/blob/v3.7.2/Python/fileutils.c#L100 ) is returning 1 for some reason, which we only expect it to do on some misbehaving BSD OSes, not on Windows: https://github.com/python/cpython/pull/10233
msg332674 — (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2018-12-28 19:06
None of the code you linked is defined on Windows at all, so it can't be that.

Are any stat checks done when there's only a .pyc to import? Could it be deciding that the .pyc is out of date and then failing to find source?
msg332696 — (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2018-12-29 03:19
I took a closer look at the diff since 3.7.1, and I'm not seeing anything either. I suspect we need to step through zipimport/importlib and figure out exactly where it rejects the .pyc files in the zip.
msg332800 — (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2018-12-31 05:09
Ah, you're right - I missed that the ForceASCII stuff was on the non-Windows side of an ifdef so it's literally impossible for that change to affect Windows, not just highly unlikely.

It would be interesting to compare the output of `python -vv` between the working case and the non-working case, as the second level of verbosity will print out all the different candidates the two versions are considering, and which ones they're accepting. For example, here's my Linux system Python up to the point where it finishes importing the UTF-8 codec:

========================
$ python3 -vv
import _frozen_importlib # frozen
import _imp # builtin
import '_thread' # <class '_frozen_importlib.BuiltinImporter'>
import '_warnings' # <class '_frozen_importlib.BuiltinImporter'>
import '_weakref' # <class '_frozen_importlib.BuiltinImporter'>
# installing zipimport hook
import 'zipimport' # <class '_frozen_importlib.BuiltinImporter'>
# installed zipimport hook
import '_frozen_importlib_external' # <class '_frozen_importlib.FrozenImporter'>
import '_io' # <class '_frozen_importlib.BuiltinImporter'>
import 'marshal' # <class '_frozen_importlib.BuiltinImporter'>
import 'posix' # <class '_frozen_importlib.BuiltinImporter'>
import _thread # previously loaded ('_thread')
import '_thread' # <class '_frozen_importlib.BuiltinImporter'>
import _weakref # previously loaded ('_weakref')
import '_weakref' # <class '_frozen_importlib.BuiltinImporter'>
# /usr/lib64/python3.7/encodings/__pycache__/__init__.cpython-37.pyc matches /usr/lib64/python3.7/encodings/__init__.py
# code object from '/usr/lib64/python3.7/encodings/__pycache__/__init__.cpython-37.pyc'
# trying /usr/lib64/python3.7/codecs.cpython-37m-x86_64-linux-gnu.so
# trying /usr/lib64/python3.7/codecs.abi3.so
# trying /usr/lib64/python3.7/codecs.so
# trying /usr/lib64/python3.7/codecs.py
# /usr/lib64/python3.7/__pycache__/codecs.cpython-37.pyc matches /usr/lib64/python3.7/codecs.py
# code object from '/usr/lib64/python3.7/__pycache__/codecs.cpython-37.pyc'
import '_codecs' # <class '_frozen_importlib.BuiltinImporter'>
import 'codecs' # <_frozen_importlib_external.SourceFileLoader object at 0x7f0ea616eb70>
# trying /usr/lib64/python3.7/encodings/aliases.cpython-37m-x86_64-linux-gnu.so
# trying /usr/lib64/python3.7/encodings/aliases.abi3.so
# trying /usr/lib64/python3.7/encodings/aliases.so
# trying /usr/lib64/python3.7/encodings/aliases.py
# /usr/lib64/python3.7/encodings/__pycache__/aliases.cpython-37.pyc matches /usr/lib64/python3.7/encodings/aliases.py
# code object from '/usr/lib64/python3.7/encodings/__pycache__/aliases.cpython-37.pyc'
import 'encodings.aliases' # <_frozen_importlib_external.SourceFileLoader object at 0x7f0ea6183550>
import 'encodings' # <_frozen_importlib_external.SourceFileLoader object at 0x7f0ea616e5c0>
# trying /usr/lib64/python3.7/encodings/utf_8.cpython-37m-x86_64-linux-gnu.so
# trying /usr/lib64/python3.7/encodings/utf_8.abi3.so
# trying /usr/lib64/python3.7/encodings/utf_8.so
# trying /usr/lib64/python3.7/encodings/utf_8.py
# /usr/lib64/python3.7/encodings/__pycache__/utf_8.cpython-37.pyc matches /usr/lib64/python3.7/encodings/utf_8.py
# code object from '/usr/lib64/python3.7/encodings/__pycache__/utf_8.cpython-37.pyc'
import 'encodings.utf_8' # <_frozen_importlib_external.SourceFileLoader object at 0x7f0ea6191278>
========================
msg332816 — (view) Author: wwq (wwqgtxx) Date: 2018-12-31 13:19
I have tried zipping the stdlib myself form normal version's "Python37Lib" with all files were end with ".py"(without "site-packages" of course). And then everything work fine. Maybe the loader only reject ".pyc" file from zip load?
msg332840 — (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2018-12-31 23:56
Yes, we've established that zipimport is rejecting .pyc files now, but we need to dig through it to figure out why. I haven't had time yet, but if someone else can then don't wait for me.
msg333203 — (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-01-08 02:26
Looks like zipimport in 3.7 always rejected CHECKED_HASH pycs, while in 3.8 it always accepts them (or runs it through a validation process that passes them when the source file doesn't exist - I only confirmed by testing a build, not by walking through the new sources).

Rather than changing the old zipimport now, it's more correct to fix the embeddable ZIP build to specify UNCHECKED_HASH.
msg333204 — (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-01-08 02:31
And I assume now that the reason it broke in 3.7.2 is because the pyc mode for the embeddable distro changed. Which means the right place for tests is in a separate build that uses properly laid out Python rather than testing in the source tree (like what I have in the windows-appx-tests.yml file and Tools/msi/testrelease.bat script, but apparently also for the embeddable distro).
msg333219 — (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-01-08 10:38
New changeset 872bd2b57ce8e4ea7a54acb3934222c0e4e7276b by Steve Dower in branch 'master':
bpo-35596: Use unchecked PYCs for the embeddable distro to avoid zipimport restrictions (GH-11465)
https://github.com/python/cpython/commit/872bd2b57ce8e4ea7a54acb3934222c0e4e7276b
msg333221 — (view) Author: miss-islington (miss-islington) Date: 2019-01-08 10:56
New changeset 69f64b67e43c65c2178c865fd1be80ed07f02d3c by Miss Islington (bot) in branch '3.7':
bpo-35596: Use unchecked PYCs for the embeddable distro to avoid zipimport restrictions (GH-11465)
https://github.com/python/cpython/commit/69f64b67e43c65c2178c865fd1be80ed07f02d3c
msg333250 — (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-01-08 20:46
This is now resolved, and only through modifying the build scripts. Which means I can take the existing build and republish a fixed embeddable package without needing a new release.

Unless Ned would prefer a complete release?
msg333252 — (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2019-01-08 21:21
It seems like this need not trigger a complete new release and, ATM, I'm not aware of any other showstopper problems that would otherwise trigger an early 3.7.3.  One question would be how and where to document this change in the build artificat.  Suggestions, Steve?
msg333253 — (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-01-08 21:23
> This is now resolved, and only through modifying the build scripts. Which means I can take the existing build and republish a fixed embeddable package without needing a new release.

Since Python itself doesn't make, I'm ok to not change the Python release. But for pratical issues, would it be possible to use a different *filename*? For example, Python website rely a lot on CDN caching. It can be surprising to have two files with the same name but different content.
msg333254 — (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2019-01-08 21:32
CDN caching on python.org is not a problem; we know how to clear out the cache.  But I also strongly dislike silent updates of released files so I agree that names should be changed if we do end up agreeing to replace one or more files.
msg333255 — (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-01-08 21:41
I know how to purge the CDN cache, so that's not an issue. And there's no good reason to leave the old one up.

Perhaps we can just add a note to the download page and I'll post on a couple of lists? This is basically a product recall, and those are usually advertised at the point of sale.
msg333257 — (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-01-08 21:48
I can add ".post1" to the version number in the file name, but I'd still want to take down the broken one. And anyone who's generating the download URL will get a broken link, which IMO is just as bad as a broken download when we could fix it.
msg333259 — (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2019-01-08 22:03
I think we should change the name (post1 is fine), delete the original file, update the file name link in the release page (https://www.python.org/downloads/release/python-372/) to use the new name, and add a sentence or two to the release page describing the change.  If you could write up something for the page, I can add it and change the file name when ready.
msg333260 — (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-01-08 22:37
It would be weird if building from sources will not give the same distribution as downloaded from official site. It would be not fair to alternate distributors.

I think this is a time to release 3.7.2.1. This would be not the first time of using the fourth number in the version.
msg333264 — (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2019-01-08 23:00
> It would be weird if building from sources will not give the same distribution as downloaded from official site. It would be not fair to alternate distributors.

Yes, I agree with that in general but, as I understand it, the change here affects only how the Windows embeddable distribution is packaged.  I don't think we expect alternate distributors to produce such distributions - or do we know of such cases?  And, even if so, it's not a big deal for a third-party to pick up the change. There are parts of the PC and Mac source tree that really are intended only for building of python.org binary releases.  If the changes affected the python executables or standard library files, that would be a very different matter.  It is a trade-off; I just don't think that this is the type of change that needs to trigger a new release cycle and I don't want to go down the path of creating a new level of release.  When was the last time we had a 3.x.y.z? I don't recall one.
msg333266 — (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-01-08 23:25
Agreed. My plan is to just replace the precompiled ZIP file of the standard library in the embeddable package with one with PYCs missing the "check source" bit that the old zipimport rejects. It's as simple as a 1 line change in a supporting script in PC/layout (though the actual change I made is more significant to support other use cases).

The binary and library sources are so identical this doesn't even require a rebuild. And anyone building their own distro from source using this script will hit the issue and find this bug. The only reason I missed it was because I tested against master, not realising that the new zipimport changed behaviour here. Nobody else will be blindly releasing these packages with only tests against an incompatible versions the way we do (and now I have tests).
msg333276 — (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-01-09 03:23
I've updated the files and sent Ned the info needed to confirm and update the download page.
msg333278 — (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2019-01-09 04:30
Thanks, Steve.  The download page for 3.7.2 has now been updated with the URLs for the modified embeddable files, the CDN caches updated, and the original embeddable download files and their GPG signature files are no longer accessible so references to the original URLs will result in hard failures.  I considered updating the 3.7.2 blog announcement but decided against it as likely adding more confusion than it was worth.  There just aren't that many users yet of the embeddable files.
msg333290 — (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-01-09 06:47
> When was the last time we had a 3.x.y.z? I don't recall one.

My apologies, it seems my memory has tricked me. I thought there was on in the 3.3 branch, but it was just that the third number was bumped again just a month ago after a bugfix release.
History
Date User Action Args
2022-04-11 14:59:09 admin set nosy:
+ lukasz.langa
github: 79777
2019-01-09 06:47:02 serhiy.storchaka set keywords:
patch, patch, patch, 3.7regression

messages:
+ msg333290

2019-01-09 04:30:37 ned.deily set status: open -> closed
messages:
+ msg333278

keywords:
patch, patch, patch, 3.7regression
resolution: fixed
stage: patch review -> resolved

2019-01-09 03:23:07 steve.dower set keywords:
patch, patch, patch, 3.7regression

messages:
+ msg333276

2019-01-08 23:25:08 steve.dower set keywords:
patch, patch, patch, 3.7regression

messages:
+ msg333266

2019-01-08 23:00:39 ned.deily set keywords:
patch, patch, patch, 3.7regression

messages:
+ msg333264

2019-01-08 22:37:54 serhiy.storchaka set keywords:
patch, patch, patch, 3.7regression

messages:
+ msg333260

2019-01-08 22:03:59 ned.deily set keywords:
patch, patch, patch, 3.7regression

messages:
+ msg333259

2019-01-08 21:48:23 steve.dower set keywords:
patch, patch, patch, 3.7regression

messages:
+ msg333257

2019-01-08 21:41:49 steve.dower set keywords:
patch, patch, patch, 3.7regression

messages:
+ msg333255

2019-01-08 21:32:59 ned.deily set keywords:
patch, patch, patch, 3.7regression

messages:
+ msg333254

2019-01-08 21:23:19 vstinner set keywords:
patch, patch, patch, 3.7regression

messages:
+ msg333253

2019-01-08 21:21:32 ned.deily set keywords:
patch, patch, patch, 3.7regression

messages:
+ msg333252

2019-01-08 20:46:03 steve.dower set keywords:
patch, patch, patch, 3.7regression

messages:
+ msg333250

2019-01-08 10:56:26 miss-islington set messages:
+ msg333221
2019-01-08 10:46:07 xtreak link issue35684 superseder
2019-01-08 10:39:44 njs unlink issue35684 superseder
2019-01-08 10:38:33 miss-islington set pull_requests:
+ pull_request10957
2019-01-08 10:38:32 miss-islington set pull_requests:
+ pull_request10958
2019-01-08 10:38:30 miss-islington set pull_requests:
+ pull_request10956
2019-01-08 10:38:05 steve.dower set messages:
+ msg333219
2019-01-08 10:37:30 serhiy.storchaka link issue35684 superseder
2019-01-08 02:58:45 steve.dower set stage: test needed -> patch review
pull_requests:
+ pull_request10954
2019-01-08 02:58:23 steve.dower set stage: test needed -> test needed
pull_requests:
+ pull_request10953
2019-01-08 02:31:45 steve.dower set keywords:
patch, patch, patch, 3.7regression

messages:
+ msg333204

2019-01-08 02:26:35 steve.dower set keywords:
patch, patch, patch, 3.7regression
assignee: steve.dower
messages:
+ msg333203
2019-01-07 08:30:36 schlamar set nosy:
+ schlamar
2018-12-31 23:56:15 steve.dower set keywords:
patch, patch, patch, 3.7regression

messages:
+ msg332840

2018-12-31 13:19:05 wwqgtxx set nosy:
+ wwqgtxx
messages:
+ msg332816
2018-12-31 05:09:14 ncoghlan set keywords:
patch, patch, patch, 3.7regression

messages:
+ msg332800

2018-12-29 03:19:01 steve.dower set keywords:
patch, patch, patch, 3.7regression

messages:
+ msg332696

2018-12-28 19:06:07 steve.dower set keywords:
patch, patch, patch, 3.7regression

messages:
+ msg332674

2018-12-28 15:02:41 ncoghlan set keywords:
patch, patch, patch, 3.7regression

messages:
+ msg332664

2018-12-28 14:22:58 miss-islington set messages:
+ msg332660
2018-12-28 11:52:27 serhiy.storchaka set keywords:
patch, patch, patch, 3.7regression
nosy:
+ brett.cannon, ncoghlan, vstinner, eric.snow
messages:
+ msg332654
2018-12-28 06:27:00 steve.dower link issue35587 superseder
2018-12-28 01:04:11 miss-islington set messages:
+ msg332630
2018-12-27 22:44:33 eryksun set keywords:
patch, patch, patch, 3.7regression
nosy:
+ serhiy.storchaka

type: crash
stage: patch review -> test needed

2018-12-27 20:45:07 miss-islington set keywords:
+ patch
pull_requests:
+ pull_request10602
2018-12-27 20:44:58 miss-islington set keywords:
+ patch
pull_requests:
+ pull_request10601
2018-12-27 20:44:49 miss-islington set keywords:
+ patch
pull_requests:
+ pull_request10600
2018-12-27 20:44:29 miss-islington set nosy:
+ miss-islington
messages:
+ msg332618
2018-12-27 20:39:53 steve.dower set keywords:
+ 3.7regression, — patch, patch

messages:
+ msg332616
versions:
+ Python 3.8

2018-12-27 20:33:31 hyu set nosy:
— serhiy.storchaka
type: crash -> (no value)
messages:
+ msg332615
2018-12-27 20:26:51 steve.dower set keywords:
+ patch
stage: test needed -> patch review
pull_requests:
+ pull_request10595
2018-12-27 20:26:29 steve.dower set keywords:
+ patch
stage: test needed -> test needed
pull_requests:
+ pull_request10594
2018-12-27 20:16:24 steve.dower set priority: normal -> release blocker

nosy:
+ ned.deily, serhiy.storchaka
messages:
+ msg332612

type: crash
stage: test needed

2018-12-27 19:08:23 steve.dower set messages:
+ msg332610
2018-12-27 17:35:37 ned.deily set nosy:
+ paul.moore, tim.golden, zach.ware, steve.dower
components:
+ Windows
2018-12-27 16:18:27 hyu create

Понравилась статья? Поделить с друзьями:
  • Python fatal error c1083
  • Python failed with error code 1
  • Python exe ошибка при запуске приложения 0xc000007b
  • Python exception текст ошибки
  • Python exception вывести ошибку