Python 2.7 Django/MySQL issue - django

I was using Django with Python 2.7 on Windows 7 and I installed XAMPP and used the PHPMyAdmin MySQL included with it to create a database to use in Django, but when I went and used the "python manage.py syncdb" command, I got this error:
Traceback (most recent call last):
File "iFriends\manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 443, in execute_from
_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 382, 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_comman
d
klass = load_command_class(app_name, subcommand)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 69, 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 import_module
__import__(name)
File "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py", line 8, 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 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "C:\Python27\lib\site-packages\django\db\__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
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 24, in load_backend
return import_module('.base', backend_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\Python27\lib\site-packages\django\db\backends\mysql\base.py", line 16, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
I have checked the host, username, password and those are correct, I really want to use Django so if anyone can help me on this, that would be great.

You need to install mysql lib for windows.
http://www.codegood.com/archives/4
http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python
http://www.codegood.com/archives/129

You require a dependency
easy_install mysql-python

Related

pkg_resources.DistributionNotFound: Django==1.8.3 in Django 1.9

I use Django 1.9 after updating of Django 1.8, and when i type command
django-admin runserver
I got this one error:
Traceback (most recent call last):
File "/usr/local/bin/django-admin", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2749, in <module>
working_set = WorkingSet._build_master()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 446, in _build_master
return cls._build_from_requirements(__requires__)
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 459, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 628, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: Django==1.8.3
And then I try to type this one command:
django-admin.py runserver
I got this one error:
Traceback (most recent call last):
File "/usr/local/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 195, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 39, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 16, in <module>
from django.db.migrations.executor import MigrationExecutor
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 7, in <module>
from .loader import MigrationLoader
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 10, in <module>
from django.db.migrations.recorder import MigrationRecorder
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 12, in <module>
class MigrationRecorder(object):
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 26, in MigrationRecorder
class Migration(models.Model):
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 27, in Migration
app = models.CharField(max_length=255)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 1072, in __init__
super(CharField, self).__init__(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 166, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 41, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
I try uninstall and install Django. But i still have this errors. Hope somebody can help me with it. Thanks
You shouldn't normally use django-admin, except when you do django-admin startproject.
After you have created the project, it is easier to use manage.py to run the dev server, because it takes care of setting the path and settings module for you.
./manage.py runserver
See the docs for more information.
Maybe you used another python version? It is python 2.7 now, and it seems you don't installed django properly for python2.7. You can try
python3 manage.py runserver
for using python3 in ubuntu (it is installed by default and accessibler with python3), or try to define how to run it with another python version.

django exception: libperconaserverclient.so.18: cannot open shared object file: No such file or directory

I am new to django.
I get this error when I update settings.py with database and run
$python2.7 manage.py migrate
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
module: libperconaserverclient.so.18: cannot open shared object file:
No such file or directory
Is it because of version of mysql ? if so which version should I use ?
$ python2.7 manage.py migrate
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/sachints/project/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 327, in execute
django.setup()
File "/home/sachints/project/env/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/home/sachints/project/env/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 49, in <module>
class AbstractBaseUser(models.Model):
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/models/base.py", line 108, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/models/base.py", line 299, in add_to_class
value.contribute_to_class(cls, name)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/models/options.py", line 263, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/utils.py", line 212, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/utils.py", line 116, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 28, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: libperconaserverclient.so.18: cannot open shared object file: No such file or directory
I am using RHEL 6.7, MySql Server version: 5.1.73 and Python 2.7.11
yum -y install mysql-devel
ln -s /usr/local/mysql/lib/libperconaserverclient_r.so.18 /usr/lib
ln -s /usr/local/mysql/lib/libperconaserverclient_r.so /usr/lib
Idconifg
done!

Lettuce and Django 1.55+ getting ImportError: cannot import name WSGIServerException

Just tried integrating Lettuce into my django installation and getting the following error:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/var/www/abc/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/var/www/abc/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/var/www/abc/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/var/www/abc/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 75, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/var/www/abc/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/var/www/abc/local/lib/python2.7/site-packages/lettuce/django/__init__.py", line 19, in <module>
from lettuce.django.server import Server
File "/var/www/abc/local/lib/python2.7/site-packages/lettuce/django/server.py", line 33, in <module>
from django.core.servers.basehttp import WSGIServerException
ImportError: cannot import name WSGIServerException
I heard that WSGIServerException was removed from django, so how do I get around this?
It's fixed on branch master, but it not yet available on PyPI.
You can simply install it from the source:
pip install -e git+https://github.com/gabrielfalcao/lettuce.git#egg=lettuce
the doc
The undocumented django.core.servers.basehttp.WSGIServerException has
been removed. Use socket.error provided by the standard library
instead.
i think you can tell "lettuce"'s author,0.0 .or: update "lettuce" python package.

Django MongoDB problem

my django app run with mysql, but when i try with mongodb then show thie error
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/home/abdullah/django-trunk/django/core/management/__init__.py", line 442, in execute_manager
utility.execute()
File "/home/abdullah/django-trunk/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/abdullah/django-trunk/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/abdullah/django-trunk/django/core/management/base.py", line 209, in execute
translation.activate('en-us')
File "/home/abdullah/django-trunk/django/utils/translation/__init__.py", line 106, in activate
return _trans.activate(language)
File "/home/abdullah/django-trunk/django/utils/translation/trans_real.py", line 191, in activate
_active.value = translation(language)
File "/home/abdullah/django-trunk/django/utils/translation/trans_real.py", line 180, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/abdullah/django-trunk/django/utils/translation/trans_real.py", line 157, in _fetch
app = import_module(appname)
File "/home/abdullah/django-trunk/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/abdullah/django-trunk/django/contrib/admin/__init__.py", line 3, in <module>
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
File "/home/abdullah/django-trunk/django/contrib/admin/helpers.py", line 2, in <module>
from django.contrib.admin.util import (flatten_fieldsets, lookup_field,
File "/home/abdullah/django-trunk/django/contrib/admin/util.py", line 1, in <module>
from django.db import models
File "/home/abdullah/django-trunk/django/db/__init__.py", line 27, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/home/abdullah/django-trunk/django/db/utils.py", line 82, in __getitem__
conn = backend.DatabaseWrapper(db, alias)
File "/usr/local/lib/python2.6/dist-packages/django_mongodb_engine-0.4.0-py2.6.egg/django_mongodb_engine/base.py", line 87, in __init__
self.ops = DatabaseOperations(self)
File "/usr/local/lib/python2.6/dist-packages/djangotoolbox-0.9.2-py2.6.egg/djangotoolbox/db/base.py", line 28, in __init__
super(NonrelDatabaseOperations, self).__init__()
TypeError: __init__() takes exactly 2 arguments (1 given)
** I have installed all necessary module installed, but when i want to runserver then show this message
I managed to fix the same error by using these packages on github:
https://github.com/django-nonrel/django-nonrel
https://github.com/django-nonrel/djangotoolbox
instead of the ones recommended on Django-Mongodb's setup page. Also, make sure to use the master branch of each, so as to not run into compatibility problems. If you're using pip, you can either pip install each of the following lines separately, or put them into your version of a requirements.txt file for your project:
git+https://github.com/django-nonrel/django-nonrel#master
git+https://github.com/django-nonrel/djangotoolbox#master
git+https://github.com/django-nonrel/mongodb-engine#master
And then run
pip install -r requirements.txt

Cannot connect to Oracle database with Django on Ubuntu

Whenever I try to run a command like python manage.py syncdb, I get the following error:
Traceback (most recent call last):
File "manage.py", line 11, in
execute_manager(settings)
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 67, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/south/management/commands/__init__.py", line 10, in
import django.template.loaders.app_directories
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/template/loaders/app_directories.py", line 21, in
mod = import_module(app)
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/contrib/admin/__init__.py", line 1, in
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/contrib/admin/helpers.py", line 1, in
from django import forms
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/forms/__init__.py", line 17, in
from models import *
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/forms/models.py", line 6, in
from django.db import connections
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/db/__init__.py", line 77, in
connection = connections[DEFAULT_DB_ALIAS]
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/db/utils.py", line 91, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/db/utils.py", line 32, in load_backend
return import_module('.base', backend_name)
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/db/backends/oracle/base.py", line 24, in
raise ImproperlyConfigured("Error loading cx_Oracle module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading cx_Oracle module: libclntsh.so.11.1: cannot open shared object file: No such file or directory
Is this resolvable on Ubuntu?
You need to install both cx_Oracle and an Oracle Client.
cx_Oracle can be found here.
An appropriate Oracle Client can be found here.
You will also need to set the LD_LIBRARY_PATH variable before you start your application. This can usually be done (for example):
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
Now you should be able to get past the cx_Oracle error message.
First things first - is this actually a Django problem, or just a cx_Oracle problem? Is cx_Oracle installed correctly? Can you connect to your Oracle database in a Python shell session?
import cx_Oracle
conn = cx_Oracle.connect('/') # user/password#dsn
cursor = conn.cursor()
If this doesn't raise an exception, you have connected successfully.
try easy_install cx_Oracle, it will compile cx_Oracle module from source