When I attempt to deploy a Flask app on a shared hosting site, using cPanel, the deployment fails with this message: "ModuleNotFoundError: No module named 'imp'."
As other posts have indicated, the imp
module has been removed from Python and a different module, importlib
, should be used instead. However, the file named passenger_wsgi.py
is generated automatically any edited version will always be overwritten. It is this file that needs to use the imp
module.
How can I deploy my Flask app on shared hosting, using cPanel to set up the app?
.
When I attempt to deploy a Flask app on a shared hosting site, using cPanel, the deployment fails with this message: "ModuleNotFoundError: No module named 'imp'."
As other posts have indicated, the imp
module has been removed from Python and a different module, importlib
, should be used instead. However, the file named passenger_wsgi.py
is generated automatically any edited version will always be overwritten. It is this file that needs to use the imp
module.
How can I deploy my Flask app on shared hosting, using cPanel to set up the app?
.
Share Improve this question asked Mar 28 at 17:17 macloomacloo 6371 gold badge9 silver badges19 bronze badges1 Answer
Reset to default 0If you attempt to deploy a Flask app on a shared hosting site, using cPanel, the deployment is likely to fail with this message: "ModuleNotFoundError: No module named 'imp'." As other posts have indicated, the `imp` module has been removed from Python and a different module, `importlib`, should be used instead.
The problem comes from the cPanel deployment: a file named `passenger_wsgi.py` is generated automatically. If you stop and restart the app, this file is rewritten, and thus you cannot edit the file yourself; the edited version will always be overwritten. It is this file that needs to use the `imp` module, and as far as I could learn, cannot be replaced or modified for a cPanel deployment of any Python app.
The solution is to roll back the Python version to 3.11.11 (or earlier). The `imp` module still exists in those versions, and so `passenger_wsgi.py` will run without error, and your app will run too — so long as it can run under Python 3.11.11.
.