unbit / uwsgi

uWSGI application server container
http://projects.unbit.it/uwsgi
Other
3.46k stars 692 forks source link

invalid option -- 'B' when using scikit-learn joblib #1945

Open bzijlema opened 5 years ago

bzijlema commented 5 years ago

I'm getting the following error when importing joblib from scikit-learn using uWSGI:

/tmp/uwsgi/venv/bin/uwsgi: invalid option -- 'B'

I run uWSGI with this parameters:

uwsgi --wsgi-file main.py --http :9000

main.py:

from sklearn.externals import joblib

def application(environ, start_response):
    pass

Output of pip freeze:

numpy==1.15.4
scikit-learn==0.20.1
scipy==1.1.0
uWSGI==2.0.17.1

Python version is 3.5.2

Commenting the import of joblib removes the error. Any ideas where this error is coming from?

xrmx commented 5 years ago

Are you sure joblib is something that should run from application server as uwsgi?

bzijlema commented 5 years ago

I found out that the error is caused by the PYTHONDONTWRITEBYTECODE environment variable. When this variable is set, the error shows when a module is imported.

According to the python docs (https://docs.python.org/3.5/using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE), setting this variable is equivalent to runing python with the "-B" parameter. It seems that this parameter is sent to uWSGI instead of python for some reason. This looks like a bug in uWSGI or the python plugin to me.

awhan commented 5 years ago

I too notice this error. Although the deployment in my case is all with docker containers built on Ubuntu 18.04 base images. Python 3.6.6 and uwsgi 2.0.17.1.

I too have the PYTHONDONTWRITEBYTECODE in my image and I too use sklearn and joblib in my code base. However unlike the OP I actually do have a flask web app that nginx talks to through uwsgi.

I am trying to reproduce this error without having to share the code base that I am working with. But that is a bit involved so kindly allow me some time.

I was NOT able to reproduce this error with PYTHONDONTWRITEBYTECODE alone and a simple docker image. So I don't think this is being caused by PYTHONDONTWRITEBYTECODE alone.