Issue 27054: Python installation problem: No module named 'encodings' (original) (raw)
Issue27054
Created on 2016-05-18 21:59 by lauer@wpi.edu, last changed 2022-04-11 14:58 by admin. This issue is now closed.
Messages (16) | ||
---|---|---|
msg265838 - (view) | Author: Hugh C. Lauer (lauer@wpi.edu) | Date: 2016-05-18 21:59 |
Hello, I am a university professor who regularly teaches classes in Python programming, particular to students who are NOT computer science majors. In preparing my course materials for next fall, I have been struggling with setting up a Python 3.5.1 environment on my Windows computer (similar to what most of my students will use). I continually get the error "Fatal Python error: Py_Initialize: unable to load the file system codec ImportError: No module named 'encodings'" This seems to happen with Python 3.5.1 as well as Python 3.5.0. Nothing related to Python works:- not Python itself, not pip. My platform is Windows 7 Enterprise, Service Pack 1. * I used the installation file "python-3.5.1-amd64.exe" downloaded from the official Python download site. * During installation, I selected "Add Python 3.5 to PATH" and "Customize installation". * Under "Advanced Options," I selected "Install for all users" I have tried various other installation options, and nothing is better. I also tried it on a Windows 10 platform. In that case, Python and IDLE are installed correctly, but I any attempt to use pip to add or install other packages fails with a different error. For pedagogical reasons, I prefer the simply Python-IDLE environment to the packages such as Miniconda3, but installing Miniconda3 did not help either. Am I missing something obvious? Regards, Hugh C. Lauer\ Department of Computer Science Worcester Polytechnic Institute Worcester, Massachusetts, USA | ||
msg265855 - (view) | Author: Hugh C. Lauer (lauer@wpi.edu) | Date: 2016-05-19 13:15 |
Upon further investigation, I find lots of encodings in the folder C:\Program Files\Python35\Lib\encodings\ and lots of compiled encodings in the subfolder __pycache__ . Somehow, these are not being found by Python itself, or there is something missing from the installation. I investigated the registry. A search for "encodings" turns up lots of registry entries but none associated with Python. Regards, Hugh C. Lauer Worcester Polytechnic Institute | ||
msg265861 - (view) | Author: Hugh C. Lauer (lauer@wpi.edu) | Date: 2016-05-19 14:38 |
On a hunch, I uninstalled Python 3.5.1 and reinstalled it for the current user only, to see if it would make a difference in the association of the encodings in the Registry. There was no difference. The original error message still appears. Regards, Hugh C. Lauer Worcester Polytechnic Institute | ||
msg265862 - (view) | Author: Stefan Krah (skrah) * ![]() |
Date: 2016-05-19 14:49 |
I can only comment on the Windows 10 issue: I think I did the install with "Right-click -> Run as administrator" and then installed for all users. Encodings, pip and everything else works here. | ||
msg265865 - (view) | Author: Zachary Ware (zach.ware) * ![]() |
Date: 2016-05-19 14:55 |
Hugh, could you check your environment and see if you have any PYTHON* variables set, particularly PYTHONHOME? | ||
msg265866 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2016-05-19 14:55 |
To list environment variable, you can open cmd.exe and type the command "set". | ||
msg265867 - (view) | Author: Zachary Ware (zach.ware) * ![]() |
Date: 2016-05-19 14:57 |
Also, I suspect your pip issue on Windows 10 is due to the fact that you need to either specify the --user flag or run pip as administrator, since your user account can't write to the global site-packages under Program Files. | ||
msg265870 - (view) | Author: Zachary Ware (zach.ware) * ![]() |
Date: 2016-05-19 15:56 |
Here's some pretty compelling evidence for a bad PYTHONHOME setting: C:\>set PYTHONHOME=C:\path\not\here C:\>py -3.5 Fatal Python error: Py_Initialize: unable to load the file system codec ImportError: No module named 'encodings' Current thread 0x00001db4 (most recent call first): C:\>set PYTHONHOME=C:\Python27\ C:\>py -3.5 Fatal Python error: Py_Initialize: unable to load the file system codec File "C:\Python27\\lib\encodings\__init__.py", line 123 raise CodecRegistryError,\ ^ SyntaxError: invalid syntax Current thread 0x00000664 (most recent call first): C:\>set PYTHONHOME= C:\>py -3.5 Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> | ||
msg265907 - (view) | Author: Hugh C. Lauer (lauer@wpi.edu) | Date: 2016-05-20 02:03 |
Thanks, I will try it when I get out of airports. Hugh Lauer On May 19, 2016 11:56 AM, Zachary Ware <report@bugs.python.org> wrote: > > > Zachary Ware added the comment: > > Here's some pretty compelling evidence for a bad PYTHONHOME setting: > > C:\>set PYTHONHOME=C:\path\not\here > > C:\>py -3.5 > Fatal Python error: Py_Initialize: unable to load the file system codec > ImportError: No module named 'encodings' > > Current thread 0x00001db4 (most recent call first): > > C:\>set PYTHONHOME=C:\Python27\ > > C:\>py -3.5 > Fatal Python error: Py_Initialize: unable to load the file system codec > File "C:\Python27\\lib\encodings\__init__.py", line 123 > raise CodecRegistryError,\ > ^ > SyntaxError: invalid syntax > > Current thread 0x00000664 (most recent call first): > > C:\>set PYTHONHOME= > > C:\>py -3.5 > Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> > > ---------- > > _______________________________________ > Python tracker <report@bugs.python.org> > <http://bugs.python.org/issue27054> > _______________________________________ | ||
msg266334 - (view) | Author: Hugh C. Lauer (lauer@wpi.edu) | Date: 2016-05-25 12:00 |
I am back from my travels. Thanks very much, Stefan. Running as administrator did the trick for Windows 10 installations. I now have a reliable, repeatable protocol that I can give to students with little computing experience that will enable them to install Python on their Windows 10 laptops. Hugh Lauer Worcester Polytechnic Institute | ||
msg266336 - (view) | Author: Hugh C. Lauer (lauer@wpi.edu) | Date: 2016-05-25 12:04 |
I am back from my travels. Thanks Zachary for this. On Windows 10, no PYTHON or PYTHONHOME environment variable is set. On Windows 7, they are set. Moreover, even though I am installing Python 3.5.1, the refer to C:\Program files\Python34 ! I will continue to experiment with this. Regards, Hugh Lauer Worcester Polytechnic Institute | ||
msg266341 - (view) | Author: Hugh C. Lauer (lauer@wpi.edu) | Date: 2016-05-25 13:01 |
All, it seems that installation of Python 3.5.1 on Windows 7 must also be done as administrator. Once I did that, the installation of Python 3.5.1, numpy 1.11.0, and matplotlib 1.5.1 all went seamlessly. The only environment variable that was changed was to add the Python installation directory to the PATH environment variable. Regards, Hugh C. Lauer Worcester Polytechnic Institute | ||
msg266384 - (view) | Author: Steve Dower (steve.dower) * ![]() |
Date: 2016-05-25 18:13 |
I suspect PYTHONHOME is the problem and not the installation method. There have been thousands of (presumably successful) installations of Python 3.5, and I expect most of them are just for the current user (as that's the default). If these were all failing for this reason, we'd have heard before now :) There are likely to be some configurations that will cause the initial install to fail if you aren't running as an administrator, but that doesn't sound like the issue here. Rogue installers that write to Python's registry keys (e.g. Anaconda) are more likely to cause problems here, as are those that globally set environment variables like PYTHONHOME/PYTHONPATH. If, like me, you install a lot of different bundles to figure out which is best, then some of these may be lingering around. But I'm 99.99% certain that our installer is not at fault and there's nothing to fix here. | ||
msg309489 - (view) | Author: Sabuj Pattanayek (Sabuj Pattanayek) | Date: 2018-01-05 00:08 |
I can confirm that this does happen if you don't install as admin. I confirmed that I didn't have PYTHONHOME or PYTHONPATH set and I still got a similar error (except it was for the site module) for the python 3.4.4 installer. setting pythonhome and pythonpath to blank does make it work, but so does just installing the exe/msi as admin. Note this error does not happen with the python 2.7 installers even if you don't install as admin. | ||
msg366042 - (view) | Author: E (ergun) | Date: 2020-04-09 11:42 |
python3 gave the error but I could sudo python3. To solve: export PYTHONHOME= export PYTHONPATH= | ||
msg366075 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2020-04-09 15:57 |
> I continually get the error > "Fatal Python error: Py_Initialize: unable to load the file system codec > ImportError: No module named 'encodings'" FYI I enhanced this error in Python 3.8 to "dump the Python path configuration". Example: $ PYTHONHOME=x PYTHONPATH=y python3.8 Python path configuration: PYTHONHOME = 'x' PYTHONPATH = 'y' program name = 'python3.8' isolated = 0 environment = 1 user site = 1 import site = 1 sys._base_executable = '/usr/bin/python3.8' sys.base_prefix = 'x' sys.base_exec_prefix = 'x' sys.executable = '/usr/bin/python3.8' sys.prefix = 'x' sys.exec_prefix = 'x' sys.path = [ 'y', 'x/lib64/python38.zip', 'x/lib64/python3.8', 'x/lib64/python3.8/lib-dynload', ] 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 0x00007f50aaad8740 (most recent call first): It should be easier for users to understand their mistake. In general, leave PYTHONHOME empty/unset unless you understand very well what you are doing ;-) |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:58:31 | admin | set | github: 71241 |
2020-04-09 15:57:25 | vstinner | set | messages: + |
2020-04-09 11:42:38 | ergun | set | nosy: + ergunmessages: + |
2018-01-05 00:08:58 | Sabuj Pattanayek | set | nosy: + Sabuj Pattanayekmessages: + |
2016-05-25 18:37:41 | zach.ware | set | stage: resolved |
2016-05-25 18:13:04 | steve.dower | set | status: open -> closedresolution: not a bugmessages: + |
2016-05-25 13:01:51 | lauer@wpi.edu | set | messages: + |
2016-05-25 12:04:52 | lauer@wpi.edu | set | messages: + |
2016-05-25 12:00:47 | lauer@wpi.edu | set | messages: + |
2016-05-20 02:03:05 | lauer@wpi.edu | set | messages: + |
2016-05-19 18:56:33 | ppperry | set | type: crash |
2016-05-19 15:56:04 | zach.ware | set | messages: + |
2016-05-19 14:57:41 | zach.ware | set | messages: + |
2016-05-19 14:55:50 | vstinner | set | nosy: + vstinnermessages: + |
2016-05-19 14:55:14 | zach.ware | set | messages: + |
2016-05-19 14:49:58 | skrah | set | nosy: + skrahmessages: + |
2016-05-19 14:38:11 | lauer@wpi.edu | set | messages: + |
2016-05-19 13:15:00 | lauer@wpi.edu | set | messages: + |
2016-05-18 23:50:29 | ned.deily | set | nosy: + paul.moore, tim.golden, zach.ware, steve.dowercomponents: + Installation, Windowsversions: + Python 3.5 |
2016-05-18 21:59:26 | lauer@wpi.edu | create |