I'm new to Python and Django.
I'm configuring a Django project using a PostgreSQL database engine backend, But I'm getting errors on each database operation. For example when I run manage.py syncdb
, I'm getting:
C:\xampp\htdocs\djangodir>python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
438, in execute_manager
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
67, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in im
port_module
__import__(name)
File "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py"
, line 7, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_
signal
File "C:\Python27\lib\site-packages\django\core\management\sql.py", line 6, in
<module>
from django.db import models
File "C:\Python27\lib\site-packages\django\db\__init__.py", line 77, in <modul
e>
connection = connections[DEFAULT_DB_ALIAS]
File "C:\Python27\lib\site-packages\django\db\utils.py", line 92, in __getitem
__
backend = load_backend(db['ENGINE'])
File "C:\Python27\lib\site-packages\django\db\utils.py", line 33, in load_back
end
return import_module('.base', backend_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in im
port_module
__import__(name)
File "C:\Python27\lib\site-packages\django\db\backends\postgresql\base.py", li
ne 23, in <module>
raise ImproperlyConfigured("Error loading psycopg module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg module: No mo
dule named psycopg
Can someone give me a clue on what is going on?
The immediate problem seems to be that you're missing the psycopg module.
If you are using Fedora 20, Django 1.6.5, postgresql 9.3.* and you need the psycopg2 module, do this:
If you are like me, you may have trouble finding the well documented libpq-dev rpm... The above worked for me just now.
I was having the same Issue on Mac.
The solution was to use only PIP to install everything, and touch some things.
First install PIP from: https://pip.pypa.io/en/latest/
Then you want to make sure if path to pg_config is in your PATH (echo $PATH), if not you can edit your bash_profile:
and add this line:
If you don't know where pg_config is you can use the "locate" tool, but be sure your locate.db is up to date (i was using an old locate.db and using paths that does not exists).
Then install Django (if needed) and psycopg2.
And then in settings.py (localhost:defaultport)
Greets!
Year, this solve my problem. After execute this, do: pip install psycopg2
Step by step that I use:
You may want to install a graphic tool to manage your databases, for that you can do:
After, you must change Postgre user password, then do:
On your settings.py file you do:
Extra:
If you want to create the db using the command line you can just do:
On your settings.py file you do:
Please note that installation of
psycopg2
via pip or setup.py requires to have Visual Studio 2008 (more precisely executable file vcvarsall.bat). If you don't have admin rights to install it or set the appropriate PATH variable on Windows, you can download already compiled library from here.