1

creating my first module in django,

I am using mac Tried steps:

1.installed python 3.6.+ version,

2.cloned git project

3.setup local env,

to create a module, 
trying with command 
 env=dev python3 manage.py startapp supriya_module_inflow;

getting error in console :

Environment Selected :dev
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 24, in <module>
    import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 35, in <module>
    execute_from_command_line(sys.argv)......
...
 raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
Supriya Mishra
  • 139
  • 1
  • 1
  • 8

4 Answers4

9

MySQLdb does not support Python 3. You'll want to pick one of the other MySQL drivers.

At the time of writing, the latest release of MySQLdb (1.2.5) doesn’t support Python 3. In order to use MySQLdb under Python 3, you’ll have to install mysqlclient instead.

Here is How to install mysqlclient in Python using pip so as to be able to import MySQLdb in Django 3.1 when running Python 3.8.5..

Joseph
  • 789
  • 1
  • 9
  • 23
David Cain
  • 16,484
  • 14
  • 65
  • 75
  • I am not getting anything in this link, do you have any short command for the same ? – Supriya Mishra Nov 25 '17 at 21:56
  • "MySQLdb is the only [driver] not supporting Python 3 currently." - You'll need to install another one of the listed drivers if you want to work with Python 3. In short, `pip install mysqlclient` in your virtualenv should work. – David Cain Nov 25 '17 at 22:02
  • You'll need to supply some more information if you'd like more detailed help, but your issue is most likely rooted around what it means for a Python package to be installed system-wide versus in a virtuanenv (and what it means to activate a virtualenv). I'd recommend you do some reading there, and the solution to your current problems should become obvious! – David Cain Nov 26 '17 at 04:01
  • followed your steps after upgrading pip `python -m pip install --upgrade pip` worked :) – Anum Sheraz Oct 18 '18 at 22:30
1

The error message indicates that there is no module named MySQLdb. It means, Python needs a module to interface with MySQL database and that modules does not seems to be present in the system. All you need to do is, just install MySQL-Python module and the script should work without any problem.

Using Python Pip

pip install MySQL-python

Collecting MySQL-python
Installing collected packages: MySQL-python
 Running setup.py install for MySQL-python
Successfully installed MySQL-python-1.2.5

On Ubuntu based systems

# apt-get install python-mysqldb

On RHEL/CentOS based systems:

# yum install MySQL-python

Using easy_install

# easy_install mysql-python
0

If you are on a virtual environment then

pip install MySQL-python

You can also check this related issue.

binpy
  • 3,994
  • 3
  • 17
  • 54
  • Requirement already satisfied: MySQL-python in /Library/Python/2.7/site-packages getting this – Supriya Mishra Nov 25 '17 at 21:49
  • are you realy work in env now? your env created with `python3`, but the error message is python2. I think you aren't.. – binpy Nov 25 '17 at 21:51
  • 2
    you can activate it with command (if linux): `$ source dev/bin/activate`. and here you should install it `(dev) $ pip install MySQL-python`. the `dev` mean is the environtment that you created before. – binpy Nov 25 '17 at 21:58
0

** Building wheel for MySQL-python (setup.py) ... error ERROR: Command errored out with exit status 1:**

can't able to install MySQL-python and getting the above error .

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 04 '21 at 06:04
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/30254220) – bunnmatt Nov 04 '21 at 08:30