Fatal Error: init_fs_encoding: failed to get the Python codec of the filesystem encoding - centos7

Trying to run Python 3.11 on CentOS 7 and keep getting this error block anytime I invoke python3.11.
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = 'python3.11'
isolated = 0
environment = 1
user site = 1
safe_path = 0
import site = 1
is in build tree = 0
stdlib dir = '/usr/local/lib/python3.11'
sys._base_executable = '/usr/local/bin/python3.11'
sys.base_prefix = '/usr/local'
sys.base_exec_prefix = '/usr/local'
sys.platlibdir = 'lib'
sys.executable = '/usr/local/bin/python3.11'
sys.prefix = '/usr/local'
sys.exec_prefix = '/usr/local'
sys.path = [
'/usr/local/lib/python311.zip',
'/usr/local/lib/python3.11',
'/usr/local/lib/python3.11/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 0x00007f11582b4740 (most recent call first):
<no Python frame>
I have tried setting paths and deconflicting the references to other python versions on the device.

Related

python-for-android, Cython, C++, CythonRecipe: Operation only allowed in c++

I have this setup.py for my Cython project:
from setuptools import setup
from Cython.Build import cythonize
setup(
name = 'phase-engine',
version = '0.1',
ext_modules = cythonize(["phase_engine.pyx"] + ['music-synthesizer-for-android/src/' + p for p in [
'fm_core.cc', 'dx7note.cc', 'env.cc', 'exp2.cc', 'fm_core.cc', 'fm_op_kernel.cc', 'freqlut.cc', 'lfo.cc', 'log2.cc', 'patch.cc', 'pitchenv.cc', 'resofilter.cc', 'ringbuffer.cc', 'sawtooth.cc', 'sin.cc', 'synth_unit.cc'
]],
include_path = ['music-synthesizer-for-android/src/'],
language = 'c++',
)
)
when I run buildozer, it gets angry about some Cython features only being available in C++ mode:
def __dealloc__(self):
del self.p_synth_unit
^
------------------------------------------------------------
phase_engine.pyx:74:8: Operation only allowed in c++
from which I understand it's ignoring my setup.py and doing its own somehow. How do I give it all these parameters?
CythonRecipe doesn't work well for Cython code that imports C/C++ code. Try CompiledComponentsPythonRecipe, or if you're having issues with #include <ios> or some other thing from the C++ STL, CppCompiledComponentsPythonRecipe:
from pythonforandroid.recipe import IncludedFilesBehaviour, CppCompiledComponentsPythonRecipe
import os
import sys
class MyRecipe(IncludedFilesBehaviour, CppCompiledComponentsPythonRecipe):
version = 'stable'
src_filename = "../../../phase-engine"
name = 'phase-engine'
depends = ['setuptools']
call_hostpython_via_targetpython = False
install_in_hostpython = True
def get_recipe_env(self, arch):
env = super().get_recipe_env(arch)
env['LDFLAGS'] += ' -lc++_shared'
return env
recipe = MyRecipe()
The dependency on setuptools is essential because of some weird stuff, otherwise you get an error no module named setuptools. The two other flags were also related to that error, the internet said they're relevant so I tried value combinations until one worked.
The LDFLAGS thing fixes an issue I had later (see buildozer + Cython + C++ library: dlopen failed: cannot locate symbol symbol-name referenced by module.so).

Python Error : File ... spherical.py... import f_utils...ImportError: DLL load failed: The specified module could not be found

I am running some codes in python 2.7 with MIN-GW - gfortran of fortran77 codes and Visual Studio 2010.I installed all requirements with pip, so when I do this:
python setup.py install
everything is successful.
f2py -c f_utils.for
Creates
libf_utils.DLYOMDEGIW6SZRJNEZ2ZMRYPGQZ75ZH3.gfortran-win_amd64.dll in ..\untitled\.libs and untitled.pyd
but As python spherical.py install Now I get this error:
Traceback (most recent call last):
File "spherical.py", line 4, in <module>
import f_utils
ImportError: DLL load failed: The specified module could not be found.
So I am searching for a solution for that. Any help would be appreciated.
setup.py:
import os
import sys
...
import setuptools
from numpy.distutils.core import setup
def configuration(parent_package='', top_path=None, package_name=DISTNAME):
if os.path.exists('MANIFEST'): os.remove('MANIFEST')
from numpy.distutils.misc_util import Configuration
config = Configuration(package_name, parent_package, top_path,
version = VERSION,
maintainer = MAINTAINER,
maintainer_email = MAINTAINER_EMAIL,
description = DESCRIPTION,
license = LICENSE,
url = URL,
download_url = DOWNLOAD_URL,
long_description = LONG_DESCRIPTION)
config.set_options(
ignore_setup_xxx_py = True,
assume_default_configuration = True,
delegate_options_to_subpackages = True,
quiet = True,
)
config.add_extension('f_utils',
sources=[os.path.join('src', 'f_utils.for')]
)
return config
if __name__ == "__main__":
setup(configuration = configuration,
install_requires = 'numpy',
namespace_packages = ['scikits'],
packages = setuptools.find_packages(),
include_package_data = True,
#test_suite="tester", # for python setup.py test
zip_safe = True, # the package can run out of an .egg file
classifiers =
[ ...
first lines of my f_utils.for:
SUBROUTINE MAT_A0(NG,NN,Rad,Ang,coef,w,O)
INTEGER NG,NN
COMPLEX*16 Rad(NG,NN)
COMPLEX*16 Ang(NG,NN),coef(NG)
COMPLEX*16 O(NN,NN)
REAL*8 w(NG)
cf2py intent(in) Rad,Ang,coef,w
cf2py intent(out) O
cf2py intent(hide) NG,NN
INTEGER l,n,k
…
first lines of my spherical.py:
from numpy import *
from scipy.special.orthogonal import ps_roots
from scipy import special
import f_utils
…
def matA0(C,m,jh,i,coef):
Rad = C.Rad(m,jh,i)
Angm = C.Ang(m)
#func = lambda k: outer( Rad[k]*Angm[k], coef[k]*Angm[k])
#return mat_integrate(func)
return f_utils.mat_a0(Rad,Angm,coef,C.weights)
…
UPDATE #1:
1) As I want to run sample in https://docs.scipy.org/doc/numpy/f2py/getting-started.html , I uninstall These : Min-GW and python 2.7 and any visual Studio software's . So I cleaned all Files related to python 2.7
2) Then I install Visual Studio 2019 and Intel Parallel Studio 2019 and python 3.7.0 (64 bit) with checkmark for python path ,also install packages needed for python such as numpy
3) then set a Path to C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2019.4.228\windows\compiler\lib\intel64
4) then Do as the structure as in the https://docs.scipy.org/doc/numpy/f2py/getting-started.html for fib1, also set () for print function.
then everything is successful.
As I used instruction same as below with a little modification , spherical.py could execute successfully, with no errors.
1) As sample in https://docs.scipy.org/doc/numpy/f2py/getting-started.html , I uninstall These : Min-GW and python 2.7 and any visual Studio software's . So I cleaned all Files related to python 2.7
2) Then I install Visual Studio 2019 and Intel Parallel Studio 2019 and python 3.7.0 (64 bit) with checkmark for python path ,also install packages needed for python such as numpy
3) then set a Path to C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2019.4.228\windows\compiler\lib\intel64
4) then Do as the structure as in the https://docs.scipy.org/doc/numpy/f2py/getting-started.html for fib1, also set () for print function.
then everything is successful.

