Python: Centos + gunicorn+flask ImportError: No module named request

Today, we use Python to download images, using urllib. Request, which is the method of Python 3. Python 2 uses urllib2

Encountered such a problem, the background reported an error, importerror: no module named request

I checked a lot of information and said that I was installing requests, but I was still like this after installation. I was almost desperate

Finally, we found a problem. The gunicorn related content displayed in the error message is python2.7

I wonder if it’s because Python 2.7 and python 3 are installed in the background, gunicorn uses Python 2.7 in the background, but urllib.request is a function of Python 3, so I can’t find the corresponding module

After analyzing the problem, then start to solve the problem

1. Look at all the directories under bin

cd /bin

2. Backup the gunicorn file inside

cp gunicorn gunicorn.bck

3. Create a soft connection of gunicorn under python3 to bin (if not, install a gunicorn with PIP3)

ln -s /usr/local/python3/bin/gunicorn /bin/gunicorn

4. You can check whether it is successful

ls -l

In this way, the background running service is python3, and the module request will not be reported again

5. If after the above problems are solved, there is a problem that the SSL module cannot be found (anyway, I have)

Please check https://www.cnblogs.com/mqxs/p/9103031.html

Similar Posts: