You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When generating a spammery.cpp file using cython --embed -3 spammery.pyx and compile it using gcc/g++ depending on whether I'm using C++ or C, running the executable I get ModuleNotFoundError at runtime even if I've added sys.path.append('.') or sys.path.append('') to the spammery.pyx file.
In addition, when I add import sys etc, the errorline cython cites is "import sys" (or I recon any statement before cimport) as the cause of ModuleNotFoundError, given that there any statements prior, in either case there's a runtime error.
I think that all cimports happen before anything else in the module, so will happen before your changes to sys.path. I don't think that's easy to change.
We should probably point to the right lines though when showing the error message.
I think that all cimports happen before anything else in the module, so will happen before your changes to sys.path. I don't think that's easy to change.
We should probably point to the right lines though when showing the error message.
Thanks for the response.
So is the behavior laid out in the design of Cython that it will by default allow import and cimport modules in sys.path default locations, but not in the current location?
Why is that, when Python by default will import not only anything in the current work directory but subdirectories etc if they have an __init__.py file and such?
Is it out of a security concern that Python doesn't seem to share, and could be easily bypassed by an evil module/program copying another evil module into a sys.path directory at runtime before importing?
It seems like such a strange design choice to me and not in compliance with how Python operates?
Describe the bug
#6514 (comment)
Take this example:
https://cython.readthedocs.io/en/latest/src/userguide/sharing_declarations.html#sharing-c-functions
When generating a spammery.cpp file using
cython --embed -3 spammery.pyx
and compile it using gcc/g++ depending on whether I'm using C++ or C, running the executable I get ModuleNotFoundError at runtime even if I've addedsys.path.append('.')
orsys.path.append('')
to the spammery.pyx file.In addition, when I add import sys etc, the errorline cython cites is "import sys" (or I recon any statement before cimport) as the cause of ModuleNotFoundError, given that there any statements prior, in either case there's a runtime error.
Code to reproduce the behaviour:
volume.pyx
volume.pxd
spammery.pyx
Expected behaviour
No compile or runtime errors.
OS
Debian 12 (bookworm)
Python version
3.11.2
Cython version
3.1.0a1
Additional context
No response
The text was updated successfully, but these errors were encountered: