There is an error during cdsw model deployment where the package of code is not imported.
- CDSW version1.9.2
- Folder Configuration/home/cdswl- ex_package_onel l- ex_package_twol l-ex_pkg_code.pyll- predictl l- predict.py
predict.py is the code used in the model deployment.- Package import code within predict.py....from ex_package_one.ex_package_two import ex_pkg_code...- Error logModuleNotFoundError: No module named 'ex_package_one'- Attempt to resolve the errorI printed it out as os.getcwd() from predict.py and it came out as /cdsw/home.sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname("__file__"))))The path was added using the above code, but the same error occurred.No package errors will occur if the code is transferred to /home/cdsw/predict.py.Is there any other way to solve this problem?Thank you for any help.
Hi @Hyeonseo ,
If we print package locations from predict.py respectively:
python -c 'import site; print(site.getsitepackages())'
do you find the result is different?
If we add all the package locations is there still such issue?
View solution in original post
I tried with sys.path.append("/home/cdsw") and it worked.
The package locations all appeared to be the same.(/usr/local/lib/python3.6/site-packages)
Writing code to add the "/home/cdsw/" path resolved the issue.
Thank you for suggesting a solution!
I wrote a code to add the "/home/cdsw/" path, and the problem has been solved.Thank you for your help!
Otherwise the issue is that ipython does not always define __file__ , it is empty in a model.
(Also __file__ should be referred without quotes ", os.path.dirname(__file__) )