Cannot import module while using custom handler
See original GitHub issue🐛 Bug report
I’m trying to use a custom crowd counting model and while serving it gives me an error while importing custom model libraries.
Python Import code is like below:
module_path = os.path.abspath(os.path.join('../../../../')) # Parent Dir on local machine
if module_path not in sys.path:
sys.path.append(module_path+"/SSDCNet")
...
from Network.SSDCNet import SSDCNet_classify
Error:
File "/tmp/models/58eb8da6a1c8563374304a9fc66b2788a9c9c440/crdcnt_handler.py", line 9, in <module>
from crowdmodel import CrowdCounter
File "/tmp/models/58eb8da6a1c8563374304a9fc66b2788a9c9c440/crowdmodel.py", line 8, in <module>
from Network.SSDCNet import SSDCNet_classify
ModuleNotFoundError: No module named 'Network'
Here is the log file:
server_log3.txt
Environment Details:
Operating System and version: Ubuntu 16.04
**Possible Fix: **
Instead of adding to sys.path
. Adding the parent folder to PYTHONPATH
before you run the torchserve
command temporarily fixes the issue.
> export PYTHONPATH=/home/ubuntu/mayub/Github/SSDCNet:$PYTHONPATH
> echo $PYTHONPATH
> torchserve --ts-config ./config.properties --start --ncs --model-store ./torchserve_model_store --models all
Since this is temporary and session based maybe a better solution is required.
Thanks !
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Resolve "Unable to import module" errors from Python ...
To resolve this error, create a deployment package or Lambda layer that includes the libraries that you want to use in your Python...
Read more >Python - Handler doesn't detect the custom handler class
Your sys.path needs to contain the project/confs directory, otherwise you won't be able to import the custom_handler module. Try again after ...
Read more >How do I resolve the "Unable to import module ... - YouTube
... Knowledge Center article with this video: https://aws.amazon.com/premiumsupport/knowledge-center/lambda- import - module - error -python/0...
Read more >ModuleNotFoundError: no module named Python Error [Fixed]
How to fix the ModuleNotFoundError in Python · 1. Make sure imported modules are installed · 2. Make sure modules are spelled correctly...
Read more >Unable to import module 'handler': No module named 'werkzeug'
I fixed it by install zappa in the venv itself. So, follow the steps (assuming you have venv in env folder locally) $...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
how to add a folder as extra files ?
@mohammedayub44 :
torch-model-archiver
is just a utility tool for packaging your model and does not validates you model. It is expected that the user will supply all the other dependency files using the--extra-files
flag. You can always create an egg/zip file to upload your custom python package if the number of files are more.