django, pyenv, uwsgi - ModuleNotFoundError: No module named 'django' - python

I have the following vassal configuration in /etc/uwsgi/vassals/gsd.ini:
[uwsgi]
plugins = python
env = DJANGO_SETTINGS_MODULE=%n.settings
virtualenv = /home/toogy/.pyenv/versions/%n
chdir = /home/webapps/%n
module = %n.wsgi:application
master = true
vacuum = true
pidfile = /tmp/uwsgi-%n.pid
socket = /tmp/uwsgi-%n.sock
daemonize = /var/log/uwsgi/%n.log
chmod-socket = 666
uid = toogy
gid = toogy
Here is the uwsgi log I get
Tue Feb 7 10:49:12 2017 - received message 1 from emperor
...gracefully killing workers...
Gracefully killing worker 1 (pid: 31406)...
worker 1 buried after 1 seconds
binary reloading uWSGI...
chdir() to /etc/uwsgi/vassals
closing all non-uwsgi socket fds > 2 (max_fd = 1024)...
found fd 3 mapped to socket 0 (/tmp/uwsgi-gsd.sock)
running /usr/bin/uwsgi
*** has_emperor mode detected (fd: 7) ***
[uWSGI] getting INI configuration from gsd.ini
*** Starting uWSGI 2.0.14 (64bit) on [Tue Feb 7 10:49:13 2017] ***
compiled with version: 6.3.1 20170109 on 18 January 2017 00:35:47
os: Linux-3.14.32-xxxx-grs-ipv6-64 #7 SMP Wed Jan 27 18:05:09 CET 2016
nodename: renard
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /etc/uwsgi/vassals
detected binary path: /usr/bin/uwsgi
chdir() to /home/webapps/gsd
your processes number limit is 15700
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)
uwsgi socket 0 inherited UNIX address /tmp/uwsgi-gsd.sock fd 3
Python version: 3.6.0 (default, Jan 16 2017, 12:12:55) [GCC 6.3.1 20170109]
PEP 405 virtualenv detected: /home/toogy/.pyenv/versions/gsd
Set PythonHome to /home/toogy/.pyenv/versions/gsd
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x39d21f0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145536 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
added /home/webapps/gsd/ to pythonpath.
Traceback (most recent call last):
File "/home/webapps/gsd/gsd/wsgi.py", line 12, in <module>
from django.core.wsgi import get_wsgi_application
ModuleNotFoundError: No module named 'django'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
gracefully (RE)spawned uWSGI master process (pid: 27844)
spawned uWSGI worker 1 (pid: 32312, cores: 1)
It cannot find django and I have no idea why because uwsgi seems to detect the python environment (in which django is installed).
Also, it says Python version: 3.6.0 while my virtualenv Python version is 3.5.2. I don't know if this is supposed to happen. The system Python version is 3.6.0.
I am using the last versions of the uwsgi and uwsgi-plugins-python Arch Linux official packages.

The problem was that the system-wide python version linked to uwsgi needs to be the same as the one of the virtualenv, which, I think, is a very stupid thing.
EDIT April 2021: I now recommend using gunicorn, which does not have this problem

In my case it was using the system wide uwsgi, I'm working using a virtualenv so if I execute
$ which uwsgi
I got /usr/local/python3.6/bin/uwsgi
As Valentin Iovene suggests you need to use the uwsgi from your virtual environment
My directories structure is something like this:
~/Env
--/app
--/bin
----/....
----/uwsgi <-- This should be the good one
----/...
--/include
--/lib
(The app directory is where my django app resides)
In my case uwsgi file hasn't execution permissions so I only executed:
$ chmod +x ~/Env/bin/uwsgi
Finally under my app directory I executed the uwsgi command as follows:
../bin/uwsgi --http :8000 --module app.wsgi
Now I can see my app working now :)
I'm following this guide: https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
Next steps are configuring nginx and https...
I know it's a late response but hope this helps and shared what worked for me.

I also found some possible pitfalls I want to share:
check, if virtualenv (which is the same as venv, pyhome and home) is set to that directory, that contains the bin, include, lib, ... directories
check, if the user (uid) can read the files in your project and the libs in virtual environment (this ends in a ModuleNotFoundError instead of a permission error)
use need-app to exit on failures (this helps for debugging and should be default imho)
use strict to avoid typos in config (this should also be default...)
if your test.py runs, try to import modules of your project and your virtual environment, to test if that works. It also helps to add a
import sys
print(sys.path)
You can also copy the printed sys.path, open a python shell and set sys.path to the same value and try to import the desired wsgi module.

look at this at gsd.ini:
virtualenv = /home/toogy/.pyenv/versions/%n
have you install django under this virtualenv?

When I execute:
uwsgi --socket client_book.sock --module myproject.wsgi --chmod-socket=666
in the directory ~/, and I would get the following error:
ModuleNotFoundError: No module named 'myproject.wsgi'
The solution was to run the command one layer deeper in the directory ~/myproject
This way, uwsgi was able to find myproject.wsgi.
This was what fixed it for me.

Related

How can use Uwsgi? where is my python home path?

I'm trying to deploy my django app with ec2. and I follow some instruction.
but when I try to connect Uwsgi and my django app, there is a problem
(unifolio-back) ubuntu#ip-172-31-37-172:~$ which python
/home/ubuntu/.local/share/virtualenvs/unifolio-back-_HCbnSkq/bin/python
(unifolio-back) ubuntu#ip-172-31-37-172:~$ uwsgi --http :8080 --home /home/ubuntu/.local/share/virtualenvs/unifolio-back-_HCbnSkq/bin/python --chdir /srv/unifolio-back/ -w mysite.wsgi
*** Starting uWSGI 2.0.19.1 (64bit) on [Sat Dec 19 09:54:26 2020] ***
compiled with version: 7.5.0 on 19 December 2020 01:14:28
os: Linux-5.4.0-1029-aws #30~18.04.1-Ubuntu SMP Tue Oct 20 11:09:25 UTC 2020
nodename: ip-172-31-37-172
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/ubuntu
detected binary path: /home/ubuntu/.local/share/virtualenvs/unifolio-back-_HCbnSkq/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /srv/unifolio-back/
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3802
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)
uWSGI http bound on :8080 fd 4
spawned uWSGI http 1 (pid: 2408)
uwsgi socket 0 bound to TCP address 127.0.0.1:40925 (port auto-assigned) fd 3
Python version: 3.6.9 (default, Oct 8 2020, 12:12:24) [GCC 8.4.0]
!!! Python Home is not a directory: /home/ubuntu/.local/share/virtualenvs/unifolio-back-_HCbnSkq/bin/python !!!
Set PythonHome to /home/ubuntu/.local/share/virtualenvs/unifolio-back-_HCbnSkq/bin/python
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007f54d0d2a600 (most recent call first):
Aborted (core dumped)
what is the problem? I guess there is something wrong with python path... but I can't fine the way to solve this.
Ubuntu's uses uwsgi's plugin based architecture. In order to successfully run a Python 3 application, you need the uwsgi-plugin-python3 plugin. First, install it with apt:
$ sudo apt install uwsgi-plugin-python3
Then, change your uwsgi command to the following:
uwsgi --http :8080 --virtualenv /home/ubuntu/.local/share/virtualenvs/unifolio-back-_HCbnSkq \
--chdir /srv/unifolio-back/ -w mysite.wsgi --plugins python3
If you are using Mac, install uwsgi using homebrew and use it.
$ brew install uwsgi
$ where uwsgi
/Users/chillaranand/homebrew/bin/uwsgi

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.
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.
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.

'import site' failed while trying to run UWSGI + virtualenv

