Ask coding questions

← Back to all posts
Add package to Django application
shiwei (2)

I am able to add packages (such as SpeechRecognition) to Python application without problem.
But if I created an Django repl and went through same process (the package was added to requirements.txt), it would return ModuleNotFoundError when I tried to reference the package.

Any idea?


PhoenixC (6)

The issue is caused by the installation path is /home/runner/.site-packages instead of /usr/local/lib/python3.6/site-packages or /home/runner/.local/lib/python3.6/site-packages.

I wrote a script to move to move all the module to the right path:

Copy to your project then add following code to the top of your

from .site_packages_setup import move_site_packages


You might need to restart the Django twice.

Vandesm14 (497)

You need to create a Django repl instead of the basic python repl.

Please mark this as answered if I helped your problem 👍

shiwei (2)

Basic python repl doesn't have problem. Only Django repl has the issue.