Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pythonnet could not loaded on other PC #7412

Closed
bls-lehoai opened this issue Feb 2, 2023 · 7 comments
Closed

Pythonnet could not loaded on other PC #7412

bls-lehoai opened this issue Feb 2, 2023 · 7 comments

Comments

@bls-lehoai
Copy link

I get this error when running our packaged app on other PC:

[6260] LOADER: Running main.py
Traceback (most recent call last):
  File "main.py", line 11, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "routers\script_router.py", line 9, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "services\xxxx_service.py", line 10, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "repositories\yyyy_repository.py", line 6, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "clr.py", line 6, in <module>
  File "pythonnet\__init__.py", line 143, in load
  File "clr_loader\types.py", line 64, in __call__
RuntimeError: cannot call null pointer pointer from cdata 'int(*)(void *, int)'
[6260] Failed to execute script 'main' due to unhandled exception!
[6260] LOADER: OK.
[6260] LOADER: Manually flushing stdout and stderr
[6260] LOADER: Cleaning up Python interpreter.

this line : File "repositories\yyyy_repository.py", line 6, in is:
import clr

I've tried many ways but didn't work. There are some PC when I unblock dll file (python.runtime.dll, etc..) then it worked, but there are some PC don't (i also tested it on windows 11). I'm pretty sure it is related to security.

@bls-lehoai bls-lehoai added the triage Please triage and relabel this issue label Feb 2, 2023
@rokm rokm added solution:not enough info Not enough info has been provided to solve or help. Fill out the issue template and removed triage Please triage and relabel this issue labels Feb 5, 2023
@rokm
Copy link
Member

rokm commented Feb 5, 2023

If it is related to security (e.g., your local security policy preventing program from loading collected DLLs, or your anti-virus program blocking them), there's nothing we can really do about it.

Same goes for cases when .NET runtime is missing on the target machine. What .NET runtime are you supposed to be using? Unless specified via PYTHONNET_RUNTIME, pythonnet seems to be using the legacy .NET framework by default. Do you have that installed on the target machines?

@rokm rokm closed this as not planned Won't fix, can't repro, duplicate, stale Feb 5, 2023
@bls-lehoai
Copy link
Author

@rokm
I found that if my application folder path has special Japanese characters then an error happens.
Move to the normal English name folder then it works!
I don't know why, no clue at all :(

@rokm
Copy link
Member

rokm commented Feb 15, 2023

Does this happen with just Japanese characters, or any non-ASCII character?

Can you provide a minimal example that triggers the error for you? E.g., is error triggered by

import clr
print("Hello world!")

or does it require some additional code (like explicitly choosing particular runtime before importing clr)?

@bls-lehoai
Copy link
Author

@rokm
I've tried to create a main.py with your sample code and running pyinstaller main.py, then moving the binary to the folder:
D:\アプリ\あのた   bb\main

then run main.exe:
image

@rokm
Copy link
Member

rokm commented Feb 16, 2023

OK, I've reproduced the problem. Let's reopen this until I figure whether it's our bug or not.

@rokm rokm reopened this Feb 16, 2023
@rokm rokm removed the solution:not enough info Not enough info has been provided to solve or help. Fill out the issue template label Feb 16, 2023
@rokm
Copy link
Member

rokm commented Feb 16, 2023

I don't think this is our bug, because I can reproduce the same error with pythonnet installed in a virtual environment that is located in a path that contains non-ASCII characters.

E.g., trying to run this code:

import sys

if len(sys.argv) > 1 and sys.argv[1] == 'coreclr':
    # Use .NET core runtime
    from clr_loader import get_coreclr
    from pythonnet import set_runtime
    set_runtime(get_coreclr())
else:
    # Use .NET framework runtime - this is the default
    #from clr_loader import get_netfx
    #from pythonnet import set_runtime
    #set_runtime(get_netfx())
    pass

import clr

from System import String
s = String("Hello world!")
print(s)

fails with (the default) .NET Framework runtime:

(venv) C:\Users\Rok\Development\pyi-pythonnet>python program.py
Traceback (most recent call last):
  File "C:\Users\Rok\Development\pyi-pythonnet\program.py", line 15, in <module>
    import clr
  File "C:\Users\Rok\Development\pyi-pythonnet\dir-čšž\venv\lib\site-packages\clr.py", line 6, in <module>
    load()
  File "C:\Users\Rok\Development\pyi-pythonnet\dir-čšž\venv\lib\site-packages\pythonnet\__init__.py", line 143, in load
    if func(b"") != 0:
  File "C:\Users\Rok\Development\pyi-pythonnet\dir-čšž\venv\lib\site-packages\clr_loader\types.py", line 64, in __call__
    return self._callable(ffi.cast("void*", buf_arr), len(buf_arr))
RuntimeError: cannot call null pointer pointer from cdata 'int(*)(void *, int)'

but works with the .NET Core runtime:

(venv) C:\Users\Rok\Development\pyi-pythonnet>python program.py coreclr
Hello world!

Which seems to imply that either pythonnet's path handling in netfx codepath is problematic, or perhaps that .NET Framework itself has problems with non-ASCII paths. Either way, nothing we can do about that.

If switching to .NET Core runtime is an option for you, you could do that to take care of non-ASCII paths.

@rokm rokm closed this as completed Feb 16, 2023
@bls-lehoai
Copy link
Author

@rokm
Thanks for your support.
it turns out that Pythonet 3.0 didn't work well. I have to revert to 2.xx version then it works! have no idea why

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants