I'm getting the following import error when I try to run uwsgi --ini <my uwsi ini file>
:
Traceback (most recent call last):
File "/var/www/mysite/venv/lib/python3.5/site-packages/django/db/backends/postgresql/base.py", line 20, in <module>
import psycopg2 as Database
File "/var/www/mysite/venv/lib/python3.5/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: No module named 'psycopg2._psycopg'
However, everything runs just fine when I run the site with
python manage.py runserver --settings=config.settings.prod
psycopg2
is installed, and can be found no problem by Django. Only when I run the server using uwsgi
can it not find the _psycopg
module.
This is my uwsgi.ini:
[uwsgi]
# variables
base = /var/www/mysite
# general settings
master = True
plugins = python3
vacuum = True
env = DJANGO_SETTINGS_MODULE=config.settings.prod
env = PYTHONHASHSEED=random
# directory containing packages
chdir=%(base)/server
# python modules and paths
home = %(base)/venv
module = config.wsgi:application
pythonpath = %(chdir)
pythonpath = %(home)/lib/python3.5/site-packages
# socket file settings
socket = %(base)/conf/%n.sock
uid = www-data
gid = www-data
chmod-socket = 644
chown-socket = www-data:www-data
# location of log files
logto = /var/log/uwsgi/%n.log
What can be the difference between these two modes? The only difference I see is that I run manage.py
as root, and uwsgi
runs as user www-data
(as per the .ini
), but running uwsgi
as root gave the same error.
Any clues?
EDIT:
Found a clue in the uwsgi
error log:
*** Starting uWSGI 2.0.7-debian (64bit) on [Mon Jan 18 22:27:08 2016] ***
compiled with version: 4.9.1 on 25 October 2014 19:17:54
os: Linux-3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt20-1+deb8u2 (2016-01-02)
nodename: averna
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /var/www/mysite/scripts
detected binary path: /usr/bin/uwsgi-core
your processes number limit is 1789
your memory page size is 4096 bytes
detected max file descriptor number: 65536
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /var/www/mysite/conf/uwsgi.sock fd 3
setgid() to 33
setuid() to 33
Python version: 3.4.2 (default, Oct 8 2014, 10:47:48) [GCC 4.9.1]
PEP 405 virtualenv detected: /var/www/mysite/venv
Set PythonHome to /var/www/mysite/venv
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x23b43f0
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 /var/www/mysite/server/ to pythonpath.
added /var/www/mysite/venv/lib/python3.5/site-packages/ to pythonpath.
Traceback (most recent call last):
File "/var/www/mysite/venv/lib/python3.5/site-packages/django/db/backends/postgresql/base.py", line 20, in <module>
import psycopg2 as Database
File "/var/www/mysite/venv/lib/python3.5/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: No module named 'psycopg2._psycopg'
It says uwsgi
is using Python version 3.4.2 (system version), but I'm running 3.5.1 in a virtualenv. Now how do I solve this without having to downgrade to Python 3.4.2 in my virtualenv?