Debuggin - Could not find app -or- No module named myapp.hooks

Could not find app "myapp": No module named 'myapp.hooks'

 · 1 min read


When running Frappe or Python commands, you may encounter an error like:


Could not find app "myapp":

No module named 'myapp.hooks'


Or when testing the import:


python3 -c "import myapp.hooks"


You may see:

Traceback (most recent call last):

 File "<string>", line 1, in <module>

ModuleNotFoundError: No module named 'myapp.hooks'



Steps to Resolve


1. Verify sys.path


python3 -c "import sys; print('\n'.join(sys.path))"


2. Test Import from the App Folder


Navigate to the app folder and try importing the module again:


cd /opt/bench/frappe-bench/apps/myapp

python3 -c "import myapp.hooks"



3. Activate the Virtual Environment


Frappe typically uses a virtual environment. Activate it and try again:


source /opt/bench/frappe-bench/env/bin/activate

python3 -c "import myapp.hooks"


Try from other folder also. if not working from other folders, thats an issue you need to handle on PYTHONPATH


4. Check .pth Files


Look for .pth files in your Python environment that might include incorrect paths:


ls /opt/bench/frappe-bench/env/lib/python3.10/site-packages/*.pth



5. Inspect PYTHONPATH


Check if PYTHONPATH is set and includes invalid paths:


echo $PYTHONPATH



Fix Invalid PYTHONPATH Entries


If you find incorrect entries like /opt/bench/frappe-bench/apps/myapp/myapp, remove them:


export PYTHONPATH=$(echo $PYTHONPATH | sed 's|/opt/bench/frappe-bench/apps/myapp/myapp:||g')



Make this change permanent by updating your shell configuration file (e.g., ~/.bashrc):


nano ~/.bashrc



Add the following line:


export PYTHONPATH=$(echo $PYTHONPATH | sed 's|/opt/bench/frappe-bench/apps/myapp/myapp:||g')


Reload your shell configuration:


source ~/.bashrc



6. Verify Directory Structure


Ensure your app follows the correct structure:


myapp/

  myapp/

    __init__.py

    hooks.py

  setup.py


7. Restart Bench


After making any changes, restart the Frappe bench:


bench restart



Quick Checklist

• Verify sys.path includes /opt/bench/frappe-bench/apps/myapp.

• Test imports from the app folder and virtual environment.

• Inspect and correct .pth files.

• Adjust PYTHONPATH if needed.

• Ensure the app directory structure is correct.





Team ERPGulf

The team behind ERPGulf blogs here, expresses their thoughts, shares the experience, often show the frustrations. Contact us on support@ERPGulf.com

No comments yet

No comments yet. Start a new discussion.

Add Comment