I have installed Python 2.7 on CentOS and created a virtualenv for my project using:
$ virtualenv -p /usr/local/bin/python2.7 venv
I have installed uwsgi with virtualenv deactivated.
I have also installed uwsgi-plugin-python, as I was facing 'unavailable modifier requested:' issue.
nginx config:
upstream django {
server unix:///tmp/mysite.sock; # for a file socket
}
server {
listen 80;
server_name mysite;
charset utf-8;
client_max_body_size 75M; # adjust to taste
location /media {
alias /projects/mysite/media;
}
location /static {
alias /projects/rebus/rebus/static;
}
location / {
uwsgi_pass django;
include /etc/nginx/uwsgi_params;
}
}
uwsgi ini file:
[uwsgi]
chdir = /projects/mysite
module = mysite.wsgi
virtualenv = /projects/mysite/venv
plugin = python
master = true
processes = 2
socket = /tmp/mysite.sock
chmod-socket = 664
vacuum = true
Now when I launch it and try to access the website:
uwsgi --ini mysite_uwsgi.ini
I get the following log:
*** Starting uWSGI 2.0.11.1 (64bit) on [Wed Aug 19 12:01:22 2015] ***
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-11) on 21 July 2015 15:58:54
os: Linux-2.6.32-042stab084.12 #1 SMP Tue Nov 26 20:18:08 MSK 2013
nodename: vs23.wovz.net
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 8
current working directory: /var/run
detected binary path: /usr/sbin/uwsgi
chdir() to /projects/mysite
your processes number limit is 1024
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)
uwsgi socket 0 bound to UNIX address /tmp/mysite.sock fd 3
Python version: 2.6.6 (r266:84292, Jul 23 2015, 15:22:56) [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)]
Set PythonHome to /projects/mysite/venv
'import site' failed; use -v for traceback
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x12e7160
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 218304 bytes (213 KB) for 2 cores
*** Operational MODE: preforking ***
Traceback (most recent call last):
File "./mysite/wsgi.py", line 10, in <module>
import os
ImportError: No module named os
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 1106)
spawned uWSGI worker 1 (pid: 1107, cores: 1)
spawned uWSGI worker 2 (pid: 1108, cores: 1)
--- no python application found, check your startup logs for errors ---
It looks like my virtualenv with Python 2.7 is not recognized and UWSGI fails to load my Django app. How can I fix that?
This might also have to do with which version of Python uwsgi was compiled against. You'll see the same symptom ('import site' failed) on systems where the default Python is 2.7 if you create a virtual environment using --python=python3 but use a uwsgi obtained via pip install uwsgi instead of pip3 install uwsgi.
maybe you didn't install uwsgi module in your virtualenv
solution:
source /projects/mysite/venv/bin/activate
pip install uwsgi
then rerun your uwsgi server and it maybe work

How to get uwsgi working with nginx and Django 1.7?

