Closed link89 closed 1 year ago
can fix by change the _get_callable() function to this
import locale
def _get_callable(self, assembly_path: StrOrPath, typename: str, function: str):
encoding = "gbk" if locale.getpreferredencoding() == "cp936" else "utf8"
func = _FW.pyclr_get_function(
self._domain,
str(Path(assembly_path)).encode(encoding),
typename.encode("utf8"),
function.encode("utf8"),
)
Environment
Details
I find that everything just works fine if Python path doesn't contains any Chinese characters. But if the path contain some Chinese chars, let's said, start a python interactive shell via the following command:
And then when I run
import clr
, the following error will be raised.I delivery a software that provide a GUI depends on pythonnet, this become an annoy bug as user may choose their own installation location, which may contain Chinese chars. Hope to find a fix or a work around.
Update:
I try to narrow down the scope of code to
https://github.com/pythonnet/clr-loader/blob/master/clr_loader/netfx.py#L36-L44
It looks to me like the
_get_callable
failed to get the right callabe object by the following args