: Error loading MySQLdb module: No module named MySQLdb - django

django.core.exceptions.ImproperlyConfigured:
Error loading MySQLdb module: No module named MySQLdb
Tell me the solution where I can change the code

You need to install MySQL-python. It can be done, for example, using pip:
pip install MySQL-python
Also, you'll need some libs to be able to install it. In Debian linux it can be done by following command:
sudo apt-get install build-essential python-dev libmysqlclient-dev

Use pip install mysqlclient. For me, pip install MySQL-python doesn't always work on my Windows.
Reference: Official documentation on MySQL DB API drivers

Related

Unable to locate package flask_mysqldb

I'm trying to install flask_mysqldb by using "sudo apt install flask_mysqldb". But I am getting error as "Unable to locate package flask_mysqldb"
This Python package that you can only install from PyPi repository. Check docs. You need to use pip to install it:
$ pip install flask-mysqldb

Error while running PIP command "no module packaging exists"

I have tried many approaches in resolving this issue but still cannot resolve it can someone please help me.
when I try to run the pip to install any new package it is ending in error with the message no module named packaging.version. This is happening in the __init__.py file where there are import command import packaging.version.
I tried to install the packaging package by using the command pip install packaging even that ended in failure with the same error.
Then I tried to install this package using the apt-get command
sudo apt-get install python-packaging but it ended saying could not find the package.
Finally I tried to update the setuptools package to version 33.1.1 as a part of the previous solutions approaches, but can't do it with pip(same issue as above) so I used the apt-get command
sudo apt-get install setuptools=33.1.1 but it is saying no package with this version found error.
I am out of ideas can someone please help. Appreciate your help.
I believe that your version of pip is obsolete. Try running pip install --upgrade pip.
If you cant do it (still the same error), I'd suggest to reinstall pip.
You can do it with get-pip.py file. Here you can find a quick guide: Installing pip setuptools and wheel.
You may also be able to reinstall it with python -m pip install -U pip.

installing pyobjc on mac osx 10.9

I'm trying to download pyobjc on my mac, which runs on 10.9.3. I've tried using easy_install, pip, and manual install. I have setuptools installed with Xcode 5.
When I use easy_install, pip, or manual install I get the error: AttributeError: 'module' object has no attribute '_install_lib' right before it quits, along with other errors before this. For easy_install I type the following line in the terminal:
easy_install -U pyobjc
and for pip I use:
pip -U pyobjc
for manual install I use:
python setup.py install
I too was having this problem, also described here. It seems to be a problem with setuptools. I was able to successfully install PyObjC by reinstalling setuptools first, i.e.:
$> sudo pip uninstall setuptools
$> pip install setuptools
$> pip install pyobjc
Hope that helps.
I think this was fixed in pyobjc 2.5.1.

Installing MySQL-python for Django

I've just learned how to use virtualenv and I installed Django 1.4.5. I'm assuming that the virtualenv created a clean slate for me to work on so with the Django 1.4.5 installed, I copied all my previous files into the virtualenv environment.
I tried to run the server but I get an error saying "no module named MySQLdb". I think this means that I forgot to install MySQL-python. I tried to install it via
pip install MySQL-python
But I get this error
Downloading/unpacking MySQL-python
Running setup.py egg_info for package MySQL-python
The required version of distribute (>=0.6.28) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U distribute'.
(Currently using distribute 0.6.24 (/home/bradford/Development/Django/django_1.4.5/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg))
Complete output from command python setup.py egg_info:
The required version of distribute (>=0.6.28) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U distribute'.
(Currently using distribute 0.6.24 (/home/bradford/Development/Django/django_1.4.5/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg))
----------------------------------------
Command python setup.py egg_info failed with error code 2 in /home/bradford/Development/Django/django_1.4.5/build/MySQL-python
Not quite sure how to go about fixing this problem =/ any help much appreciated!
I recently had exactly this issue (just not in relation to Django). In my case I am developing on Ubuntu 12.04 using the default pip and distribute versions, which are basically a little out of date for MySQL-python.
Because you are working in an isolated virtualenv, you can safely follow the suggested instruction without affecting your Python installation.
So you can...
workon your_virtualenv #activate your virtualenv, you do use virtualenvwrapper, right?
easy_install -U distribute #update distribute on your virtualenv
pip install MySQL-python #install your package
If for some reason upgrading distribute is not an option, you could try installing an older version of MySQL-python as follows (you'd have to check this version is compatible with your version of Django):
pip install MySQL-python==x.y.z #where x.y.z is the version you want
Spent an hour looking through stackoverflow. Evntually found answer in the other question. This is what saved me:
sudo apt-get install libmysqlclient-dev
mysql_config goes with the package.
When doing in a virtualenv :
pip install MySQL-python
I got
EnvironmentError: mysql_config not found
To install mysql_config, as Artem Fedosov said, first install
sudo apt-get install libmysqlclient-dev
then everything works fine in virtualenv
MySQL driver for Python (mysql-python) needs libmysqlclient-dev. You can get it with:
sudo apt-get update
sudo apt-get install libmysqlclient-dev
If python-dev is not installed, you may have to install it too:
sudo apt-get install python-dev
Now you can install MySQL driver:
pip install mysql-python
Here is a more detailed documentation for MySQL in Django:
http://codex.themedelta.com/how-to-install-django-with-mysql-in-a-virtualenv-on-linux/
I had to do this:
pip install mysql-python
inside the virtualenv
The commands are always run in ubuntu:
easy_install -U distribute
later
sudo apt-get install libmysqlclient-dev
and finally
pip install MySQL-python
The suggested solutions didn't work out for me, because I still got compilation errors after running
`$ sudo apt-get install libmysqlclient-dev`
so I had to run
apt-get install python-dev
Then everything worked fine for me with
apt-get install python-dev
Try this:
Version Python 2.7
MySQL-python package, you should use either MySQL_python‑1.2.5‑cp27‑none‑win32.whl or
MySQL_python‑1.2.5‑cp27‑none‑win_amd64.whl depending on whether you have installed 32-bit or 64-bit Python.
pip install MySQL_python‑1.2.5‑cp27‑none‑win32.whl
if you are using mysqlclient package, then use
mysqlclient‑1.4.6‑cp27‑cp27m‑win32.whl or
mysqlclient‑1.4.6‑cp27‑cp27m‑win_amd64.whl
pip install mysqlclient‑1.4.6‑cp27‑cp27m‑win32.whl
https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient

django_auth_ldap no module named ldap

I am trying to get the django_auth_module working but I don't think I managed to install it properly.
I downloaded the package and ran setup.py install.
Then in my settings.py file I tried to import the module ldap and it gave me the following error :
ImportError: no module named ldap
I am working on a CentOS 6 server.
Maybe it has to do with where I should install the module? The folder is in the directory just above my site folder, but maybe that's wrong...
RESOLVED :
Ok, I just needed to install the module python-ldap... problem solved!
Install missing module
Hint: To install python-ldap with pip on Ubuntu, some libraries are needed.
Use the apt-get commands to install them.
Python 2
sudo apt-get install python-dev libldap2-dev libsasl2-dev libssl-dev
sudo pip install python-ldap
Python 3
sudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev
sudo pip3 install pyldap
Try the below command to install for Python3.
sudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev
sudo pip3 install pyldap