This is what I tried:
I have a django.conf inside /etc/nginx/sites-available/
upstream django {
server unix:///tmp/uwsgi.sock;
}
server {
listen 80;
server_name weasyprint.django.dev;
charset utf-8;
error_log /var/log/nginx/django-weasyprint.log;
location / {
uwsgi_pass django;
include /etc/nginx/uwsgi_params;
}
}
And then I do a sudo ln -s /etc/nginx/sites-available/django.conf inside sites-enabled
And then I restarted nginx.
I created a django folder called weasyprint_site inside /var/virtual/WebApps/virtualenvs/WeasyPrintProject
I used virtualenv on the same folder, so now my structure is like this:
WeasyPrintProject
|---------bin
|---------include
|---------lib
|---------local
|---------share
|---------weasyprint_site
|------------db.sqlite3
|------------manage.py
|------------test.py
|------------uwsgi.ini
|------------weasyprint_site
and then I also put in a uwsgi.ini as you can see above.
Its contents are:
[uwsgi]
socket=/tmp/uwsgi.sock
chmod-socket=666
uid = www-data
gid = www-data
chdir=/var/virtual/WebApps/virtualenvs/WeasyPrintProject
module=weasy_print.wsgi:application
master=true
pidfile=/var/virtual/WebApps/virtualenvs/WeasyPrintProject/weasy_print.pid
vacuum=true
When I am at /var/virtual/WebApps/virtualenvs/WeasyPrintProject/weasyprint_site,
I run
uwsgi --ini uwsgi.ini
I get the following:
[uWSGI] getting INI configuration from uwsgi.ini
*** Starting uWSGI 2.0.9 (64bit) on [Thu Feb 19 11:59:12 2015] ***
compiled with version: 4.8.2 on 16 February 2015 05:39:16
os: Linux-3.13.0-43-generic #72-Ubuntu SMP Mon Dec 8 19:35:06 UTC 2014
nodename: vagrant-ubuntu-trusty-64
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /var/virtual/WebApps/virtualenvs/WeasyPrintProject/weasyprint_site
writing pidfile to /var/virtual/WebApps/virtualenvs/WeasyPrintProject/weasy_print.pid
detected binary path: /var/virtual/WebApps/virtualenvs/WeasyPrintProject/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /var/virtual/WebApps/virtualenvs/WeasyPrintProject
your processes number limit is 15934
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)
uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3
Python version: 2.7.6 (default, Mar 22 2014, 23:03:41) [GCC 4.8.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1915160
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145536 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
ImportError: No module named weasy_print.wsgi
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 1913)
spawned uWSGI worker 1 (pid: 1914, cores: 1)
I have 2 issues:
I cannot get back to bash unless I do a Ctrl+C
there is an import error saying no module named weasy_print.wsgi
I followed the instructions in here
My virtualenv for this particular project is to use python 2.7.4 and I am attempting to run django 1.7. The environment is Ubuntu 14.04
How do I get the django app to work.
Firstly, you're chdiring into WeasyPrintProject, but your project is in WeasyPrintProject/weasyprint_site. You should chdir into that directory inside your uwsgi.ini file.
Secondly, your project name is weasyprint_site, not weasy_print, so you should call module weasyprint_site.wsgi:application instead.
And last problem is: you should specify path to your virtualenv inside uwsgi.ini, so uwsgi process can now where are additional packages required by your application.
To return to your console without interrupting your uwsgi server, you must put it in background, by forking it, daemonizing it or simply launching from init script. I personally recomment using emperor/vassals system built in into wsgi.
Also having your project inside virtualenv directory is not recommended.

Django, VirtualEnv, Ubuntu, uwsgi/gunicorn: Unable to locate all python/django modules

