Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

[CDSW] Package import error during model deployment

avatar
Explorer

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.

2 ACCEPTED SOLUTIONS

avatar
Expert Contributor

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

avatar
Contributor

I tried with sys.path.append("/home/cdsw") and it worked.

View solution in original post

5 REPLIES 5

avatar
Expert Contributor

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?

 

 

avatar
Explorer

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!

avatar
Contributor

I tried with sys.path.append("/home/cdsw") and it worked.

avatar
Explorer

I wrote a code to add the "/home/cdsw/" path, and the problem has been solved.

Thank you for your help!

avatar
Contributor

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__) )