More elegant solution for importing files

I am wondering if there are more elegant solutions than the second to last comment on this Github issues thread:

I have a module A.py which I need in B.py which defines some Ray actors. Adding A.py to the PYTHONPATH does not work. Moving A.py source code into B.py works.

What is the best strategy to handle this kind of import in Ray right now?

Does Handling Dependencies — Ray v1.9.2 help?

Yes this is great! I got confused reading old stackoverflow posts and github issues talking about PythonPath…

Looks like Simon beat me to the punch here! @marsupialtail we’re trying to make this feature more prominent/discoverable in the docs, please let us know if you can think of other places in the Ray docs where we should add inbound links to this page.

Perhaps you guys can start by linking this doc page to all the places I found, like: Import not working in a cluster · Issue #3116 · ray-project/ray · GitHub
How to submit a task which is implemented in a separate module? · Issue #7133 · ray-project/ray · GitHub
Parallel: Import a python file from sibling folder - Stack Overflow

1 Like

Done! Great idea, thanks a lot for the suggestion.