Skip to content

Cythonized python.net code cannot find system assemblies #941

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

Open
crayxt opened this issue Aug 16, 2019 · 6 comments
Open

Cythonized python.net code cannot find system assemblies #941

crayxt opened this issue Aug 16, 2019 · 6 comments

Comments

@crayxt
Copy link

crayxt commented Aug 16, 2019

Dup of my SO question https://stackoverflow.com/questions/57493309/cythonized-python-net-code-cannot-find-system-assemblies

When I compile the python code which uses python.net to access .Net assemblies, it can't find those assemblies. Without compilation it works ok.

For demo code, I used https://github.com/pythonnet/pythonnet/blob/master/demo/helloform.py

My setup.py file

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize

ext_modules = [
    Extension(
        'helloform',
        sources = ['helloform.py'],
        language = 'c++'
      )
]

setup(
  name = 'helloform',
  ext_modules = cythonize(ext_modules),
)

Then I build it with python setup.py build_ext --inplace.

I wanted to load compiled module from Python prompt with import helloform but it failed with

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "helloform.py", line 8, in init helloform
ModuleNotFoundError: No module named 'System'
@filmor
Copy link
Member

filmor commented Aug 28, 2019

I'd guess that cython handles __import__ by itself in some way that is incompatible with our hook. Not much we can do about this until #727 is implemented.

@donno
Copy link

donno commented Nov 14, 2019

Could the functionality that drives the import override be provided via a named function that can be called? For example, System = clr.ImportModule('System')

Or possibly using the return value of clr.AddReference(...), i.e that turns the System.RuntimeType into the ModuleObject (and also register it under clr, i.e clr.System).

@filmor
Copy link
Member

filmor commented Nov 14, 2019

It could and it should, good idea.

@crayxt
Copy link
Author

crayxt commented May 24, 2021

Dear all, is there any news on this subject? thanks,

@Anderu123
Copy link

Anderu123 commented Feb 12, 2022

Could the functionality that drives the import override be provided via a named function that can be called? For example, System = clr.ImportModule('System')

Or possibly using the return value of clr.AddReference(...), i.e that turns the System.RuntimeType into the ModuleObject (and also register it under clr, i.e clr.System).

Could the functionality that drives the import override be provided via a named function that can be called? For example, System = clr.ImportModule('System')

Or possibly using the return value of clr.AddReference(...), i.e that turns the System.RuntimeType into the ModuleObject (and also register it under clr, i.e clr.System).

Hi sir, could you kindly show me examples of how to retrieve/use the method/function out of ModuleObject, cause I kept attribute error out of it, appreciate it alot.

Like how to invoke Byte, Array out of System, thank you very much in advanced.

@josephernest
Copy link

Could the functionality that drives the import override be provided via a named function that can be called? For example, System = clr.ImportModule('System')

Good idea. Is this feature available? Do you know where in the source code of clr is done this import override?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants