charmplusplus / charm4py

Parallel Programming with Python and Charm++
https://charm4py.readthedocs.io
Apache License 2.0
289 stars 21 forks source link

Importing charm4py from project root fails #266

Open mayantaylor opened 1 month ago

mayantaylor commented 1 month ago

After successfully installing charm4py, and launching a python shell, import charm4py works in almost every context - except when the python shell is launched from the project root. I believe this is due to the c_object_store.*.so generation. Steps to reproduce the issue are below (this is within a python venv):

cd charm4py python setup.py install python >>> import charm4py FAILS: ModuleNotFoundError: No module named 'charm4py.c_object_store' cd <any other directory> python >>> import charm4py SUCCEEDS

Python import search process: Python import searches the paths in sys.path for a <module_name>/__init.py__. The first entry in sys.path is always the current directory. Other relevant entries include .../lib/python3.11/site-packages, which is where the installed charm4py libraries live. In the charm4py case, the directory found by import must also include a c_object_store.*.so of some form to correctly import charm4py. The problem lies in the fact that $root/charm4py doesn't include this .so:

> > `charm4py % diff <(ls charm4py) <(ls /Users/maya/test/venv/lib/python3.11/site-packages/charm4py)
> 0a1
> > LICENSE
> 5c6
> < c_object_store.html
> ---
> ---
> c_object_store.cpython-311-darwin.so

Potential solutions: Copying the necessary .so from site-packages into $root/charm4py solves the issue. I'm not sure if the problem here is that the .so is not in this directory, or that import looks in the root directory to begin with.