your programing

django.core.exceptions.ImproperlyConfigured : MySQLdb 모듈로드 오류 : MySQLdb라는 모듈이 없습니다.

lovepro 2020. 10. 6. 18:51
반응형

django.core.exceptions.ImproperlyConfigured : MySQLdb 모듈로드 오류 : MySQLdb라는 모듈이 없습니다.


mysql을 위해 데이터베이스에 연결하는 동안 직면 한 문제. 내가 사용한 데이터베이스 설정도 제공했습니다.

 Traceback (most recent call last):
 File "manage.py", line 10, in <module>
 execute_from_command_line(sys.argv)
 File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/home/ar/Desktop/test/testprac/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 "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 77, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/home/arundhati/Desktop/test/testprac/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/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 "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/sql.py", line 9, in <module>
from django.db import models
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/utils.py", line 27, in load_backend
return import_module('.base', backend_name)
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/ar/Desktop/test/testprac/local/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: No module named MySQLdb

Databse 설정 ::

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'ar_test_db',                      # Or path to database file if using 
        # The following settings are not used with sqlite3:
        'USER': '',
        'PASSWORD': '',
        'HOST': '',                      # Empty for localhost through domain sockets or   '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}

도움을 주셔서 감사합니다 !!


python mysql 패키지가 설치되어 있지 않은 것 같습니다.

pip install mysql-python

또는 가상 환경을 사용하지 않는 경우 (* nix 호스트에서) :

sudo pip install mysql-python

python-mysqldb-MySQL에 대한 Python 인터페이스를 설치해야합니다.

시험
sudo apt-get install python-mysqldb


pip로 mysqlclient를 설치하는 중에 오류가 발생하면 mysql dev 라이브러리가 부족할 수 있습니다. 다음을 실행하여 설치하십시오.

apt-get install libmysqlclient-dev

mysqlclient를 다시 설치하십시오.

pip install mysqlclient

python, mysql, sequel pro 응용 프로그램을 사용하여 Mac OS X Mountain Lion에서 PyCharm에 대한 Django 개발 환경을 설정할 때이 스레드의 소유자와 동일한 오류가 발생했습니다. 그러나 Mac OS Mountain Lion x86_x64 (MySql과 Python도 동일한 아키텍처 여야 함)에서 python-mysqldb를 실행하고 이미 pip 등과 같은 모든 것을 시도한 사람들에 대한 내 대답입니다.이 문제를 해결하려면 다음 단계를 수행하십시오.

  1. 여기 에서 Python 용 MySql을 다운로드 하십시오.
  2. 다운로드 한 파일의 압축을 풉니 다. 터미널 창에서 다음을 수행하십시오. tar xvfz downloade.tar.
  3. cd / to untared 디렉토리
  4. sudo python setup.py install 실행
  5. "Environment Error : / usr / local / bin / mysql_config not found"와 같은 오류가 발생하면 다음과 같이 경로를 추가해보십시오. "export PATH = $ PATH : / usr / local / mysql / bin". 하지만 이드는 나를 도와주지 않았고 나는 다른 해결책을 찾았다. 명령 실행 끝에 다음과 같은 오류 출력이 표시됩니다.

    mysql_config에서 "/path_to_file/MySQL-python-1.2.4b4/setup_posix.py"파일, 25 행, 환경 오류 발생 ( "% s 찾을 수 없음"% (mysql_config.path,))

  6. vim으로 setup_posix.py를 열고 25 행으로 이동합니다 (동일한 버전이 아니면 다를 수 있음).

  7. mysql에 '/ usr / local / mysql / bin /'과 같은 심볼릭 링크가 없다면 25 행은 편집 후 다음과 같이 보일 것입니다.

    f = popen("%s --%s" % ('/usr/local/mysql/bin/mysql_config', what))

  8. 이 후 다음과 같은 또 다른 오류가 발생했습니다.

    django.core.exceptions.ImproperlyConfigured : MySQLdb 모듈로드 오류 : dlopen (/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so, 2) : 라이브러리가로드되지 않음 : libmysqlclient.18.dylib 참조 위치 : /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so 이유 : 이미지를 찾을 수 없음

  9. 마지막으로 콘솔에서 다음을 수행했습니다.

    sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

현재 모든 것이 잘 작동합니다. 따라서 Mac을 사용하는 사람에게 도움이되기를 바랍니다. :)


