classification
Title: Python installation problem: No module named 'encodings'
Type: crash Stage: resolved
Components: Installation, Windows Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Sabuj Pattanayek, lauer@wpi.edu, paul.moore, skrah, steve.dower, tim.golden, vstinner, zach.ware
Priority: normal Keywords:

Created on 2016-05-18 21:59 by lauer@wpi.edu, last changed 2018-01-05 00:08 by Sabuj Pattanayek. This issue is now closed.

Messages (14)
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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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.
History
Date User Action Args
2018-01-05 00:08:58Sabuj Pattanayeksetnosy: + Sabuj Pattanayek
messages: + msg309489
2016-05-25 18:37:41zach.waresetstage: resolved
2016-05-25 18:13:04steve.dowersetstatus: open -> closed
resolution: not a bug
messages: + msg266384
2016-05-25 13:01:51lauer@wpi.edusetmessages: + msg266341
2016-05-25 12:04:52lauer@wpi.edusetmessages: + msg266336
2016-05-25 12:00:47lauer@wpi.edusetmessages: + msg266334
2016-05-20 02:03:05lauer@wpi.edusetmessages: + msg265907
2016-05-19 18:56:33ppperrysettype: crash
2016-05-19 15:56:04zach.waresetmessages: + msg265870
2016-05-19 14:57:41zach.waresetmessages: + msg265867
2016-05-19 14:55:50vstinnersetnosy: + vstinner
messages: + msg265866
2016-05-19 14:55:14zach.waresetmessages: + msg265865
2016-05-19 14:49:58skrahsetnosy: + skrah
messages: + msg265862
2016-05-19 14:38:11lauer@wpi.edusetmessages: + msg265861
2016-05-19 13:15:00lauer@wpi.edusetmessages: + msg265855
2016-05-18 23:50:29ned.deilysetnosy: + paul.moore, tim.golden, zach.ware, steve.dower

components: + Installation, Windows
versions: + Python 3.5
2016-05-18 21:59:26lauer@wpi.educreate