Created 03-09-2023 11:13 PM
There is an error during cdsw model deployment where the package of code is not imported.
- CDSW version
1.9.2
- Folder Configuration
/home/cdsw
l- ex_package_one
l l- ex_package_two
l l-ex_pkg_code.py
l
l- predict
l 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 log
ModuleNotFoundError: No module named 'ex_package_one'
- Attempt to resolve the error
I 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.
Created 03-10-2023 12:55 AM
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?
Created 03-10-2023 02:12 AM
I tried with sys.path.append("/home/cdsw") and it worked.
Created 03-10-2023 12:55 AM
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?
Created 03-12-2023 10:05 PM
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!
Created 03-10-2023 02:12 AM
I tried with sys.path.append("/home/cdsw") and it worked.
Created on 03-12-2023 10:07 PM - edited 03-12-2023 10:09 PM
I wrote a code to add the "/home/cdsw/" path, and the problem has been solved.
Thank you for your help!
Created 03-10-2023 05:01 AM
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__) )