I'm trying to setup uWSGI to serve my django app but I'm having issues with the path, or at least I think it's a path issue. The symptom is that when I make a curl request to the application, I get tracebacks indicating that basic python/django modules can't be found. ex:
File "/opt/example/venvs/example/lib/python2.7/site-packages/django/test/_doctest.py", line 104, in <module> import unittest, difflib, pdb, tempfile
File "/usr/lib/python2.7/pdb.py", line 59, in <module>
class Pdb(bdb.Bdb, cmd.Cmd): AttributeError: 'module' object has no attribute 'Cmd'
I've looked at the other SO related questions but none appear to be my issue.
Here's my setup:
django==1.5.1
uwsgi==1.9.15 (installed from pip)
python is 2.7
Ubuntu 12.04 LTS
nginx = 0.8.54 ( but I don't believe this is relevant as I haven't connected uwsgi up to nginx yet )
I'm running in a vagrant created virtualbox, with chef and fab doing all the typical provisioning.
Here's the path of the VM once I've ssh'd into the machine:
PATH="/opt/example/venvs/example/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/vagrant_ruby/bin"
Here's the .wsgi file ( fairly standard except for the print path that I added for debug ):
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")
import sys
print sys.path
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Here's the uwsgi ini file ( notice all the various pythonpaths that I had to add ):
[uwsgi]
#socket=/tmp/hs.com.sock
virtualenv=/opt/example/venv
chdir=/opt/example/apps/example/src
module=example.wsgi:application
master=true
workers=8
pidfile=/opt/example/apps/example/src/example/uwsgi-master.pid
max-requests=5000
#plugins=python
enable-threads=true
processes=2
no-site=true
http=:8003
#env=DJANGO_SETTINGS_MODULE=example.settings
pythonpath=..
pythonpath=/vagrant/src
pythonpath=/opt/example/apps/example/src/example
pythonpath=/opt/example/venvs/example/lib/python2.7
pythonpath=/opt/example/venvs/example/lib/python2.7/plat-linux2
pythonpath=/opt/example/venvs/example/lib/python2.7/lib-tk
pythonpath=/opt/example/venvs/example/lib/python2.7/lib-old
pythonpath=/opt/example/venvs/example/lib/python2.7/lib-dynload
pythonpath=/opt/example/venvs/example/lib/python2.7/distutils
#pythonpath=/opt/example/venvs/example/lib/python2.7/encodings
#pythonpath=/opt/example/venvs/example/lib/python2.7/config
pythonpath=/usr/lib/python2.7/
pythonpath=/usr/lib/python2.7/lib-dynload/
pythonpath=/usr/lib/python2.7/distutils/
pythonpath=/usr/lib/python2.7/plat-linux2/
pythonpath=/usr/lib/python2.7/lib-tk/
#pythonpath=/opt/example/venvs/example/lib/python2.7/site-packages/django/
#pythonpath=/opt/example/venvs/example/lib/python2.7/site-packages/django/core/
pythonpath=/opt/example/venvs/example/lib/python2.7/site-packages/django/core/management
#pythonpath=/opt/example/venvs/example/lib/python2.7/site-packages/django/core/management/commands
pythonpath=/opt/example/venvs/example/local/lib/python2.7/site-packages
pythonpath=/opt/example/venvs/example/lib/python2.7
pythonpath=/opt/example/venvs/example/lib/python2.7/site-packages
pythonpath=/vagrant/src/example
The reason there are so many pythonpaths in there is because the app was failing to find very basic modules, and so I kept adding paths to make it resolve. This worked for several errors, but 1) I can't find the proper path for the Cmd attributerror above and 2) adding each of these individual paths just doesn't FEEL right.
the uwsgi output to 'uwsgi --ini inifile'
[uWSGI] getting INI configuration from xxx
*** Starting uWSGI 1.9.15 (32bit) on [Fri Sep 13 18:12:44 2013] ***
compiled with version: 4.6.3 on 13 September 2013 06:46:44
os: Linux-3.2.0-23-generic-pae #36-Ubuntu SMP Tue Apr 10 22:19:09 UTC 2012
nodename: xxx
machine: i686
clock source: unix
detected number of CPU cores: 1
current working directory: /vagrant/src
writing pidfile to /opt/example/apps/example/src/example/uwsgi-master.pid
detected binary path: /opt/example/venvs/example/bin/uwsgi
your processes number limit is 1824
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uWSGI http bound on localhost:8003 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:34622 (port auto-assigned) fd 3
Python version: 2.7.3 (default, Apr 10 2013, 06:03:17) [GCC 4.6.3]
Set PythonHome to /opt/example/venv
Python main interpreter initialized at 0xa044e58
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 192012 bytes (187 KB) for 2 cores
*** Operational MODE: preforking ***
added ../ to pythonpath.
added /vagrant/src/ to pythonpath.
added /opt/example/apps/example/src/example/ to pythonpath.
added /opt/example/venvs/example/lib/python2.7/ to pythonpath.
added /opt/example/venvs/example/lib/python2.7/plat-linux2 to pythonpath.
added /opt/example/venvs/example/lib/python2.7/lib-tk to pythonpath.
added /opt/example/venvs/example/lib/python2.7/lib-old to pythonpath.
added /opt/example/venvs/example/lib/python2.7/lib-dynload/ to pythonpath.
added /opt/example/venvs/example/lib/python2.7/distutils/ to pythonpath.
added /usr/lib/python2.7/ to pythonpath.
added /usr/lib/python2.7/lib-dynload/ to pythonpath.
added /usr/lib/python2.7/distutils/ to pythonpath.
added /usr/lib/python2.7/plat-linux2/ to pythonpath.
added /usr/lib/python2.7/lib-tk/ to pythonpath.
added /opt/example/venvs/example/lib/python2.7/site-packages/django/core/management/ to pythonpath.
added /opt/example/venvs/example/local/lib/python2.7/site-packages/ to pythonpath.
added /opt/example/venvs/example/lib/python2.7/ to pythonpath.
added /opt/example/venvs/example/lib/python2.7/site-packages/ to pythonpath.
added /vagrant/src/example/ to pythonpath.
['/vagrant/src/example/', '/opt/example/venvs/example/lib/python2.7/site-packages/', '/opt/example/venvs/example/lib/python2.7/', '/opt/example/venvs/example/local/lib/python2.7/site-packages/', '/opt/example/venvs/example/lib/python2.7/site-packages/django/core/management/', '/usr/lib/python2.7/lib-tk/', '/usr/lib/python2.7/plat-linux2/', '/usr/lib/python2.7/distutils/', '/usr/lib/python2.7/lib-dynload/', '/usr/lib/python2.7/', '/opt/example/venvs/example/lib/python2.7/distutils/', '/opt/example/venvs/example/lib/python2.7/lib-dynload/', '/opt/example/venvs/example/lib/python2.7/lib-old', '/opt/example/venvs/example/lib/python2.7/lib-tk', '/opt/example/venvs/example/lib/python2.7/plat-linux2', '/opt/example/venvs/example/lib/python2.7/', '/opt/example/apps/example/src/example/', '/vagrant/src/', '../', '.', '', '/opt/example/venv/lib/python2.7/', '/opt/example/venv/lib/python2.7/plat-linux2', '/opt/example/venv/lib/python2.7/lib-tk', '/opt/example/venv/lib/python2.7/lib-old', '/opt/example/venv/lib/python2.7/lib-dynload', '/vagrant/src/example']
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0xa044e58 pid: 2911 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 2911)
spawned uWSGI worker 1 (pid: 2912, cores: 1)
spawned uWSGI worker 2 (pid: 2913, cores: 1)
spawned uWSGI http 1 (pid: 2914)
From another terminal I run curl -v localhost:8003 and I get the 'AttributeErrror...' i posted above. The curl output is:
curl: (52) Empty reply from server
* Closing connection #0
Here's what I've tried:
using the latest uWSGI version 1.9.15 and the LTS version 1.4.x
installing uWSGI inside the virtualenv and outside of it
django's runserver serves my app just fine, and I can see the path that's printed out because of the debug print sys.path statement in the wsgi file and it's simply a subset of the paths that I have in my wsgi.ini file
also printed out environment variables in both runserver and uwsgi environments from the wsgi.py file and I don't see anything of importance that are different
uwsgi is able to serve a basic test.py application file without issue, so I believe that eliminates any installation/setup issues
tried running uwsgi with sudo
I also tried it with a basic django app ( created directly from startproject ), and this ALSO FAILS with the same attributeerror, and requires the same list of pythonpaths.
I must be missing some simple setup or configuration... ? Let me know if more information is required.
Edit1: This doesn't look to be specific to uWSGI, but more related to the virtualenv setup and path. I installed gunicorn and had the exact same results.
I think your uwsgi.ini file is missing an 's' on
virtualenv=/opt/example/venv

Categories

Resources