uwsgi module not found after Python upgrade

I have a Flask/UWSGI application running on my home server. A recent Ubuntu upgrade deleted Python 3.10 and installed Python 3.12 instead. I’ve made a new venv and installed the application, but it no longer runs. In the UWSGI log it says:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>ModuleNotFoundError: No module named 'wsgi'
</code>
<code>ModuleNotFoundError: No module named 'wsgi' </code>
ModuleNotFoundError: No module named 'wsgi'

My application is called sieve and the working directory is /usr/share/sieve. I’m using a ini file, /usr/share/sieve/sieve.ini, which looks like this:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>[uwsgi]
module = wsgi
callable = app
master = true
processes = 5
socket = /usr/share/sieve/sieve.sock
chmod-socket = 660
vacuum = true
die-on-term = true
logto = /usr/share/sieve/sieve.log
logfile-chown = jon:www-data
log-date = [%%Y-%%m-%%d %%H:%%M:%%S]
</code>
<code>[uwsgi] module = wsgi callable = app master = true processes = 5 socket = /usr/share/sieve/sieve.sock chmod-socket = 660 vacuum = true die-on-term = true logto = /usr/share/sieve/sieve.log logfile-chown = jon:www-data log-date = [%%Y-%%m-%%d %%H:%%M:%%S] </code>
[uwsgi]
module = wsgi
callable = app

master = true
processes = 5 

socket = /usr/share/sieve/sieve.sock
chmod-socket = 660
vacuum = true

die-on-term = true
logto = /usr/share/sieve/sieve.log
logfile-chown = jon:www-data
log-date = [%%Y-%%m-%%d %%H:%%M:%%S]

I’ve also tried module=sieve.wsgi and module=wsgi:app as suggested elsewhere.

The application is in a sieve subdirectory and /usr/share/sieve/sieve/wsgi.py looks like this:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#!/usr/bin/env python
from run_app import app
if __name__ == '__main__':
app.run(debug=True)
</code>
<code>#!/usr/bin/env python from run_app import app if __name__ == '__main__': app.run(debug=True) </code>
#!/usr/bin/env python
from run_app import app

if __name__ == '__main__':
    app.run(debug=True)

The service definition includes these lines:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>WorkingDirectory=/usr/share/sieve
Environment="PATH=$PATH:/usr/share/sieve/venv/bin"
ExecStart=/usr/share/sieve/venv/bin/uwsgi --ini sieve.ini --enable-threads
</code>
<code>WorkingDirectory=/usr/share/sieve Environment="PATH=$PATH:/usr/share/sieve/venv/bin" ExecStart=/usr/share/sieve/venv/bin/uwsgi --ini sieve.ini --enable-threads </code>
WorkingDirectory=/usr/share/sieve
Environment="PATH=$PATH:/usr/share/sieve/venv/bin"
ExecStart=/usr/share/sieve/venv/bin/uwsgi --ini sieve.ini --enable-threads

I’m not sure what has changed since it was last working, but looking further up the log, this setup worked fine:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>[2024-08-27 21:32:30] - *** Starting uWSGI 2.0.21 (64bit) on [Tue Aug 27 21:32:30 2024] ***
[2024-08-27 21:32:30] - compiled with version: 11.3.0 on 20 November 2022 14:54:48
[2024-08-27 21:32:30] - os: Linux-6.8.0-40-generic #40~22.04.3-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 30
17:30:19 UTC 2
</code>
<code>[2024-08-27 21:32:30] - *** Starting uWSGI 2.0.21 (64bit) on [Tue Aug 27 21:32:30 2024] *** [2024-08-27 21:32:30] - compiled with version: 11.3.0 on 20 November 2022 14:54:48 [2024-08-27 21:32:30] - os: Linux-6.8.0-40-generic #40~22.04.3-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 30 17:30:19 UTC 2 </code>
[2024-08-27 21:32:30] - *** Starting uWSGI 2.0.21 (64bit) on [Tue Aug 27 21:32:30 2024] ***
[2024-08-27 21:32:30] - compiled with version: 11.3.0 on 20 November 2022 14:54:48
[2024-08-27 21:32:30] - os: Linux-6.8.0-40-generic #40~22.04.3-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 30
 17:30:19 UTC 2

The current version does not work (with the same site code and config).

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>[2024-09-24 20:33:49] - *** Starting uWSGI 2.0.27 (64bit) on [Tue Sep 24 20:33:49 2024] ***
[2024-09-24 20:33:49] - compiled with version: 13.2.0 on 24 September 2024 18:04:08
[2024-09-24 20:33:49] - os: Linux-6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:02:04 UTC 2024
</code>
<code>[2024-09-24 20:33:49] - *** Starting uWSGI 2.0.27 (64bit) on [Tue Sep 24 20:33:49 2024] *** [2024-09-24 20:33:49] - compiled with version: 13.2.0 on 24 September 2024 18:04:08 [2024-09-24 20:33:49] - os: Linux-6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:02:04 UTC 2024 </code>
[2024-09-24 20:33:49] - *** Starting uWSGI 2.0.27 (64bit) on [Tue Sep 24 20:33:49 2024] ***
[2024-09-24 20:33:49] - compiled with version: 13.2.0 on 24 September 2024 18:04:08
[2024-09-24 20:33:49] - os: Linux-6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:02:04 UTC 2024

Why has my application stopped working and what to I need to do to make UWSGI find the module again?

Figured it out – the answer is to update the service definition so the working directory is the code root.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>WorkingDirectory=/usr/share/sieve/sieve
</code>
<code>WorkingDirectory=/usr/share/sieve/sieve </code>
WorkingDirectory=/usr/share/sieve/sieve

I guess Python 3.12 is a bit more strict about project structure. Ideally I should rewrite this so the different parts of the application can be imported properly, but it works now, so this will do!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật