Title: `getfilesystemencoding()` returns incorrect value on Linux · Issue #2664 · pythonnet/pythonnet · GitHub
Open Graph Title: `getfilesystemencoding()` returns incorrect value on Linux · Issue #2664 · pythonnet/pythonnet
X Title: `getfilesystemencoding()` returns incorrect value on Linux · Issue #2664 · pythonnet/pythonnet
Description: There seems to be a discrepancy between pythonnet and system-installed python when determining the file-system-encoding. This is my pythonnet code: Runtime.PythonDLL = "/usr/lib/x86_64-linux-gnu/libpython3.12.so"; PythonEngine.Initialize...
Open Graph Description: There seems to be a discrepancy between pythonnet and system-installed python when determining the file-system-encoding. This is my pythonnet code: Runtime.PythonDLL = "/usr/lib/x86_64-linux-gnu/li...
X Description: There seems to be a discrepancy between pythonnet and system-installed python when determining the file-system-encoding. This is my pythonnet code: Runtime.PythonDLL = "/usr/lib/x86_64-linux-g...
Opengraph URL: https://github.com/pythonnet/pythonnet/issues/2664
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`getfilesystemencoding()` returns incorrect value on Linux","articleBody":"There seems to be a discrepancy between pythonnet and system-installed python when determining the file-system-encoding.\n\nThis is my pythonnet code:\n\n```cs\n Runtime.PythonDLL = \"/usr/lib/x86_64-linux-gnu/libpython3.12.so\";\n PythonEngine.Initialize();\n PythonEngine.BeginAllowThreads();\n\n using (Py.GIL())\n {\n dynamic sys = Py.Import(\"sys\");\n Console.WriteLine(\"Filesystem encoding: {0}\", sys.getfilesystemencoding());\n Console.WriteLine(\"Default encoding: {0}\", sys.getdefaultencoding());\n }\n```\n\nWhich prints:\n\n```\nFilesystem encoding: ascii\nDefault encoding: utf-8\n```\n\nHowever, this is not correct! First, it only prints this on Linux. On windows, the filesystem-encoding is correctly determined to be 'utf-8'. Running a simple oneliner in python itself returns the correct values on both platforms:\n\n```\n$ python -c \"import sys; print(sys.getfilesystemencoding()); print(sys.getdefaultencoding())\"\nutf-8\nutf-8\n```\n\nThe python-version is 3.12.3, the dotnet version is 8.0.408 on both platforms as well.\n\nI've tried to work around this with environment variables, but those aren't recognized as expected, see https://github.com/pythonnet/pythonnet/discussions/2539#discussioncomment-15095791\n\nAnother option might be to call [`PySys_AddXOption`](https://docs.python.org/3.11/c-api/sys.html#c.PySys_AddXOption) with [\"utf8\" to set UTF-8 Mode manually](https://docs.python.org/3.11/library/os.html#utf8-mode:~:text=It%20can%20be%20enabled%20or%20disabled%20using%20the%20%2DX%20utf8%20command%20line%20option), but pythonnet has no binding for this function.\n\nI'm at a loss about what to do next. This seems like a genuine bug, so I opened this here instead of starting a discussion.","author":{"url":"https://github.com/iFreilicht","@type":"Person","name":"iFreilicht"},"datePublished":"2025-11-27T10:59:54.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/2664/pythonnet/issues/2664"}
| 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:587969af-ffb1-f44a-0ea2-93b18a3d2a5b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 852A:D2C73:1DE48EA:29B66AA:696FE945 |
| html-safe-nonce | b57ede43255d5f6d1db7392bebe0d5a5b03290835ec55277e82d1709913efbf7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NTJBOkQyQzczOjFERTQ4RUE6MjlCNjZBQTo2OTZGRTk0NSIsInZpc2l0b3JfaWQiOiIyMTg2ODEwMTc0MjE3MzgyMjEzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 941b6f5479ee6a281d56c3ff4975007a7567427f52b7dbdc14fbae2f055e7a92 |
| hovercard-subject-tag | issue:3670902206 |
| 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/2664/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1fcd97fad645df79eab2de00b6b0632b975a3f1fe3dc9f3b2527715ce2c99007/pythonnet/pythonnet/issues/2664 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1fcd97fad645df79eab2de00b6b0632b975a3f1fe3dc9f3b2527715ce2c99007/pythonnet/pythonnet/issues/2664 |
| og:image:alt | There seems to be a discrepancy between pythonnet and system-installed python when determining the file-system-encoding. This is my pythonnet code: Runtime.PythonDLL = "/usr/lib/x86_64-linux-gnu/li... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | iFreilicht |
| hostname | github.com |
| expected-hostname | github.com |
| None | bb7c872aa74896d911608183f4997f8b9c121a1624064705ec4570cd91bd7839 |
| 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 | 257e1b418957178bd3ac9f7520608a40ebbb0f1e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width