Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working for uWSGI #531

Closed
Jonney opened this issue Feb 17, 2025 · 2 comments
Closed

Not working for uWSGI #531

Jonney opened this issue Feb 17, 2025 · 2 comments

Comments

@Jonney
Copy link

Jonney commented Feb 17, 2025

[uWSGI] getting INI configuration from uwsgi.ini
2025-02-17 11:50 - *** Starting uWSGI 2.0.28 (64bit) on [Mon Feb 17 11:50:52 2025] ***
2025-02-17 11:50 - compiled with version: 12.2.0 on 17 February 2025 03:28:29
2025-02-17 11:50 - os: Linux-6.1.0-31-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.128-1 (2025-02-07)
2025-02-17 11:50 - nodename: bridge
2025-02-17 11:50 - machine: x86_64
2025-02-17 11:50 - clock source: unix
2025-02-17 11:50 - pcre jit enabled
2025-02-17 11:50 - detected number of CPU cores: 2
2025-02-17 11:50 - current working directory: /data/website
2025-02-17 11:50 - writing pidfile to /dev/shm/website.pid
2025-02-17 11:50 - detected binary path: /data/website/python-3.12.9/bin/uwsgi
2025-02-17 11:50 - setgid() to 1002
2025-02-17 11:50 - setuid() to 1002
2025-02-17 11:50 - chdir() to /data/website/
2025-02-17 11:50 - your processes number limit is 6750
2025-02-17 11:50 - your memory page size is 4096 bytes
2025-02-17 11:50 -  *** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers ***
2025-02-17 11:50 - detected max file descriptor number: 65535
2025-02-17 11:50 - lock engine: pthread robust mutexes
2025-02-17 11:50 - thunder lock: enabled
2025-02-17 11:50 - uwsgi socket 0 bound to UNIX address /dev/shm/website.socket fd 3
2025-02-17 11:50 - Python version: 3.12.9 (main, Feb 15 2025, 13:28:13) [GCC 12.2.0]
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = '.:.:'
  program name = '/data/website/python-3.12.9/bin/uwsgi'
  isolated = 0
  environment = 1
  user site = 1
  safe_path = 0
  import site = 1
  is in build tree = 0
  stdlib dir = '/opt/python-3.12.9/lib/python3.12'
  sys._base_executable = '/root/.local/share/uv/python/cpython-3.12.9-linux-x86_64-gnu/bin/uwsgi'
  sys.base_prefix = '/opt/python-3.12.9'
  sys.base_exec_prefix = '/opt/python-3.12.9'
  sys.platlibdir = 'lib'
  sys.executable = '/data/website/python-3.12.9/bin/uwsgi'
  sys.prefix = '/opt/python-3.12.9'
  sys.exec_prefix = '/opt/python-3.12.9'
  sys.path = [
    '/data/website',
    '/data/website',
    '/data/website',
    '/opt/python-3.12.9/lib/python312.zip',
    '/opt/python-3.12.9/lib/python3.12',
    '/opt/python-3.12.9/lib/python3.12/lib-dynload',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007ff1e2713040 (most recent call first):
  <no Python frame>
2025-02-17 11:50 - VACUUM: unix socket /dev/shm/website.socket removed.

Note this error:

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>

I tried compiling and installing Python 3.12.9 from source without any issues, everything went well. However, when installing via uv python install, I encountered the above error, and the same happens with other versions of Python. And only uwsgi had this issue, the other libraries are all fine.

@zbynekwinkler
Copy link

See possibly related issue unbit/uwsgi#2525

@Jonney Jonney closed this as not planned Won't fix, can't repro, duplicate, stale Feb 17, 2025
@Jonney
Copy link
Author

Jonney commented Feb 18, 2025

Finally, I found the root of the problem.

  • The default installation path for uv python install is ~/.local/share/uv/python/*
  • Run uwsgi using the root account and specified --user nobody

When these two conditions are met simultaneously, a ModuleNotFoundError occurs.

The master process of uwsgi runs as root, so it can read the Python built-in library normally. However, when starting the worker process, it dynamically loads modules and does not have permission to access /root/.local/share/uv/python/*, leading to a ModuleNotFoundError.

The same issue occurs with gunicorn. When gunicorn starts the worker process, it throws an exception just like uwsgi does.

If I compile Python from source and the installation path is /opt/python/*, the nobody user has access permission, so it goes well.

Solution:

Set the environment variable UV_PYTHON_INSTALL_DIR to install Python in a directory outside of /root, allowing normal users to have access permission.

@Jonney Jonney closed this as completed Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants