Replies: 3 comments
-
|
I just took over a code base and ran into the same issue. |
Beta Was this translation helpful? Give feedback.
-
|
There are two potential reasons for this: First (and most likely from what I've seen in the questions here) is that you're using The other potential problem is that you're missing some crucial parths in The way I resolved this was to just add to I'm not sure this is a great solution, but it sure does work. |
Beta Was this translation helpful? Give feedback.
-
|
Thank you, I'll give it a try
…------------------ 原始邮件 ------------------
发件人: ***@***.***>;
发送时间: 2025年11月27日(星期四) 下午4:22
收件人: ***@***.***>;
抄送: ***@***.***>; ***@***.***>;
主题: Re: [pythonnet/pythonnet] 'encodings' Error (Discussion #2619)
There are two potential reasons for this: First (and most likely from what I've seen in the questions here) is that you're using ; as a path separator when setting PythonEngine.PythonPath. This is correct on Windows, but on Linux you need to use :, see also #2217 (comment)
The other potential problem is that you're missing some crucial parths in PythonEngine.PythonPath. This can happen especially if you set this variable before calling PythonEngine.Initialize() as this will skip the default module search path discovery!
The way I resolved this was to just add to sys.path instead of overriding PythonEngine.PythonPath:
Runtime.PythonDLL = pythonDLLPath; PythonEngine.Initialize(); PythonEngine.BeginAllowThreads(); using (Py.GIL()) { dynamic sys = Py.Import("sys"); sys.path.append(singlePackagePath); sys.path.extend(multiplePackagePaths); Console.WriteLine("Python version: {0}", sys.version); Console.WriteLine("PythonPath: {0}", PythonEngine.PythonPath); Console.WriteLine("sys.path: {0}", sys.path); }
I'm not sure this is a great solution, but it sure does work.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Excuse me:
The encodings directory exists in the Lib directory of Conda's envs environment, and all the files inside also exist. Why does it still report an error?
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'
Beta Was this translation helpful? Give feedback.
All reactions