Hi Stackoverflow community,
I have recently been experimenting with setting up Django on dreamhost (using Passenger) and have come across a problem I can't seem to fix.
First of all, I have used the following guides to learn and set everything up:
1) Update new Django and Python 2.7.* with virtualenv on Dreamhost (with passenger)
2) http://www.ricksresources.com/2012/07/writing-wsgi-apps-on-dreamhost-shared-hosting/
3) http://wiki.dreamhost.com/Django
And here is a summary of the steps I have completed:
- Setup a subdomain sub.domain.com on dreamhost.com
- Enabled Passenger for the subdomain in order to take advantage of WSGI
- Installed Python 3.4 into my $HOME/Python3.4 directory
- Installed ez_setup.py in order to get pip
- Installed virtualenv in order to create a separate environment for the django project
- Created a virtualenv in $HOME/sub.domain.com/env/
- Downloaded and installed Django 1.7 using pip
- Started a djangoproject called djtest
Created a passenger_wsgi.py file in the subdomain root directory: sub.domain.com with the following code:
import sys, os cwd = os.getcwd() sys.path.append(cwd) project_location = cwd + "/djtest" sys.path.insert(0,project_location) PYTHON_EXE = '/home/USERNAME/DOMAIN/env/bin/python3' if sys.executable != PYTHON_EXE: os.execl(PYTHON_EXE, PYTHON_EXE, *sys.argv) sys.path.insert(0,'home/USERNAME/DOMAIN/env/bin') sys.path.insert(0,'home/USERNAME/DOMAIN/env/lib/python3.4/site-packages/django') sys.path.insert(0,'home/USERNAME/DOMAIN/env/lib/python3.4/site-packages') os.environ['DJANGO_SETTINGS_MODULE'] = "djtest.settings" from django.core.wsgi import get_wsgi_application application = get_wsgi_application()
After I try to access the domain I get the following error:
python3.4: error while loading shared libraries: libpython3.4m.so.1.0: cannot open shared object file: No such file or directory
Please note however, that Passenger + Python do work together since putting the following code into passenger_wsgi.py renders it correctly on the web:
def application(environ, start_response):
start_response('200 OK', [('content-type', 'text/html')])
return ['Hello world!']
I came across a few articles which are stating it is a problem related to not correctly specifying the public library path and the python path, i.e.: LD_LIBRARY_PATH and PYTHONPATH for example: Python: ImportError: No module named os
So I am guessing my mistake is somewhere around that and how to correctly specify those when running a setup in virtualenv.
Any help would be strong appreciated :)
Thank you!
~Aivoric
EDIT
It seems I found a solution...well django now fires up correctly...but I still don't know why the environment variables are not working. Why doesn't the LD_LIBRARY_PATH set by itself without having to hard-code it into the code?
So what I did was insert the line:
os.environ['LD_LIBRARY_PATH'] = '/home/USERNAME/Python34/lib'
Into this code:
import sys, os
cwd = os.getcwd()
sys.path.append(cwd)
project_location = cwd + "/djtest"
sys.path.insert(0,project_location)
os.environ['LD_LIBRARY_PATH'] = '/home/USERNAME/Python34/lib'
#Switch to new python
PYTHON_EXE = '/home/USERNAME/DOMAIN/env/bin/python3'
if sys.executable != PYTHON_EXE:
os.execl(PYTHON_EXE, PYTHON_EXE, *sys.argv)
sys.path.insert(0,'home/USERNAME/DOMAIN/env/bin')
sys.path.insert(0,'home/USERNAME/DOMAIN/env/lib/python3.4/site-packages/django')
sys.path.insert(0,'home/USERNAME/DOMAIN/env/lib/python3.4/site-packages')
os.environ['DJANGO_SETTINGS_MODULE'] = "djtest.settings"
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
I think the error was being generated when os.execl was being used but it was unable to find the shared libraries: libpython3.4m.so.1.0
If someone can tell me why that might have happened it will make me very happy :) thank you!