-
Notifications
You must be signed in to change notification settings - Fork 770
Closed
Description
Environment
- Pythonnet version:2.0.21
- Python version: 3.10.11
- Operating System: Ubuntu 2210
- .NET Runtime: 6.0.412
Details
- ModuleNotFoundError: No module named 'encodings' in linux
This error occurs in virtualenv and conda, and has not been tested in other ways. (Initialized successfully in windows.)
- error message:
/opt/miniconda3/envs/py310/lib/python310.zip;/opt/miniconda3/envs/py310/lib/python3.10;/opt/miniconda3/envs/py310/lib/python3.10/lib-dynload;/opt/miniconda3/envs/py310/lib/python3.10/site-packages;~/.local/lib/python3.10/site-packages
Python path configuration:
PYTHONHOME = '/opt/miniconda3/envs/py310/bin/python'
PYTHONPATH = (not set)
program name = 'python3'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = '/opt/miniconda3/envs/py310/bin/python3'
sys.base_prefix = ''
sys.base_exec_prefix = ''
sys.platlibdir = 'lib'
sys.executable = '/opt/miniconda3/envs/py310/bin/python3'
sys.prefix = ''
sys.exec_prefix = ''
sys.path = [
'/opt/miniconda3/envs/py310/lib/python310.zip;/opt/miniconda3/envs/py310/lib/python3.10;/opt/miniconda3/envs/py310/lib/python3.10/lib-dynload;/opt/miniconda3/envs/py310/lib/python3.10/site-packages;~/.local/lib/python3.10/site-packages',
]
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 0x00007f348e961740 (most recent call first):
<no Python frame>
- export PYTHONPATH & run
export PYTHONPATH="/opt/miniconda3/envs/py310/lib/python310.zip;/opt/miniconda3/envs/py310/lib/python3.10;/opt/miniconda3/envs/py310/lib/python3.10/lib-dynload;/opt/miniconda3/envs/py310/lib/python3.10/site-packages;~/.local/lib/python3.10/site-packages"
- result:
/opt/miniconda3/envs/py310/lib/python310.zip;/opt/miniconda3/envs/py310/lib/python3.10;/opt/miniconda3/envs/py310/lib/python3.10/lib-dynload;/opt/miniconda3/envs/py310/lib/python3.10/site-packages;~/.local/lib/python3.10/site-packages
Python path configuration:
PYTHONHOME = '/opt/miniconda3/envs/py310/bin/python'
PYTHONPATH = '/opt/miniconda3/envs/py310/lib/python310.zip;/opt/miniconda3/envs/py310/lib/python3.10;/opt/miniconda3/envs/py310/lib/python3.10/lib-dynload;/opt/miniconda3/envs/py310/lib/python3.10/site-packages;~/.local/lib/python3.10/site-packages'
program name = 'python3'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = '/opt/miniconda3/envs/py310/bin/python3'
sys.base_prefix = ''
sys.base_exec_prefix = ''
sys.platlibdir = 'lib'
sys.executable = '/opt/miniconda3/envs/py310/bin/python3'
sys.prefix = ''
sys.exec_prefix = ''
sys.path = [
'/opt/miniconda3/envs/py310/lib/python310.zip;/opt/miniconda3/envs/py310/lib/python3.10;/opt/miniconda3/envs/py310/lib/python3.10/lib-dynload;/opt/miniconda3/envs/py310/lib/python3.10/site-packages;~/.local/lib/python3.10/site-packages',
]
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 0x00007fe65d843740 (most recent call first):
<no Python frame>
string winPath = @"D:\tools\python310";
string linuxPath = "/opt/miniconda3/envs/py310";
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
string pathToVirtualEnv = winPath;
Runtime.PythonDLL = Path.Combine(pathToVirtualEnv, "python310.dll");
PythonEngine.PythonHome = Path.Combine(pathToVirtualEnv, "python.exe");
PythonEngine.PythonPath = @$"{pathToVirtualEnv}\Lib\site-packages;{pathToVirtualEnv}\Lib;{pathToVirtualEnv}\DLLs";
}
else if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
//Virtualenv
var pathToVirtualEnv = "/opt/miniconda3/envs/py310";
Runtime.PythonDLL = $"{pathToVirtualEnv}/lib/libpython3.10.so";
var path = Environment.GetEnvironmentVariable("PATH").TrimEnd(';');
path = string.IsNullOrEmpty(path) ? pathToVirtualEnv : path + ";" + pathToVirtualEnv;
Environment.SetEnvironmentVariable("PATH", path, EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("PATH", pathToVirtualEnv, EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("PYTHONHOME", pathToVirtualEnv, EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("PYTHONPATH", $"{pathToVirtualEnv}/lib/python310.zip;{pathToVirtualEnv}/lib/python3.10;{pathToVirtualEnv}/lib/python3.10/lib-dynload;{pathToVirtualEnv}/lib/python3.10/site-packages;~/.local/lib/python3.10/site-packages", EnvironmentVariableTarget.Process);
var pythonpath = Environment.GetEnvironmentVariable("PYTHONPATH", EnvironmentVariableTarget.Process);;
Console.WriteLine(pythonpath);
PythonEngine.PythonHome = $"{pathToVirtualEnv}/bin/python";
PythonEngine.PythonPath = pythonpath;
} else {
Console.WriteLine("This OS is not support");
return;
}
PythonEngine.Initialize();Metadata
Metadata
Assignees
Labels
No labels