difficulties with cx_freeze setup for kivy with Python 2.7

I am trying to build a package for just a simple Python 2.7 + kivy 1.9.1 script using cx_freeze. Unfortunately I get the following error when executing the DoScroll.exe file:
File "C:\Utils\Pyhton27\lib\site-packages\kivy\lang.py", line 1829, in load_file
with open(filename, 'r') as fd:
IOError: [Errno 2] No such file or directory: 'C:\Projects\Testing\build\exe.win32-2.7\library.zip\kivy\data\style.kv'
The zip file does not contain the kivy\data folder. So my idea was to add the kivy package explicitly to the setup.py file. But this does not help.
How could I resolve this issue?
The setup.py file I am using:
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == "win32":
base = "Win32GUI"
options = {
'build_exe': {
'packages': ['kivy']
}
}
executables = [
Executable('DoScroll.py', base=base)
]
setup(name='scroller',
version='0.1',
description='demo scroller',
executables = executables,
options=options
)

Bundling GTK3+ with cx_freeze

Platform is Windows 7 64bit using python 2.7 and GTK3 installed from
http://games.2g2s.de/?page_id=223 and PyGobject from here
http://sourceforge.net/projects/pygobjectwin32/files/?source=navbar
I used the script provided on wiki:
from cx_Freeze import setup, Executable
import os, site, sys
## Get the site-package folder, not everybody will install
## Python into C:\PythonXX
site_dir = site.getsitepackages()[1]
include_dll_path = os.path.join(site_dir, "gtk")
## Collect the list of missing dll when cx_freeze builds the app
missing_dll = ['libgtk-3-0.dll',
'libgdk-3-0.dll',
'libatk-1.0-0.dll',
'libcairo-2.dll',
'libcairo-gobject-2.dll',
'libgdk_pixbuf-2.0-0.dll',
'libpango-1.0-0.dll',
'libpangocairo-1.0-0.dll',
'libpangoft2-1.0-0.dll',
'libpangowin32-1.0-0.dll',
'libffi-6.dll',
'libfontconfig-1.dll',
'libfreetype-6.dll',
'libgio-2.0-0.dll',
'libglib-2.0-0.dll',
'libgmodule-2.0-0.dll',
'libgobject-2.0-0.dll',
'libpng15-15.dll',
]
## We also need to add the glade folder, cx_freeze will walk
## into it and copy all the necessary files
glade_folder = 'glade'
## We need to add all the libraries too (for themes, etc..)
gtk_libs = ['etc', 'lib', 'share']
## Create the list of includes as cx_freeze likes
include_files = []
for dll in missing_dll:
include_files.append((os.path.join(include_dll_path, dll), dll))
## Let's add glade folder and files
include_files.append((glade_folder, glade_folder))
## Let's add gtk libraries folders and files
for lib in gtk_libs:
include_files.append((os.path.join(include_dll_path, lib), lib))
base = None
## Lets not open the console while running the app
if sys.platform == "win32":
base = "Win32GUI"
executables = [
Executable("materii.py",
base=base
)
]
buildOptions = dict(
compressed = False,
includes = ["gi"],
packages = ["gi"],
include_files = include_files
)
setup(
name = "test_gtk3_app",
author = "Gian Mario Tagliaretti",
version = "1.0",
description = "GTK 3 test",
options = dict(build_exe = buildOptions),
executables = executables
)
The exe is compiled but fails to run, due to this
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", in <module>
exec code in m.__dict__
File "materii.py", line 2, in <module>
File "C:\Python27\lib\site-packages\gi\__init__.py", line 27, in <module>
from ._gi import _API
File "ExtensionLoader_gi__gi.py", line 22, in <module>
File "ExtensionLoader_gi__gi.py", line 14, in __bootstrap__
ImportError: DLL load failed: The specified module could not be found.
Line 2 from materii.py is
from gi.repository import Gtk
Can you help me please?
Go to the gnome dir, which by itself is in the site-packages dir and manually copy all the .dll files (not the nested one) from this dir to your build/your-application-dir/ dir. And it will work.

