'ModuleNotFoundError: No module named 'MySQLdb' In Django

浪子不回头ぞ 提交于 2020-07-07 11:05:28

问题


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'

回答1:


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.

  • MySQL DB API Drivers -- MySQLdb



回答2:


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



回答3:


If you are on a virtual environment then

pip install MySQL-python

You can also check this related issue.



来源:https://stackoverflow.com/questions/47490797/modulenotfounderror-no-module-named-mysqldb-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!