Python Forum
[CPython] Can't run script python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[CPython] Can't run script python
#1
Hi all,

I have a problem need your help.
Thanks in advance.

1. Context:
I customized source code CPython 3.9.6 (https://www.python.org/downloads/release/python-396/)
In detailed, instead of reading directories from config, i fixed some directories sys._base_executable = '/', sys.base_prefix = '/mfp', sys.base_exec_prefix = '/mfpsys',...

2. Problem
I run into a problem when run script Python. I got the following log
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = '/'
sys.base_prefix = '/mfpsys'
sys.base_exec_prefix = '/mfpsys'
sys.platlibdir = 'lib'
sys.executable = '/'
sys.prefix = '/mfpsys'
sys.exec_prefix = '/mfpsys'
sys.path = [
'/site-packages',
'/mfpsys/lib/python3.9',
'/mfpsys/lib/python3.9/lib-dynload',
'/mfpsys/lib/python3.9/site-packages',
]
LookupError: no codec search functions registered: can't find encoding

I have investigated in source code Python 3.9.6, found the related source code show above error log.

\Python-3.9\Python\codecs.c
PyObject* _PyCodec_Lookup(const char* encoding)
{
...
const Py_ssize_t len = PyList_Size(interp->codec_search_path);

if (len == 0) {
PyErr_SetString(PyExc_LookupError,
"no codec search functions registered: "
"can't find encoding");
goto onError;
}
...
}

I have no idea to this problem. Please give me your kind suggestion.
Reply
#2
Clearly the list interp->codec_search_path is empty and the code expected this list to have been populated by some other part of the code. I suggest to grep codec_search_path in the source tree to find where it should be populated.

Apart from that, the value '/' for sys.executable looks invalid because this variable normally contains the path to the python command.
Reply
#3
(May-21-2022, 04:21 PM)Gribouillis Wrote: Clearly the list interp->codec_search_path is empty and the code expected this list to have been populated by some other part of the code. I suggest to grep codec_search_path in the source tree to find where it should be populated.

Apart from that, the value '/' for sys.executable looks invalid because this variable normally contains the path to the python command.

Thanks for your suggestion.

I have found the following logic to append value to codec_search_path.
int PyCodec_Register(PyObject *search_function)
{
...
return PyList_Append(interp->codec_search_path, search_function); // <==== Set breakpoint
...
}

Tried setting breakpoint here, but it does not hit. It seems there is something wrong causes logic of append is not called.
I'm working on it.
Gribouillis likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,008 Jun-29-2023, 11:57 AM
Last Post: gologica
  ImportError: /home/ali/Documents/test/charm/core/crypto/AES.cpython-39-x86_64-linux-g Anldra12 0 1,209 Apr-28-2022, 07:13 AM
Last Post: Anldra12
  Reducing runtime memory usage in Cpython interpreter david_the_graower 2 2,175 Oct-18-2021, 09:56 PM
Last Post: david_the_graower
  Navigating cpython source using python quazirfan 3 1,985 Aug-09-2021, 07:52 PM
Last Post: quazirfan
  IronPython from CPython amasis 3 2,156 Feb-05-2021, 12:26 PM
Last Post: jefsummers
  ImportError: /home/pybind11_example.cpython-37m-x86_64-linux-gnu.so: undefined symbol chaitra 2 5,026 Feb-03-2021, 05:14 AM
Last Post: chaitra
  How to kill a bash script running as root from a python script? jc_lafleur 4 5,789 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,248 May-28-2020, 05:27 PM
Last Post: micseydel
  compiled cpython output wrong version bigrockcrasher 0 1,480 Feb-25-2020, 06:31 PM
Last Post: bigrockcrasher
  Package python script which has different libraries as a single executable or script tej7gandhi 1 2,583 May-11-2019, 08:12 PM
Last Post: keames

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020