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.
Related
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"
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 using py 3.6 and whenever i type this:
import wmi
def avg(value_list):
num = 0
length = len(value_list)
for val in value_list:
num += val
return num/length
w = wmi.WMI(namespace=r"C:\Users\name\Desktop\OpenHardwareMonitor")
sensors = w.Sensor()
cpu_temps = []
gpu_temp = 0
for sensor in sensors:
if sensor.SensorType==u'Temperature' and not 'GPU' in sensor.Name:
cpu_temps += [float(sensor.Value)]
elif sensor.SensorType==u'Temperature' and 'GPU' in sensor.Name:
gpu_temp = sensor.Value
print("Avg CPU: {}").format(avg(cpu_temps))
print("GPU: {}").format(gpu_temp)
it comes out as:
PS C:\Users\name> & C:/Users/name/AppData/Local/Programs/Python/Python36/python.exe "c:/Users/name/gpu temps.py"
Traceback (most recent call last):
File "c:/Users/name/pip install gpiozero.py", line 1, in <module>
import wmi
ModuleNotFoundError: No module named 'wmi'
i went through alot of the options on the web and 1 other post and went through all the options, including " pywin32-300.win-amd64-py3.6.exe" on https://github.com/mhammond/pywin32/releases...
still doesnt work
In regards to the details given in the comments.
What I would generally suggest is to create virtual environments for each python project you have.
in visual studio code here is how you could do it:
Open your project folder with VS-Code
open the terminal inside VS-Code
execute C:\Users\name\AppData\Local\Programs\Python\Python36\python.exe -m venv env (or the path to your python installation you'd like to create a virtual environment of)
activate your enviornment by entering . .\env\Scripts\Activate.ps1 (assuming windows, you might need to enter Set-ExecutionPolicy Unrestricted -Scope Process to allow execution
now you should have a little (env) shown in the terminal, indicatung you're using the virtual environment.
next you can enter all the pip install commands you need for your project.
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")
Note: I'm on Windows using Git Bash.
So, I am trying to setup a dev environment for the work for my class. It is going to involve a combination of coding in R and Python.
I created virtual environments using pipenv and virtualenv and ran into the same problem with both. So, first, let's create a virtual environment for the project in a sub-folder dev_env:
cd project_folder/dev_env
pipenv --python 3.7
pipenv --py
Output
C:\Users\Ra Me\.virtualenvs\dev_env-5TUtSZI9\Scripts\python.exe
Now I'm going into my file.rmd and trying the reticulate package.
#install.packages("reticulate")
library(reticulate)
Next, I tried 2 methods:
Sys.setenv(RETICULATE_PYTHON = "C:/Users/Ra Me/.virtualenvs/dev_env-5TUtSZI9/Scripts")
or
use_virtualenv("C:/Users/Ra Me/.virtualenvs/dev_env-5TUtSZI9/", required = TRUE)
x = 1
if x:
print('Hello!')
Both of them produced the error
Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
However, when I change the path to the Python environment that's installed for all users on my machine, it works.
Sys.setenv(RETICULATE_PYTHON = "C:/Program Files/Python37/")
This method also works. However, here we are not even using the reticulate project.
knitr::opts_chunk$set(engine.path = list(
python = "C:/Program Files/Python37/python.exe",
r = "C:/Program Files/R/R-3.6.1/bin/R.exe"
))