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: patch-diff.githubusercontent.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:d85b8cbe-7496-738c-76db-8652309587c7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A634:5A639:1180B3:17EB1B:696FCDDB |
| html-safe-nonce | f670d3651b57874c97485ff1c1b9b42a3272420b9311e2ad665020109b92f895 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNjM0OjVBNjM5OjExODBCMzoxN0VCMUI6Njk2RkNEREIiLCJ2aXNpdG9yX2lkIjoiMzYxMTU3NDUyNTY1MzY2NzI5MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8181f7654eae458ec61a525844465de972783a14352a16857e028e2369495504 |
| 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 | 0a44b41159f8508d767a50a41d4355b6e6607de801262664cbe75414886e44e9 |
| 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 | 347f3ebfaef84b36b267c7a20bade84594f267d5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width