Unable to connect Django app to an external PostgreSQL database
Short Description
I am having a number of issues trying to connect a Django app (currently setup as SQLite3) to a newly created PostgreSQL on my Ubuntu Server.The Question(s)
Can anyone share their success in doing this? Is there a good step-by-step tutorial on doing this? Or at least useful pointers on how to debug this?Steps So Far (Background information)
1) I have installed PostgreSQL on my Ubuntu Server following this tutorial. Note that this produced Zero errors. 2) I configured my Django settings.py as seen belowDATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'mytestdb',
'USER': 'mux_user',
'PASSWORD': 'mux',
'HOST': '192.168.1.111',
'PORT': '',
}
}
3) Ran Django's 'syncdb'. This generated the following error.
django.core.exceptions.ImproperlyConfigured: Error loading psycopg module: No module named psycopg
4) Attempted to install psycopg with PIP, easy_install, and with the setup.py. All had the same failure of not being able to find the pg_config.
5) Google told me that I needed to install libpq-dev and python-dev in-order to compile the psycopg package. This is where I have lost most of my confidence in understanding what I am doing. I understand that these 2 packages are to al开发者_如何学Golow me to compile python source, but is it really necessary to do this?
System Information
Client: OS: OS X Snow Leopard-10.6.6 Django: Version 1.2.5 Python: 2.7 (running virtualenv)Soon to be client
OS: Windows XP / 7 Running an bundled executable of the python environment aboveServer:
OS: Ubuntu 10.10 (server, no gui) PostgreSQL: 8.4 (that's what apt-get install downloaded)Update
I did find in the documentation where it talks about needing to install psycopg. I suppose the question moves from do I really need this, to what is the best way to install psycopg on my clients.Update 5-13-2011: 9:20AM
After speaking with a colleague, I believe this SO question addresses most of my issuesI'm no Python guy but you do need the PostgreSQL libraries installed as the Python interface to PostgreSQL (psycopg) is just a Python layer on top of the PostgreSQL C libraries. So, no PostgreSQL development libraries means there's nothing to wrap in Python and no way to talk to PostgreSQL from Python.
You need to put your pg_config into your path, first locate this file on your machine, then run something similar to:
export PATH=$PATH:/opt/local/lib/postgresql90/bin
pip install psycopg2
If you do not have postgres installed on your client machine, then you should be able to install with macports:
sudo port install postgresql90
The issues I ran into were centered around using a 32bit install of Python (required by wxPython 2.8 on Snow Leopard). Please see my answer on this SO Question.
@mu is too short: Thanks for the help.
精彩评论