Jacob Morris
Jacob Morris

Reputation: 500

Upgrading to Python 3.5 but uWSGI using Python 2.7

I am currently trying to upgrade our Python 2.7 project to 3.5. I'm using pipenv to create a virtual environment to do this in. Our server has been upgraded to Ubuntu 16.04. In my current pip environment, when running python -V it correctly returns "Python 3.5.2". However, when attempting to start uWSGI I receive the following error:

Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 7, in <module>
    from pipenv import cli
ImportError: No module named 'pipenv'
[uWSGI] getting INI configuration from /opt/site/uwsgi.ini
*** Starting uWSGI 2.0.15 (64bit) on [Tue Jul 21 19:47:23 2020] ***
compiled with version: 4.8.4 on 05 October 2017 19:12:33
os: Linux-4.4.0-185-generic #215-Ubuntu SMP Mon Jun 8 21:53:19 UTC 2020
nodename: ip-172-31-15-50
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /opt/site/mysite
detected binary path: /usr/local/bin/uwsgi
chdir() to /opt/site/mysite
your processes number limit is 64022
your memory page size is 4096 bytes
 *** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers *** 
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3
Python version: 2.7.16 (default, Mar 26 2019, 10:00:46)  [GCC 4.8.4]
Set PythonHome to /home/u_admin/.local/share/virtualenvs/site-qq5I0OuW
ImportError: No module named site

I believe the issue is related to this line:

Python version: 2.7.16 (default, Mar 26 2019, 10:00:46)  [GCC 4.8.4]

Although I'm unsure as to why uWSGI is still using Python 2.

Any help would be greatly appreciated. Thanks!

EDIT:

Here is my uwsgi.ini:

[uwsgi]                                                                            
                                                                                   
# Django-related settings                                                          
# the base directory (full path)                                                   
# main Django wsgi file                                                            
chdir           = /opt/my_project/portal                                           
module          = wsgi.portal:application                                          
# Exit with error code if app can't be imported                                    
need-app        = true                                                             
                                                                                   
# process-related settings                                                         
# graceful reload                                                                  
stopsignal      = SIGHUP                                                           
# Exit when supervisord sends SIGTERM instead of restarting                        
die-on-term     = true                                                             
                                                                                   
# master                                                                           
master          = true                                                             
                                                                                   
# maximum number of worker processes                                               
processes       = 5                                                                
threads         = 3                                                                
max-requests    = 3000                                                             
                                                                                   
# Give up if a request takes so long that nginx has already timed out              
harakiri        = 35                                                               
                                                                                   
# for NewRelic                                                                     
enable-threads     = true                                                          
single-interpreter = true                                                          
                                                                                   
# the socket (use the full path to be safe)                                        
socket          = /tmp/uwsgi.sock                                                  
stats           = /tmp/uwsgi_stats.sock                                            
                                                                                   
chown-socket    = myproject:myprojecttech                                          
chmod-socket    = 664                                                              
                                                                                   
# At exit, preserve socket for use on the next launch                              
vacuum          = false                                                            
plugins-dir = /usr/lib/uwsgi/plugins                                               
plugins = python35                                                                 
home = /home/u_admin/.local/share/virtualenvs/agportal-qq5I0OuW

EDIT:

After running uwsgi -H path/to/python I receive the following message:

*** Starting uWSGI 2.0.19.1 (64bit) on [Fri Jul 24 19:14:30 2020] ***
compiled with version: 5.4.0 20160609 on 20 July 2020 17:01:06
os: Linux-4.4.0-185-generic #215-Ubuntu SMP Mon Jun 8 21:53:19 UTC 2020
nodename: ip-172-31-15-50
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /opt/spensa/site
detected binary path: /home/u_admin/.local/share/virtualenvs/site-qq5I0OuW/bin/uwsgi
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 64022
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
The -s/--socket option is missing and stdin is not a socket.

This did not change the issue's status.

Upvotes: 0

Views: 1268

Answers (2)

Jacob Morris
Jacob Morris

Reputation: 500

I found a file under our supervisord structure in the "conf.d" folder. (/etc/supervisor/confd).

This file started uwsgi using a file titled vuwsgi.py (theoretically for virtual uwsgi, I'm guessing).

After changing this line:

os.execvp('uwsgi', ['uwsgi', '-H', venv_path] + sys.argv[1:])

to

os.execvp('path/to/my/virtualenv/bin/uwsgi', ['path/to/my/virtualenv/bin/uwsgi', '-H', venv_path] + sys.argv[1:])

uWSGI changed from using Python 2.7 to Python 3.5.

Upvotes: 0

Mrinal Roy
Mrinal Roy

Reputation: 979

If you have used the default venv or virtualenv to create the virtual environment you're going to use. Then you can specify the path like the following:

uwsgi -H /fullpath/to/virtualenv

Here -H is the shortcut. Documentation on this: uWSGI Options.

Upvotes: 0

Related Questions