uwsgi: no app loaded. going in full dynamic mode

In my uwsgi config, I have these options:
[uwsgi]
chmod-socket = 777
socket = 127.0.0.1:9031
plugins = python
pythonpath = /adminserver/
callable = app
master = True
processes = 4
reload-mercy = 8
cpu-affinity = 1
max-requests = 2000
limit-as = 512
reload-on-as = 256
reload-on-rss = 192
no-orphans
vacuum
My app structure looks like this:
/adminserver
app.py
...
My app.py has these bits of code:
app = Flask(__name__)
...
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5003, debug=True)
The result is that when I try to curl my server, I get this error:
Wed Sep 11 23:28:56 2013 - added /adminserver/ to pythonpath.
Wed Sep 11 23:28:56 2013 - *** no app loaded. going in full dynamic mode ***
Wed Sep 11 23:28:56 2013 - *** uWSGI is running in multiple interpreter mode ***
What do the module and callable options do? The docs say:
module, wsgi Argument: string
Load a WSGI module as the application. The module (sans .py) must be
importable, ie. be in PYTHONPATH.
This option may be set with -w from the command line.
callable Argument: string Default: application
Set default WSGI callable name.
Module
A module in Python maps to a file on disk - when you have a directory like this:
/some-dir
module1.py
module2.py
If you start up a python interpreter while the current working directory is /some-dir you will be able to import each of the modules:
some-dir$ python
>>> import module1, module2
# Module1 and Module2 are now imported
Python searches sys.path (and a few other things, see the docs on import for more information) for a file that matches the name you are trying to import. uwsgi uses Python's import process under the covers to load the module that contains your WSGI application.
Callable
The WSGI PEPs (333 and 3333) specify that a WSGI application is a callable that takes two arguments and returns an iterable that yields bytestrings:
# simple_wsgi.py
# The simplest WSGI application
HELLO_WORLD = b"Hello world!\n"
def simple_app(environ, start_response):
"""Simplest possible application object"""
status = '200 OK'
response_headers = [('Content-type', 'text/plain')]
start_response(status, response_headers)
return [HELLO_WORLD]
uwsgi needs to know the name of a symbol inside of your module that maps to the WSGI application callable, so it can pass in the environment and the start_response callable - essentially, it needs to be able to do the following:
wsgi_app = getattr(simple_wsgi, 'simple_app')
TL;PC (Too Long; Prefer Code)
A simple parallel of what uwsgi is doing:
# Use `module` to know *what* to import
import simple_wsgi
# construct request environment from user input
# create a callable to pass for start_response
# and then ...
# use `callable` to know what to call
wsgi_app = getattr(simple_wsgi, 'simple_app')
# and then call it to respond to the user
response = wsgi_app(environ, start_response)
For anyone else having this problem, if you are sure your configuration is correct, you should check your uWSGI version.
Ubuntu 12.04 LTS provides 1.0.3. Removing that and using pip to install 2.0.4 resolved my issues.
First, check your configuration whether is correct.
my uwsgi.ini configuration:
[uwsgi]
chdir=/home/air/repo/Qiy
uid=nobody
gid=nobody
module=Qiy.wsgi:application
socket=/home/air/repo/Qiy/uwsgi.sock
master=true
workers=5
pidfile=/home/air/repo/Qiy/uwsgi.pid
vacuum=true
thunder-lock=true
enable-threads=true
harakiri=30
post-buffering=4096
daemonize=/home/air/repo/Qiy/uwsgi.log
then use uwsgi --ini uwsgi.ini to run uwsgi.
if not work, you rm -rf the venv directory, and re-initial the venv, and re-try my step.
I re-initial the venv solved my issue, seems the problem is when I pip3 install some packages of requirements.txt, and upgrade the pip, then install uwsgi package. so, I delete the venv, and re-initial my virtual environment.