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

Problem running with mod_wsgi #827

Open
tigger04 opened this issue Jul 1, 2024 · 12 comments
Open

Problem running with mod_wsgi #827

tigger04 opened this issue Jul 1, 2024 · 12 comments

Comments

@tigger04
Copy link

tigger04 commented Jul 1, 2024

Hi there, I've been following the installation instructions diligently, but I seem to have run in to a roadblock on first_setup.py:

root@numbas:/srv/www/numbas_editor# source bin/activate
(numbas_editor) root@numbas:/srv/www/numbas_editor# python3 first_setup.py
/srv/www/numbas_editor/first_setup.py:11: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  from pkg_resources import packaging
Traceback (most recent call last):
  File "/srv/www/numbas_editor/first_setup.py", line 11, in <module>
    from pkg_resources import packaging
ImportError: cannot import name 'packaging' from 'pkg_resources' (/srv/www/numbas_editor/lib/python3.12/site-packages/pkg_resources/__init__.py)

Any advice greatly appreciated!

@tigger04
Copy link
Author

tigger04 commented Jul 1, 2024

further troubleshooting ...

(numbas_editor) root@numbas:/srv/www/numbas_editor# pip install packaging
Requirement already satisfied: packaging in ./lib/python3.12/site-packages (24.1)
(numbas_editor) root@numbas:/srv/www/numbas_editor# python -c "import pkg_resources; print(pkg_resources.__file__)"
<string>:1: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
/srv/www/numbas_editor/lib/python3.12/site-packages/pkg_resources/__init__.py

@tigger04
Copy link
Author

tigger04 commented Jul 1, 2024

Almost got there ... installing an older version of setuptools let's me run the installer first-run.py.

pip install setuptools==69.5.1

Everything was looking good, ready to launch the editor, but I get

Bad Request (400)

in the browser then.

And nothing in the logs at all :(

Any help, again, v much appreciated

@christianp
Copy link
Member

Sorry, this is me not keeping up with packaging deprecations.
I've just pushed a commit which changes first_setup.py to use the packaging package. Can you do a git pull and try it? You might need to do pip install -r requirements.txt to make sure you install packaging.

@tigger04
Copy link
Author

tigger04 commented Jul 9, 2024

Thank you! I seem to have made significant progress and got first_setup.py to run through to completion.
Now to get it to work with apache, struggling to get past this in the server logs, pretty sure it looks like I've got the file permissions wrong somewhere. Playing around with them, will report back if I can pinpoint the problem.

[Tue Jul 09 23:44:19.751055 2024] [wsgi:warn] [pid 111387:tid 140507470796672] (13)Permission denied: mod_wsgi (pid=111387): Unable to stat Python home /opt/python/numbas-editor. Python interpreter may not be able to be initialized correctly. Verify the supplied path and access permissions for whole of the path.
Python path configuration:
Python path configuration:
  PYTHONHOME = '/opt/python/numbas-editor'
  PYTHONPATH = (not set)
  program name = 'python3'
  isolated = 0
  environment = 1
  user site = 1
  safe_path = 0
  import site = 1
  is in build tree = 0
  stdlib dir = '/opt/python/numbas-editor/lib/python3.12'
  sys._base_executable = '/usr/bin/python3'
  sys.base_prefix = '/opt/python/numbas-editor'
  sys.base_exec_prefix = '/opt/python/numbas-editor'
  sys.platlibdir = 'lib'
  sys.executable = '/usr/bin/python3'
  sys.prefix = '/opt/python/numbas-editor'
  sys.exec_prefix = '/opt/python/numbas-editor'
  sys.path = [
    '/opt/python/numbas-editor/lib/python312.zip',
    '/opt/python/numbas-editor/lib/python3.12',
    '/opt/python/numbas-editor/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'

@christianp
Copy link
Member

Has your Python version changed since you made the virtualenv? Can you try deleting and remaking it, and see if that helps?

@tigger04
Copy link
Author

So having another crack at this, running Django naked without Apache, first thing I found was:
ModuleNotFoundError: No module named 'distutils'

Turns out distutils is deprecated as of Python 3.12 which I'm running - this was quickly overcome with:

pip install setuptools

(might be worth adding to requirements.txt)

Buuut I can't get it to accept a connection from anything but localhost, despite:

ALLOWED_HOSTS = ['*']

So i'm back to scratching my head with apache .. hmmmm

@tigger04
Copy link
Author

tigger04 commented Jul 14, 2024

Has your Python version changed since you made the virtualenv? Can you try deleting and remaking it, and see if that helps?

Nope i've been with Python 3.12 the whole time. As part of my effort to get this thing running I even tried reverting my system to 3.8 / 3.9, turns out a lot of things in Ubuntu rely on Python and I ended up borking my whole system and having to restore from backup

🤦

So it's 3.12 or bust! Yes, reinstalled this too.

christianp added a commit that referenced this issue Jul 16, 2024
distutils was removed in pyhton 3.12

see #827
@christianp
Copy link
Member

As far as I can see, distutils was only needed for the headless_test command, which I think was could be removed, but I've made a quick change to remove the dependency on distutils.

If you're using python manage.py runserver on its own, by default it only binds to localhost so won't accept connections from outside. You can accept external connections with python manage.py runserver 0.0.0.0:8000

@tigger04
Copy link
Author

Thanks so much Christian

I have managed to get the editor running for a single-user with python3 manage.py runserver

I'm struggling with setting it up on apache as per install instructions on
https://numbas.github.io/editor/ubuntu-web.html

Essentially stuck on this as before

Scratching my head have scrubbed and reinstalled Python 3.12 😤

@christianp
Copy link
Member

@tigger04 I searched for "apache wsgi ModuleNotFoundError: No module named 'encodings'" and got this StackOverflow question. The answer suggests that it's to do with an old version of mod_wsgi, and that you could try installing mod_wsgi from through pip.

@tigger04
Copy link
Author

Ah, I felt like I was tantalizingly close with that one, but alas I am on the current version (5.0.0)
[Tue Jul 16 14:15:57.261007 2024] [mpm_event:notice] [pid 31268:tid 123290232399744] AH00489: Apache/2.4.58 (Ubuntu) OpenSSL/3.0.13 mod_wsgi/5.0.0 Python/3.12 configured -- resuming normal operations

@christianp christianp changed the title first_setup.py: pkgtools is deprecated, help! Problem running with mod_wsgi Jul 19, 2024
@christianp
Copy link
Member

@tigger04 I've renamed this issue because I think the pkgtools problem is now fixed.

For the mod_wsgi problem: there's an error message at the top of the output you gave:

Permission denied: mod_wsgi (pid=111387): Unable to stat Python home /opt/python/numbas-editor. Python interpreter may not be able to be initialized correctly. Verify the supplied path and access permissions for whole of the path

Does the user running apache have access to /opt/python/numbas-editor?

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