PCRE issue when setting up WSGI application

冷暖自知 提交于 2021-02-07 01:57:38

问题


I am working with Ubuntu 16.04.2 LTS.

I have been following a guide How To Set Up uWSGI and Nginx to Serve Python Apps on Ubuntu 14.04. Once I have set up the virtualenv I follow the instructions:

pip install uwsgi

You can verify that it is now available by typing:

uwsgi --version

If it returns a version number, the uWSGI server is available for use.

However when I do this I get:

uwsgi: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

If I push on and work further through the guide things fall over when I try use uwsgi.

My research tells me that PCRE is Perl Compatible Regular Expressions and several people have asked questions online with libpcre.so.1 issues with other applications.

For example a response to a similar issue relating to nginx:

The message means what it says. The nginx executable was compiled to expect the PCRE (Perl-compatible Regular Expression) shared library to be available somewhere on LD_LIBRARY_PATH or specified in /etc/ld.so.conf or whatever equivalent library-locating mechanisms apply to your operating system, and it cannot find the library.

You will need to install PCRE - or configure your environment so that nginx will look for the PCRE library where it is installed.

But I can't find much relevant to installing PCRE or configuring it. Most install instructions use: apt-get install libpcre3 libpcre3-dev and then reinstalling uwsgi pip install uwsgi -I. As in this example. Where I have tried everything posted and got nowhere.

I think my principle issue is that I don't understand the problem very well or how to do the things mentioned in the nginx example above.

Any insight or guidance would be much appreciated.


回答1:


Even though my context may be different, the following steps should help you as well.

I did pip install uwsgi into my environment created by conda create -yn <env_name> python. Note, that one wouldn't even need to install PCRE into the environment, because it is included with Anaconda. We can see this issue in the environment, after source activate <env_name>:

# uwsgi --version
uwsgi: error while loading shared libraries: libpcre.so.1: cannot open...

With root/sudo access you can find where libpcre.so.1 is/will be:

# find / -name libpcre.so.1
/opt/anaconda3/lib/libpcre.so.1

Now let Linux know how to access it:

# ldconfig /opt/anaconda3/lib/

That's all you need to make it work. You can see the change you are making:

# find / -name uwsgi
/opt/anaconda3/envs/<env_name>/bin/uwsgi

# ldd -d /opt/anaconda3/envs/<env_name>/bin/uwsgi
        linux-vdso.so.1 =>  (0x00007fff2d1ba000)
        ...
        /lib64/ld-linux-x86-64.so.2 (0x00007ff98dbc5000)
undefined symbol: pcre_free     (/opt/anaconda3/envs/cts/bin/uwsgi)

PS Turned out ldconfig above populates global cache /etc/ld.so.cache, which, in my case, clashed with system library (/lib/x86_64-linux-gnu/libdbus-1.so.3). So I had to revert the change by running ldconfig without parameters and resort to runtime linking = starting uwsgi as

# LD_LIBRARY_PATH=/opt/anaconda3/lib uwsgi --version


来源:https://stackoverflow.com/questions/43301339/pcre-issue-when-setting-up-wsgi-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!