Error loading MySQLdb module: No module named MySQLdb - python-2.7

i am getting this error when running python manage.py syncdb.
I've tried installing all the packages that were described in various posts to no avail.I desperately want a solution as i have lost too many time in this!
Thanks in advance for any help!
Edit: Also my setting for database is:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg3', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'db1', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': 'XYZ', # Not used with sqlite3.
'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
}
}
My O.S is Linux Mint 17.1 Mate.
Also do i need to install django in a virtual environment?

Try installing this way
apt-get install python-dev libmysqlclient-dev
pip install MySQL-python

Phew!
Got it working at last!
Seems like my Django package was not compatible with libs & dependencies.I created a virtual environment and installed the latest Django package as well as its dependencies, libs etc.
That is it!

Related

Having hard time deploying Django + PostGis on AWS Beanstalk (DatabaseOperations error)

I’m having troubles making Django + PostGIS work on AWS BeanStalk.
The app runs, some parts of the app work properly, but when trying to access object with GeoDjango fields (PointField) I get this error:
Attribute Error
'DatabaseOperations' object has no attribute 'select'
/opt/python/run/venv/lib/python3.4/site-packages/django/contrib/gis/db/models/fields.py
in select_format, line 61
I have googled this error, and very few people encountered it. The closest error I could find is: Getting 'DatabaseOperations' object has no attribute 'geo_db_type' error when doing a syncdb
But my databases is configured correctly in the Django Settings Module as follows:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': os.environ['RDS_DB_NAME'],
'USER': os.environ['RDS_USERNAME'],
'PASSWORD': os.environ['RDS_PASSWORD'],
'HOST': os.environ['RDS_HOSTNAME'],
'PORT': os.environ['RDS_PORT'],
}
}
I’m using Django 1.9.5 with PostGis 2.3.0 and PostgreSQL 9.5.2
I’m using a custom AMI based on 2017.03 that I made using this script:
https://gist.github.com/nitrag/932ecd7d109f9d1e3ed378353e0d5c2f
PostGis is installing properly on the EC2 instance, I even tried another script and got the same final error. (http://www.daveoncode.com/2014/02/18/creating-custom-ami-with-postgis-and-its-dependencies-to-deploy-django-geodjango-amazon-elastic-beanstalk/)
I am really on my last legs here, any help will be greatly appreciated!

How do I get Jython-Django to work with Postgresql JDBC

I have tried to setup an instance of Django on Jython using Postgresql. I can't get Django to talk to Postgresql. Can someone help me figure out what is wrong?**
So far, I have the following system installed for development:
Windows 7
JDK7 (x86)
Jython Version 2.7b2
Django-1.6.5
django-jython 1.7.0b2(Database backends and management commands, for development underDjango/Jython)
postgresql-9.3.5-1-windows-x64.exe
Eclipse-PyDev
I was able to run the server and database, but now I am having issues with configuring Django to work with the Postgresql database.
I followed the configuration steps here:
https://pythonhosted.org/django-jython/database-backends.html#postgresql
My settings.py file has the following:
DATABASES = {
'default': {
'ENGINE': 'doj.db.backends.postgresql',
'NAME': 'gate',
'USER': 'gate',
'PASSWORD': 'test',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
When I check my class path:
C:\>echo %CLASSPATH%
C:\Program Files (x86)\Java\jdk1.7.0_67\bin.;C:\Program Files (x86)\Java\jre7\li
b\ext\QTJava.zip
I have the JDBC file postgresql-9.3-1102.jdbc41.jar in the lib folder listed above.
Error Message from Django
File "C:\jython2.7b2\Lib\site-packages\django\db\utils.py", line 131, in load_backend raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'doj.db.backends.postgresql' isn't an available
database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
Error was: No module named schema
I believe the problem is that you are using the wrong version of Django.
Jython-Django is compatible only starting from 1.7.
See https://docs.djangoproject.com/en/1.6/howto/jython/

Error was: No module named backends.spatialite.base

For testing purposes I'm trying to use SQLite, but it seems I'm missing the spatialite backend:
django.core.exceptions.ImproperlyConfigured: 'django.contrib.gis.backends.spatialite' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named backends.spatialite.base
Any idea how I can make Django find it?
I have installed spatialite.
This is my db setup:
DATABASES['default'] = {
'ENGINE': 'django.contrib.gis.backends.spatialite',
'NAME': '/tmp/test.db'
}
Ubuntu 12.04.1 LTS; Python 2.7.3; Django 1.4.1
You should look for:
django.contrib.gis.db.backends.spatialite
not
django.contrib.gis.backends.spatialite
:)
trying importing from shell

Django MongoDB Engine connection failure

[SOLVED] After successfully completing the django tutorial, I have tried to use mongoDB as a database, with Django MongoDB Engine. This is the database configuration in settings.py:
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine',
'NAME': 'test',
'HOST': 'localhost',
'PORT': 27017,
# 'OPTIONS' : {
# 'slave_okay' : True,
# }
}
}
And this is the error message I get, after running python manage.py syncdb
:
raise AutoReconnect("could not find master/primary")
pymongo.errors.AutoReconnect: could not find master/primary
I got this error, even after shutting down the mongoDB server, so I figured out that this needed to be a connection issue. I posted an answer on how I solved this.
Using Ubuntu 12.04 LTS x64, Python 2.7, django 1.4.2, mongoDB x86_64 2.2.1 (clean new install)
The way I solved this is so simple that I am almost ashamed at myself for asking the question in the first place, but I hope it will be useful:
I simply upgraded the Django MongoDB Engine by typing into the terminal:
sudo pip install git+https://github.com/django-nonrel/mongodb-engine --upgrade
And that's it.
Can you try running ...
db.repairDatabase()
... from the mongo terminal?

Crossplatform deployment

I'm working with Django project on Linux and Windows. So I'm trying to config 'settings.py' to work on both platforms.
I can config the template dirs as:
TEMPLATE_DIRS = (
'c:/artefacts/workspace/BookMixToFb2/src/templates',
'/home/demas/workspace/BookMixToFb2/src/templates'
)
and this will be work on linux and windows.
But when I setup a database connection I have only one possibility to set way to the database file:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
#'NAME': 'C:\\Users\\ademidov.GMCS\\workspace\\BookMixToFb2\\sqlite.db', # Or path to database file if using sqlite3.
'NAME': '/home/demas/workspace/BookMixToFb2/sqlite.db', # Or path to database file if using sqlite3.
Is there any way to set two different paths to database file and pass the current path as command line argument?
Yes, you should use this tip: Use os.path.dirname() in settings.py to avoid hardcoded dirnames.