II'm new on django .
I am using ubuntu 13.04
Although i created the databse through phpmyadmin and also entered the credentials in settings.py
but when i typed in the console
python manage.py syncdb
i got this error
Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/init.py", line 453, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/init.py", line 392, 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 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/init.py", line 77, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 8, in
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
File "/usr/local/lib/python2.7/dist-packages/django/core/management/sql.py", line 9, in
from django.db import models
File "/usr/local/lib/python2.7/dist-packages/django/db/init.py", line 40, in
backend = load_backend(connection.settings_dict['ENGINE'])
File "/usr/local/lib/python2.7/dist-packages/django/db/init.py", line 34, in getattr
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 93, in getitem
backend = load_backend(db['ENGINE'])
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 27, in load_backend
return import_module('.base', backend_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 17, in
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
i have tried giving extensions to db name in settings.py but it didn't work.
Please suggest what to do.
Thanks !
Or you can do:
sudo apt-get install python-mysqldb
Do you have mysql installed in you virtual environment
Try
pip install MySQL-python
Related
I am setting up a Django backend for my application. I am trying to change the default sqlite database to mysql. While performing the first migration, I get the following error:
Traceback (most recent call last): File
"/Users/user1/djangoApp/djangoProject/env/lib/python3.6/site-packages/django/db/backends/mysql/base.py",
line 15, in
import MySQLdb as Database File "/Users/user1/djangoApp/djangoProject/env/lib/python3.6/site-packages/MySQLdb/init.py",
line 18, in
import _mysql ImportError: dlopen(/Users/user1/djangoApp/djangoProject/env/lib/python3.6/site-packages/_mysql.cpython-36m-darwin.so,
2): Library not loaded: #rpath/libmysqlclient.21.dylib Referenced
from:
/Users/user1/djangoApp/djangoProject/env/lib/python3.6/site-packages/_mysql.cpython-36m-darwin.so
Reason: image not found
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "manage.py", line 15, in
execute_from_command_line(sys.argv) File "/Users/user1/djangoApp/djangoProject/env/lib/python3.6/site-packages/django/core/management/init.py",
line 381, in execute_from_command_line
utility.execute() File "/Users/user1/djangoApp/djangoProject/env/lib/python3.6/site-packages/django/core/management/init.py",
line 357, in execute
django.setup() File "/Users/user1/djangoApp/djangoProject/env/lib/python3.6/site-packages/django/init.py",
line 24, in setup
apps.populate(settings.INSTALLED_APPS) File "/Users/user1/djangoApp/djangoProject/env/lib/python3.6/site-packages/django/apps/registry.py",
line 112, in populate
app_config.import_models() File "/Users/user1/djangoApp/djangoProject/env/lib/python3.6/site-packages/django/apps/config.py",
line 198, in import_models
self.models_module = import_module(models_module_name) File "/Users/user1/djangoApp/djangoProject/env/lib/python3.6/importlib/init.py",
line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level) File "", line 994, in _gcd_import File
"", line 971, in _find_and_load File
"", line 955, in _find_and_load_unlocked
File "", line 665, in _load_unlocked
File "", line 678, in
exec_module File "", line 219, in
_call_with_frames_removed File "/Users/user1/djangoApp/djangoProject/env/lib/python3.6/site-packages/django/contrib/auth/models.py",
line 2, in
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager File
"/Users/user1/djangoApp/djangoProject/env/lib/python3.6/site-packages/django/contrib/auth/base_user.py",
line 47, in
class AbstractBaseUser(models.Model): File "/Users/user1/djangoApp/djangoProject/env/lib/python3.6/site-packages/django/db/models/base.py",
line 101, in new
new_class.add_to_class('_meta', Options(meta, app_label)) File "/Users/user1/djangoApp/djangoProject/env/lib/python3.6/site-packages/django/db/models/base.py",
line 305, in add_to_class
value.contribute_to_class(cls, name) File "/Users/user1/djangoApp/djangoProject/env/lib/python3.6/site-packages/django/db/models/options.py",
line 203, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) File
"/Users/user1/djangoApp/djangoProject/env/lib/python3.6/site-packages/django/db/init.py",
line 33, in getattr
return getattr(connections[DEFAULT_DB_ALIAS], item) File "/Users/user1/djangoApp/djangoProject/env/lib/python3.6/site-packages/django/db/utils.py",
line 202, in getitem
backend = load_backend(db['ENGINE']) File "/Users/user1/djangoApp/djangoProject/env/lib/python3.6/site-packages/django/db/utils.py",
line 110, in load_backend
return import_module('%s.base' % backend_name) File "/Users/user1/djangoApp/djangoProject/env/lib/python3.6/importlib/init.py",
line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level) File "/Users/user1/djangoApp/djangoProject/env/lib/python3.6/site-packages/django/db/backends/mysql/base.py",
line 20, in
) from err django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
OS:macOS Mojave
Framework: Django
I am using a virtualenv
I have already installed "mysqlclient" using the command
pip3 install mysqlclient
I have verified that the mysqlclient folder exists under the installed location.
I have the mysql server up and running.
I have tried many available solutions online but nothing works
To reproduce:
1 - Start a django project using
"django-admin startproject djangoApp"
2 - Install and start the mysql server.
3 - Update the settings.py file of the entry application to the following
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'djangoApp',
'USER': 'root',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': ''
}
}
4 - Now try to migrate using
python manage.py migrate
Expected:The migration should be successful
Actual:Migration fails with the given error
I am new to Django
I needed to symlink the lib files to the /usr/local/lib directory.
Fourth answer in the link worked for me
Thank you #Mohit Harshan #Daniel Rosema for taking time out to help me
Hi all and thanks for taking time to help.
I am a front-end developer and newbie on the Django project.
I am trying to config a project on my Mac.
My colleague helped me to install the virtual environment but it an error still be there when I try to run the server of my project(Hobbit is the name of my project).
(env) ➜ Hobbit git:(feature/sell_system_main) ✗ python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 6, in <module>
from django.contrib.admin.sites import AdminSite, site
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 4, in <module>
from django.contrib.admin.forms import AdminAuthenticationForm
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/contrib/admin/forms.py", line 6, in <module>
from django.contrib.auth.forms import AuthenticationForm
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/contrib/auth/forms.py", line 17, in <module>
from django.contrib.auth.models import User
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/contrib/auth/models.py", line 48, in <module>
class Permission(models.Model):
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/db/models/base.py", line 96, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/db/models/base.py", line 264, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/db/models/options.py", line 124, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/db/utils.py", line 198, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/db/utils.py", line 113, in load_backend
return import_module('%s.base' % backend_name)
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/liao/workspace/env/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 17, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/liao/workspace/env/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: /usr/local/mysql/lib/libmysqlclient.18.dylib
Referenced from: /Users/liao/workspace/env/lib/python2.7/site-packages/_mysql.so
Reason: image not found
So I try to reinstall mysql by pip install mysql-python and result is
Requirement already satisfied (use --upgrade to upgrade): mysql-python in /Users/liao/workspace/env/lib/python2.7/site-packages
It seems that I have installed mysql in virtual environment.
Now I am confused what is the problem. Mysql or Django?
I am trying to run iPython notebook on OSX Yosemite. I have installed everything via
pip install ipython[all]
and I see
mattia:~ mattiaspeziali$ pip freeze
backports.ssl-match-hostname==3.4.0.2
certifi==14.5.14
docutils==0.12
gnureadline==6.3.3
ipython==2.3.1
Jinja2==2.7.3
MarkupSafe==0.23
nose==1.3.4
numpy==1.8.2
numpydoc==0.5
pandas==0.14.1
Pygments==2.0.1
pyzmq==14.4.1
Sphinx==1.2.3
tornado==4.0.2
vboxapi==1.0
However, jinja2 seems not installed properly:
mattia:~ mattiaspeziali$ ipython notebook
Traceback (most recent call last):
File "/usr/local/bin/ipython", line 11, in <module>
sys.exit(start_ipython())
File "/Library/Python/2.7/site-packages/IPython/__init__.py", line 120, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 563, in launch_instance
app.initialize(argv)
File "<string>", line 2, in initialize
File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 92, in catch_config_error
return method(app, *args, **kwargs)
File "/Library/Python/2.7/site-packages/IPython/terminal/ipapp.py", line 321, in initialize
super(TerminalIPythonApp, self).initialize(argv)
File "<string>", line 2, in initialize
File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 92, in catch_config_error
return method(app, *args, **kwargs)
File "/Library/Python/2.7/site-packages/IPython/core/application.py", line 381, in initialize
self.parse_command_line(argv)
File "/Library/Python/2.7/site-packages/IPython/terminal/ipapp.py", line 316, in parse_command_line
return super(TerminalIPythonApp, self).parse_command_line(argv)
File "<string>", line 2, in parse_command_line
File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 92, in catch_config_error
return method(app, *args, **kwargs)
File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 475, in parse_command_line
return self.initialize_subcommand(subc, subargv)
File "<string>", line 2, in initialize_subcommand
File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 92, in catch_config_error
return method(app, *args, **kwargs)
File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 406, in initialize_subcommand
subapp = import_item(subapp)
File "/Library/Python/2.7/site-packages/IPython/utils/importstring.py", line 42, in import_item
module = __import__(package, fromlist=[obj])
File "/Library/Python/2.7/site-packages/IPython/html/notebookapp.py", line 42, in <module>
from jinja2 import Environment, FileSystemLoader
ImportError: No module named jinja2
I tried also to uninstall and re-install jinja2, but nothing changes. Any suggestion?
In addition:
mattia:~ mattiaspeziali$ which python
/usr/local/bin/python
mattia:~ mattiaspeziali$ which ipython
/usr/local/bin/ipython
mattia:~ mattiaspeziali$ which pip
/usr/local/bin/pip
Re-installing iPython solved the issue.
I had the same trouble with jinja2+ipython[notebook]. It seems that jinja2 is not mandatory to run ipython terminal and it is not installed by default.
But you must install it before ipython to be able to open a notebook.
I want to invoke a database with Django ORM. I have this problem:
*#*:~/standAlone$ python manage.py sql MyApp
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/*/django/core/management/__init__.py", line 443, in execute_fr om_command_line
utility.execute()
File "/home/*/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/*/django/core/management/__init__.py", line 261, in fetch_comm and
klass = load_command_class(app_name, subcommand)
File "/home/*/django/core/management/__init__.py", line 69, in load_comman d_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/home/*/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/*/django/core/management/commands/sql.py", line 4, in <module>
from django.core.management.sql import sql_create
File "/home/*/django/core/management/sql.py", line 6, in <module>
from django.db import models
File "/home/*/django/db/__init__.py", line 11, in <module>
if DEFAULT_DB_ALIAS not in settings.DATABASES:
File "/home/*/django/utils/functional.py", line 184, in inner
self._setup()
File "/home/*/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/home/*/django/conf/__init__.py", line 95, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings '{{ project_name }}.settings' (Is it on s
Is that {{ project_name }}.settings an artefact of the way you copy/pasted the code? Or is {{ project_name }} really in your manage.py file? That would explain the error. Probably left over from generating the project with some tool?
Alternatively, what's your django settings environment variable set to (django < 1.4). Or, what's the corresponding os.environ['...'] setting in your manage.py (if you use django 1.4)?
I'm running the following commands and get the following error:
root# sudo python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 67, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib/pymodules/python2.6/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/lib/pymodules/python2.6/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 "/usr/lib/pymodules/python2.6/django/core/management/sql.py", line 5, in <module>
from django.contrib.contenttypes import generic
File "/usr/lib/pymodules/python2.6/django/contrib/contenttypes/generic.py", line 6, in <module>
from django.db import connection
File "/usr/lib/pymodules/python2.6/django/db/__init__.py", line 77, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/usr/lib/pymodules/python2.6/django/db/utils.py", line 91, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/lib/pymodules/python2.6/django/db/utils.py", line 32, in load_backend
return import_module('.base', backend_name)
File "/usr/lib/pymodules/python2.6/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/lib/pymodules/python2.6/django/db/backends/mysql/base.py", line 14, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
I have a feeling that mysqldb isn't configured properly with django, I was wondering if i'm missing anything. i ran the following commands right before it:
# apt-get install python-django
# apt-get install python-mysqldb
I had this same issue where my virtualenv was broken and could no longer run django when I upgraded to ubuntu 12.04.
I simply ran (while my ve was active)
pip uninstall MySQL-python
and then re-installed it with
pip install MySQL-python
worked fine again after that.