Can't Load Mod_Wsgi Compiled for Python 3

Can't load mod_wsgi compiled for Python 3

That means that the library libpython3.5m.so.1.0 can't be found at runtime because the directory /opt/anaconda/anaconda3/lib is not a place where the dynamic linker would look for it.

You can try to rebuild mod_wsgi using:

./configure LDFLAGS='-Wl,-rpath=/opt/anaconda/anaconda3/lib' --with-python=/opt/anaconda/anaconda3/bin/python

That will save the library path within the generated binary.

The other option would be to set the LD_LIBRARY_PATH environment variable for the apache process, which is not really a good method.

Or add the directory /opt/anaconda/anaconda3/lib to the library search path using a conf file in /etc/ld.so.conf.d/, that would be a global setting tough. See man ld-linux for more info.

Also, don't forget to correctly set the WSGIPythonHome directive in your config file.


edit:

I've done some experimenting and I could reproduce your second error message when the python3 binary is not found on the PATH.

In that case it seems setting the WSGIPythonHome directive is not enough, you need to set the PYTHONHOME environment variable before apache is started, or change PATH so the interpreter can be found. On CentOS changing /etc/sysconfig/httpd should do the trick, just add:

export PYTHONHOME=/opt/anaconda/anaconda3
# alternatively this should also work:
export PATH="$PATH:/opt/anaconda/anaconda3/bin"

Or create a symlink to the interpreter in a directory on the path, e.g. /usr/local/bin...

For reference, an extended explanation why this is needed can be found here

mod_wsgi python can't import from standard library

Your mod_wsgi is likely not compiled against Python 2.7. You cannot use a virtualenv for one Python version with mod_wsgi compiled against a different Python version.

Read from:

http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Python_Shared_Library

and do checks in that document.

Why can't my mod_wsgi module find libpython3.7m.so.1.0 even though it exists?

I never stumbled onto the root cause of this issue but when I added this line

LoadFile /usr/local/lib/libpython3.7m.so.1.0

to the top of my /etc/httpd/conf.modules.d/10-wsgi.conf file and restarted my server, everything worked fine.

httpd won't start with custom conf files and mod_wsgi built with Python 3.9

You are seeing this error...

libpython3.9.so.1.0: cannot open shared object file: No such file or directory

...because httpd has no idea it's supposed to look in /opt/python3.9/lib to find the necessary shared library. There are several ways of resolving this problem:

  1. Set -rpath when linking the module.

    This embeds a path to the library in the compiled binary. You would set it by running make like this inside the mod_wsgi-4.9.2 directory:

    make LDFLAGS='-L/opt/python3.9/lib -Wl,-rpath,/opt/python3.9/lib'
  2. Set LD_LIBRARY_PATH in httpd's environment. This provides
    httpd with an additional list of directories to search for shared
    libraries. We can test it like this:

    LD_LIBRARY_PATH=/opt/python3.9/lib httpd -DFOREGROUND

    To set it persistently, you'd want to customize the httpd
    service unit:

    • Run systemctl edit httpd

    • In the editor that comes up, add the following content:

      [Service]
      Environment=LD_LIBRARY_PATH=/opt/python3.9/lib

      This creates
      /etc/systemd/system/httpd.service.d/override.conf.

    • Run systemctl daemon-reload to refresh the cached version of the unit file.

    • Restart your httpd service.

  3. Edit the global library search path by creating
    /etc/ld.so.conf.d/python3.9.conf with the following content:

    /opt/python3.9/lib

    Then run:

    ldconfig

Any of the above options should get things running for you.

How to compile mod_wsgi with Apache 2.2 & Python 3.2 for Windows?

Try again with the very latest source code. You may also want to use the 3.X branch instead of default branch for time being.

Django WSGI Script Won't load due to a Python issue

Most likely your mod_wsgi is compiled against one Python installation but you are trying to force it to use a different Python installation. The reason you are having a problem is because one Python installation was compiled with UCS2 support and the other UCS4.

Use 'ldd' on mod_wsgi.so to show what Python installation it is trying to use and then provide that information as part of question along with mod_wsgi configuration or WSGI script contents where you are trying to force it to use different Python installation, or incompatible virtual environment.



Related Topics



Leave a reply



Submit