내 대답은 @ Ron-E와 비슷하지만 몇 가지 오류 / 수정 사항이 더 있으므로 Mavericks 및 Python 2.7.6에서 Mac OSX에 대한 단계를 아래에두고 있습니다.

  1. Python mysql 패키지 설치 (성공 메시지가 표시되면 아래 단계 무시)

    pip install mysql-python
    
  2. 위의 작업을 수행 할 때 "EnvironmentError : mysql_config not found"오류가 발생했습니다. 여기에 이미지 설명 입력이 문제를 해결하기 위해 터미널에서 다음을 수행했습니다.

    export PATH=$PATH:/usr/local/mysql/bin
    
  3. 1 단계를 다시 실행하면 "오류 : 명령 'cc'가 종료 상태 1로 실패했습니다."라는 새 오류가 표시됩니다. 여기에 이미지 설명 입력이 문제를 해결하기 위해 터미널에서 다음을 수행했습니다.

     export CFLAGS=-Qunused-arguments
     export CPPFLAGS=-Qunused-arguments
    
  4. 1 단계를 다시 실행하고 'Successfully installed mysql-python'성공 메시지를 받았습니다!


파이썬 mysqldb라이브러리 가 없습니다 . 다음 명령 (Debian / Ubuntu 용)을 사용하여 설치합니다.sudo apt-get install python-mysqldb


Windows 환경의 경우 여기에서 Mysql-python을 다운로드하여 설치하십시오. http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python .


SQL 커넥터를 찾지 못했기 때문입니다. 시험:

pip install mysqlclient

Ubuntu에서는 배포 저장소를 사용하는 것이 좋습니다.

sudo apt-get install python-mysqldb

This happened with me as well and I believe this has become a common error not only for Django developers but also for Flask as well, so the way I solved this issue was using brew.

  1. brew install mysql
  2. sudo pip install mysql-python

This way every single issue was solved and both frameworks work absolutely fine.

P.S.: For those who use macports (such as myself), this can be an issue as brew works in a different level, my advice is to use brew instead of macports

I hope I could be helpful.


For Ubuntu 16.04 and 18.04 or python 3 versions

sudo apt-get install python3-mysqldb

With the same error message as Will, it worked for me to install mysql first as the missing file will be added during the installation. So after

brew install mysql

pip install mysql-python

ran without errors.


Just to add to other answers, if you're using Django, it is advisable that you install mysql-python BEFORE installing Django.


I wasted a lot of time on this. Turns out that the default database library is not supported for Python 3. You have to use a different one.


if the error looks like this

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module:
dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: 
/usr/local/opt/mysql/lib/libmysqlclient.20.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_mysql.so

then try :

pip install python-mysqldb

Faced similar issue. I tried installing mysql-python using pip, but it failed due to gcc dependency errors.

The solution that worked for me

conda install mysql-python

Please note that I already had anaconda installed, which didn't had gcc dependency.


I was having the same problem.The following solved my issue

Run pip install pymysql in your shell

Then, edit the init.py file in your project origin directory(the same as settings.py) and then

add:

import pymysql

pymysql.install_as_MySQLdb()

this should solve the problem.


If you are using pyhton version 3.4 or above. you have to install

sudo apt-get install python3-dev libmysqlclient-dev 

터미널에서. 그런 다음 pip install mysqlclient가상 환경 또는 pip를 설치 한 위치에 설치하십시오.


나는 한 해결 이 환경에서이 문제를 :

$ pyenv --version
pyenv 1.2.9

$ python --version
Python 3.7.2

$ python -m django --version
2.1.7

./settings.py

DATABASES = {
    'default': {
        'NAME': 'my_db_name',
        'ENGINE': 'mysql.connector.django',   # 'django.db.backends.mysql'
        'USER': '<user>',
        'PASSWORD': '<pass>',
        'HOST': 'localhost',
        'PORT': 3306,
        'OPTIONS': {
            'autocommit': True,
        },
    }
}

을 사용하는 경우 다음을 'ENGINE': 'mysql.connector.django'실행하는 드라이버를 설치하십시오.

$ pip install mysql-connector-python
Successfully installed mysql-connector-python-8.0.15 protobuf-3.7.0 six-1.12.0

그것은 $ pip install mysql-python나를 위해 작동하지 않았습니다.

을 사용하는 경우 다음을 'ENGINE': 'django.db.backends.mysql'실행하는 드라이버를 설치해야합니다.
$ pip install mysqlclient

마지막으로 실행하십시오.
$ python manage.py migrate

괜찮다면 파이썬은 다음 모든 테이블 ID 데이터베이스를 생성합니다.

auth_group
auth_group_permissions
auth_permission
auth_user
auth_user_groups
auth_user_user_permissions
django_admin_log
django_content_type
django_migrations
django_session

다음 작동 모드를 시도해 볼 수 있습니다.
sudo python manage.py runserver 0.0.0.0:8000


Python 폴더에 대한 권한이없는 것 같습니다. 시험sudo chown -R $USER /Library/Python/2.7

참고 URL : https://stackoverflow.com/questions/15312732/django-core-exceptions-improperlyconfigured-error-loading-mysqldb-module-no-mo

반응형