"__file__" is not defined when packed up into a cython pyd

90 views
Skip to first unread message

John Mellencamp

unread,
Oct 19, 2023, 9:14:32 AM10/19/23
to cython-users
Good morning,
My name is Juan Cristóbal, from Spain.
We are packing up most of our libraries in python to a .pyd using cython 3.0.
Everything compiles ok and we are able to build up the dll/pyd.
But when importing the library, here comes trouble:
i get a "__file__" is not defined error.
We have lots of places where we use something like "os.path.dirname(__file__)" and alike.
My assumption is that the translated C __FILE__ works differently, which much probably be in use in the pyd.
My question is: is there an alternative to "__file__" and all the "inspect" module functions? (None of them are believed to be working in a Cython translated code).
We have many places in our code that make use of relative paths from a specific file.
So, using something like "__file__" but that works in a .pyd is more than welcome.

Thanks.

da-woods

unread,
Oct 19, 2023, 1:21:28 PM10/19/23
to cython...@googlegroups.com
In all cases, __file__ should work once module import has completed.

__file__ should work during module import provided you are using multi-phase 
init. That should be available on most recent versions of Python (>= 3.5). However, if may be turned off if you have manually set CYTHON_PEP489_MULTI_PHASE_INIT to 0 as part of your build process.
--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/4ee8fc78-66ec-4e61-a4f1-fb28933ad04an%40googlegroups.com.


John Mellencamp

unread,
Oct 24, 2023, 5:39:40 AM10/24/23
to cython-users
thanks! it worked like a charm!
Reply all
Reply to author
Forward
0 new messages