I have Python (3.9) installed to to my local user account programs folder. When I execute it, I get the following error. A few things that are odd:
In my main Python script, I cannot even do a simple print() first thing, so the problem is directly with Python itself
sys.path has 2 entries that don't exist. I am not sure how they were set to those values, or what set them, but they are wrong as those paths don't exist and a third entry references a zip file, which is probably related to the issue I am having
I inspected all the paths manually and everything is as it should be, and the encodings module does exist
Python only exists in my PATH environment variable once, which is:
C:\Users\<username>\AppData\Local\Programs\Python\Launcher\ and that Launcher folder doesn't exist, and I have no idea how it was even set as I intentionally told Python not to add itself to the PATH variable so it would never interfere with other Python installations (which there currently are none).
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = 'C:\Users\<username>\AppData\Local\Programs\Python\python.exe'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = 'C:\\Users\\<username>\\AppData\\Local\\Programs\\Python\\python.exe'
sys.base_prefix = ''
sys.base_exec_prefix = ''
sys.platlibdir = 'lib'
sys.executable = 'C:\\Users\\<username>\\AppData\\Local\\Programs\\Python\\python.exe'
sys.prefix = ''
sys.exec_prefix = ''
sys.path = [
'C:\\Users\\<username>\\AppData\\Local\\Programs\\Python\\python39.zip',
'C:\\Python39\\Lib\\',
'C:\\Python39\\DLLs\\',
'C:\\Users\\<username>\\AppData\\Local\\Programs\\Python',
]
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 0x000071d4 (most recent call first):
<no Python frame>
If sys.path is incorrect (which it appears as such), how can I manually set this, or fix it? Especially given that my script never gets the opportunity to execute
I had a similar problem in which I wanted to use my Ubuntu python installed in /usr/bin but when I typed python, the default python was pointing to Anaconda python installation instead of the python installed in /usr/bin.
I solved that using this:
Use the default Python rather than the Anaconda installation when called from the terminal
So in file ~/.bashrc instead of
Added by the Anaconda3 4.3.0 installer
export PATH="/home/user/anaconda3/bin:$PATH"
one would use
export PATH="$PATH:/home/user/anaconda3/bin"
Related
I have one file with my own utils I use in many projects. In order not to copy it to every single project and manually pip install everything needed, I decided to make module out of it.
However, when I use PyInstaller to create .exe file from project and try to run it, I get error:
Python path configuration:
PYTHONHOME = 'C:\Users\Adam\AppData\Local\Temp\_MEI102882'
PYTHONPATH = (not set)
program name = 'C:\Users\Adam\Desktop\Praca\TEST\dist\main.exe'
isolated = 0
environment = 0
user site = 0
import site = 0
sys._base_executable = 'C:\\Users\\Adam\\Desktop\\Praca\\TEST\\dist\\main.exe'
sys.base_prefix = ''
sys.base_exec_prefix = ''
sys.platlibdir = 'lib'
sys.executable = 'C:\\Users\\Adam\\Desktop\\Praca\\TEST\\dist\\main.exe'
sys.prefix = ''
sys.exec_prefix = ''
sys.path = [
'C:\\Users\\Adam\\AppData\\Local\\Temp\\_MEI102882\\base_library.zip',
'C:\\Users\\Adam\\AppData\\Local\\Temp\\_MEI102882\\lib-dynload',
'C:\\Users\\Adam\\AppData\\Local\\Temp\\_MEI102882',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
LookupError: unknown encoding: utf-8
Current thread 0x000022ac (most recent call first):
<no Python frame>
I'm not even sure what to do now. I see that some paths refer to Temp folder, don't know, however, if this is how it should be.
I am working in Windows 11, Python 3.10, Mu 1.1.0. I followed the instructions on ATBS to create a batch file to run a script from the WIN + R launcher. However in CMD the error A(below) pops up. I tried following instructions from the documentation on python.org, and in Appendix B of ATBS to edit environment variables. I added the following to PATH env variables: C:\Users\19139\MyPythonScript; C:\Users\19139\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.10\Python 3.10 (64-bit).lnk; and C:\Users\19139\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.10\Python 3.10 (64-bit).lnk\Scripts. Is there some issue with the fact that the PATH includes start menu? All I am able to call from CMD is py --version. When I try and directly call a python script I get Error B. I disabled the "App Installer"(s) under App Aliases for Python.exe and Python3.exe but no change in error. I can call py --version, but I am beyond the scope of my ability to figure out what to do. I am unsure of next possible step to problem solve, suggestions welcome.
Error A:
`enter code here`Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = 'C:\Users\19139\AppData\Local\Programs\Python\Python310\python.exe'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = 'C:\\Users\\19139\\AppData\\Local\\Programs\\Python\\Python310\\python.exe'
sys.base_prefix = ''
sys.base_exec_prefix = ''
sys.platlibdir = 'lib'
sys.executable = 'C:\\Users\\19139\\AppData\\Local\\Programs\\Python\\Python310\\python.exe'
sys.prefix = ''
sys.exec_prefix = ''
sys.path = [
'C:\\Users\\19139\\AppData\\Local\\Programs\\Python\\Python310\\python310.zip',
'C:\\Users\\19139\\AppData\\Local\\Programs\\Python\\Python310\\Lib\\',
'C:\\Users\\19139\\AppData\\Local\\Programs\\Python\\Python310\\DLLs\\',
'C:\\Users\\19139\\AppData\\Local\\Programs\\Python\\Python310',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
Traceback (most recent call last):
File "C:\Users\19139\AppData\Local\Programs\Python\Python310\Lib\encodings\__init__.py", line 31, in <module>
ModuleNotFoundError: No module named 'codecs'
Error B
C:\Users\19139>python "C:\Users\19139\MyPythonScript\mClip.py"
Python was not found; run without arguments to install from the Microsoft Store, or
disable this shortcut from Settings > Manage App Execution Aliases.
First of all, unlike ubuntu/ linux Windows doesn't detect python on its own. That's why we need to specify the path manually, to make it aware of python.
Is there some issue with the fact that the PATH includes start menu?
Yes, there is issue there. PATH for python doesn't include Start Menu generally.
You are looking at the wrong place or have installed python package at the wrong location. Find the correct python package location.
Python PATH looks something like this:
C:\Users\user_name\python_installerpkg_name
For example, if you have installed python using a python installer pkg like anaconda/ mini-conda, you can use its command prompt to find the location via where python. Then use the location to set the PATH in environment variables. the PATH would look like: C:\Users\user_name\anaconda
Error B
Until you configure the correct path in the environment variables you won't be able to use the command python filename.py from the command line.
I've set up a virtual environment on MacOS BigSur 11.6 using python 3.9.7 version.
Environment name is "ambiente" and this is how the terminal looks like :
(ambiente) mac.fede#Ahoga PageDownloader %
I'm in PageDownloader directory.
Inside this folder there is my python project.
I can run the program using : python3 PageDownloader.py and all works fine.
I tried to install and run it using PyInstaller and the UNIX executable works fine.
Then using Platypus I bottled it to an application, when the icon is double clicked a shell script runs and launches the UNIX executable file obtained before.
When I double click the application this is the output :
initializing script //this launches PageDownloader Executable file
Python path configuration:
PYTHONHOME = '/Users/mac.fede/Documents/GitHub/PageDownloader/PageDownloader.app/Contents/Resources'
PYTHONPATH = (not set)
program name = '/Users/mac.fede/Documents/GitHub/PageDownloader/PageDownloader.app/Contents/Resources/PageDownloader'
isolated = 0
environment = 0
user site = 0
import site = 0
sys._base_executable = '/Users/mac.fede/Documents/GitHub/PageDownloader/PageDownloader.app/Contents/Resources/PageDownloader'
sys.base_prefix = ''
sys.base_exec_prefix = ''
sys.platlibdir = 'lib'
sys.executable = '/Users/mac.fede/Documents/GitHub/PageDownloader/PageDownloader.app/Contents/Resources/PageDownloader'
sys.prefix = ''
sys.exec_prefix = ''
sys.path = [
'/Users/mac.fede/Documents/GitHub/PageDownloader/PageDownloader.app/Contents/Resources/base_library.zip',
'/Users/mac.fede/Documents/GitHub/PageDownloader/PageDownloader.app/Contents/Resources/lib-dynload',
'/Users/mac.fede/Documents/GitHub/PageDownloader/PageDownloader.app/Contents/Resources',
]
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 0x000000010c0cfe00 (most recent call first):
<no Python frame>
Other posts on StackOverflow like this : Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding, when trying to start uwsgi
Suggests to remove the PYTHONHOME environment variable but I don't know how to do it. I can see that it's set and shouldn't. I did some researches on the internet but I didn't understand how to do this on Mac. I already tried :
unset PYTHONPATH
unset PYTHONHOME
Before launching the executable file but same error.
Now, I don't know if this is the right way to create an exportable application from python program on MacOS, I'm trying to figure it out so all this solution is "home made". If you have any suggestion I would be very happy to hear it.
With "exportable" I mean an application that I can share with my friends or other people and runnable with a double click.
I am trying to start my uwsgi server in my virtual environment, but after I added plugin python3 option I get this error every time:
!!! Python Home is not a directory: /home/env3/educ !!!
Set PythonHome to /home/env3/educ
Python path configuration:
PYTHONHOME = '/home/env3/educ'
PYTHONPATH = (not set)
program name = '/home/env3/educ/bin/python'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = '/home/env3/educ/bin/python'
sys.base_prefix = '/home/env3/educ'
sys.base_exec_prefix = '/home/env3/educ'
sys.executable = '/home/env3/educ/bin/python'
sys.prefix = '/home/env3/educ'
sys.exec_prefix = '/home/env3/educ'
sys.path = [
'/home/env3/educ/lib/python38.zip',
'/home/env3/educ/lib/python3.8',
'/home/env3/educ/lib/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 0x00007efe89db8780 (most recent call first):
<no Python frame>
Also I tried to create new virtual environment using python3 -m venv env and moved project files to it, but still the same error.
Here is my uwsgi.ini file:
[uwsgi]
base = /home/env3/educ
projectname = educ
plugins = python3
master = true
virtualenv = /home/env3/%(projectname)
pythonpath = %(base)
env = DJANGO_SETTINGS_MODULE=%(projectname).settings.pro
module = %(projectname).wsgi:application
socket = /tmp/%(projectname).sock
chmod-socket = 666
I use Python 3.8.5
I am trying to use Django + uWSGI + nginx + Postgresql.
I see your PYTHONHOME is set to PYTHONHOME = '/home/env3/educ'. Try to check if it is really there.
The solution for me was to remove the PYTHONHOME environment variable.
For you, it can be just that, or setting that variable to another value.
This worked on Windows, and would work on Linux for sure. If someone tries this, please post a comment here !
A CPython developer confirmed the solution here. :
This is not a Python bug, this is a symptom of setting PYTHONHOME and/or PYTHONPATH when they’re not needed. In nearly all cases you don’t need to set either of them;
In the case of PYTHONHOME it’s almost always a mistake to set.
I solve this problem by unsetting PYTHONHOME or PYTHONPATH, because they override the virtual environment variables.
In my case this is caused by my admin's base environment. I would try removing PYTHONHOME and PYTHONPATH variables by doing
unset PYTHONPATH
unset PYTHONHOME
This message is for those with the same problem who will find this page later.
I couldn't start uWSGI with my config, and I had the same message in logging files.
init_fs_encoding: failed to get the Python codec of the filesystem
encoding Python runtime state: core initialized ModuleNotFoundError:
No module named 'encodings'
The problem was uWSGI didn't have enough permissions to access the virtual environment. When I fixed the permissions, uWSGI started my config.
Denys posted the uwsgi.ini config in his message. I guess the path to the virtual environment is wrong.
base = /home/env3/educ
projectname = educ
virtualenv = /home/env3/%(projectname)
If the virtual environment was created in the project directory, then the path should look like this:
virtualenv = /home/env3/%(projectname)/env
The cause of the problem in my case was in the setting of virtualenv. Under linux system, the path to virtualenv starts very likely as /home/(your login username)/env3/, not /home/env3/. So before you try other solutions, you had better make sure the path to your virtualenv is correct.
In my case, I had to remove home= variable and it fixed the issue.
try using http=127.0.0.1:8000 in uwsgi.ini file.
that solved my problem.
in my case I did not unset the pythonhome, pythonpath
Just simply type this in cygwin terminal:
python.exe setup.py install (take note of the ".exe")
I have installed Python 2.6.7 in $HOME/local of a machine which already has a default Python in /usr (I don't have admin access on this machine). The default Python is compiled in 32bits and my local installation is a 64bits. For some unknown reasons my local Python library (which I call as an embedded python interpreter from within a C program) search for the modules in the default (wrong) installation.
This is the result of "import random"
Traceback (most recent call last):
File "test.py", line 3, in <module>
import random
File "/tmp/work/mdorier1/local/lib/python2.6/random.py", line 45, in <module>
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
ImportError: /usr/lib/python2.6/lib-dynload/math.so: wrong ELF class: ELFCLASS32
As you can see, the import statement correctly search "random.py" in the local installation of Python, but the import statement in random.py go search for math.so in the wrong location, which ends in an error since the default location has 32 bits modules.
I guessed there is a problem with an environment variable, and I tried
import sys
sys.path
to get
['/tmp/work/mdorier1/local/lib/python26.zip',
'/tmp/work/mdorier1/local/lib/python2.6',
'/tmp/work/mdorier1/local/lib/python2.6/plat-linux2',
'/tmp/work/mdorier1/local/lib/python2.6/lib-tk',
'/tmp/work/mdorier1/local/lib/python2.6/lib-old',
'/usr/lib/python2.6/lib-dynload',
'/tmp/work/mdorier1/local/lib/python2.6/site-packages']
I noticed that on of the paths indeed points to the default installation of Python. My questions thus are:
- Why this path shows up here, as the local installation has nothing to do with the default one?
- How do I change it (in a clean and permanent way)? This path should be the path to lib-dynload in the local installation instead.
Thanks
You probably don't have your Python's bin directory in the PATH variable before the system Python.
Or perhaps you simply compiled your Python incorrectly and did not use:
./configure --prefix=/tmp/work/mdorier1/local
so now it thinks that its files are somewhere else.