Title: ModuleNotFoundError: No module named 'encodings' when trying to use virtual environment in C# app on Ubuntu · Issue #2548 · pythonnet/pythonnet · GitHub
Open Graph Title: ModuleNotFoundError: No module named 'encodings' when trying to use virtual environment in C# app on Ubuntu · Issue #2548 · pythonnet/pythonnet
X Title: ModuleNotFoundError: No module named 'encodings' when trying to use virtual environment in C# app on Ubuntu · Issue #2548 · pythonnet/pythonnet
Description: Environment: Ubuntu 24.04.1 LTS .NET SDK 8.0.112 Python 3.12.3 Details: Trying to run some Python in a C# app. This is my code: Runtime.PythonDLL = @"/usr/lib/x86_64-linux-gnu/libpython3.12.so"; string pathToVirtualEnv = @"/home/jadan/ve...
Open Graph Description: Environment: Ubuntu 24.04.1 LTS .NET SDK 8.0.112 Python 3.12.3 Details: Trying to run some Python in a C# app. This is my code: Runtime.PythonDLL = @"/usr/lib/x86_64-linux-gnu/libpython3.12.so"; st...
X Description: Environment: Ubuntu 24.04.1 LTS .NET SDK 8.0.112 Python 3.12.3 Details: Trying to run some Python in a C# app. This is my code: Runtime.PythonDLL = @"/usr/lib/x86_64-linux-gnu/libpython3.12.so...
Opengraph URL: https://github.com/pythonnet/pythonnet/issues/2548
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ModuleNotFoundError: No module named 'encodings' when trying to use virtual environment in C# app on Ubuntu","articleBody":"**Environment:**\n\n- Ubuntu 24.04.1 LTS\n- .NET SDK 8.0.112\n- Python 3.12.3\n\n**Details:**\n\nTrying to run some Python in a C# app. This is my code: \n\n```\nRuntime.PythonDLL = @\"/usr/lib/x86_64-linux-gnu/libpython3.12.so\";\n\nstring pathToVirtualEnv = @\"/home/jadan/venvs/venv_mare\";\n\nstring path = Environment.GetEnvironmentVariable(\"PATH\")!.TrimEnd(Path.PathSeparator);\npath = string.IsNullOrEmpty(path) ? pathToVirtualEnv : path + Path.PathSeparator + pathToVirtualEnv;\nEnvironment.SetEnvironmentVariable(\"PATH\", path, EnvironmentVariableTarget.Process);\nEnvironment.SetEnvironmentVariable(\"PYTHONHOME\", pathToVirtualEnv, EnvironmentVariableTarget.Process);\nEnvironment.SetEnvironmentVariable(\"PYTHONPATH\",\n $\"{pathToVirtualEnv}/lib/site-packages{Path.PathSeparator}\" + \n $\"{pathToVirtualEnv}{Path.PathSeparator}\", EnvironmentVariableTarget.Process);\n\nPythonEngine.PythonPath = PythonEngine.PythonPath + Path.PathSeparator + Environment.GetEnvironmentVariable(\"PYTHONPATH\", EnvironmentVariableTarget.Process);\nPythonEngine.PythonHome = pathToVirtualEnv;\n\nPythonEngine.Initialize();\n\nusing (Py.GIL())\n{\n dynamic np = Py.Import(\"numpy\");\n}\n```\n\nUnfortunately, this give the following error: \n\n```\nPython path configuration:\n PYTHONHOME = '/home/jadan/venvs/venv_mare'\n PYTHONPATH = (not set)\n program name = 'python3'\n isolated = 0\n environment = 1\n user site = 1\n safe_path = 0\n import site = 1\n is in build tree = 0\n stdlib dir = ''\n sys._base_executable = '/usr/bin/python3'\n sys.base_prefix = ''\n sys.base_exec_prefix = ''\n sys.platlibdir = 'lib'\n sys.executable = '/usr/bin/python3'\n sys.prefix = ''\n sys.exec_prefix = ''\n sys.path = [\n '',\n '/home/jadan/venvs/venv_mare/lib/python3.12/site-packages',\n '/home/jadan/venvs/venv_mare',\n '',\n ]\nFatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding\nPython runtime state: core initialized\nModuleNotFoundError: No module named 'encodings'\n```\n\nCan someone help me?","author":{"url":"https://github.com/JelleAdan","@type":"Person","name":"JelleAdan"},"datePublished":"2025-02-12T15:57:29.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/2548/pythonnet/issues/2548"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:fcc73329-3ab9-db6b-cd44-fdccaf24dc10 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DC9E:11B887:10BA264:16567F2:69702DB1 |
| html-safe-nonce | 4258f8089bcdc11b41907f9ad3b06de20756067052381d3498ade2f155c886a5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzlFOjExQjg4NzoxMEJBMjY0OjE2NTY3RjI6Njk3MDJEQjEiLCJ2aXNpdG9yX2lkIjoiNTIzMjQ1MjAyMzAzNzczNDMyMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 271723f07809a89ce532b7c6f25ecb27cca9b3cf1ef175776d7e0db1ba224b68 |
| hovercard-subject-tag | issue:2848680703 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pythonnet/pythonnet/2548/issue_layout |
| twitter:image | https://opengraph.githubassets.com/195f2ec89cadacc116f71f3b31050b54d1d179017ddbb743eff1f1ad90fcaece/pythonnet/pythonnet/issues/2548 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/195f2ec89cadacc116f71f3b31050b54d1d179017ddbb743eff1f1ad90fcaece/pythonnet/pythonnet/issues/2548 |
| og:image:alt | Environment: Ubuntu 24.04.1 LTS .NET SDK 8.0.112 Python 3.12.3 Details: Trying to run some Python in a C# app. This is my code: Runtime.PythonDLL = @"/usr/lib/x86_64-linux-gnu/libpython3.12.so"; st... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JelleAdan |
| hostname | github.com |
| expected-hostname | github.com |
| None | 01fa379f5de85ef8e791d09724e69709ce9eb9595278316e0a921312dc88e0bc |
| turbo-cache-control | no-preview |
| go-import | github.com/pythonnet/pythonnet git https://github.com/pythonnet/pythonnet.git |
| octolytics-dimension-user_id | 6050430 |
| octolytics-dimension-user_login | pythonnet |
| octolytics-dimension-repository_id | 14748123 |
| octolytics-dimension-repository_nwo | pythonnet/pythonnet |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14748123 |
| octolytics-dimension-repository_network_root_nwo | pythonnet/pythonnet |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | dda91974c069382b0dfa47b2da7e28bd061c8331 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width