最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Python Flask WSGI failure with deprecated imp module - Stack Overflow

programmeradmin2浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

If 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.

.

发布评论

评论列表(0)

  1. 暂无评论