在macos上使用mysql设置django

xoefb8l8  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(356)

我是django的新手,正在尝试在macos上建立一个连接到mysql的基本web应用程序。然而,我似乎无法让mysqlclient在macos上工作。
我正在运行一个虚拟环境和以下版本:

$ brew --version
Homebrew 1.8.5
$ pip --version
pip 18.1
$ python --version
Python 3.7.1
$ mysql --version
mysql  Ver 8.0.12 for osx10.14 on x86_64 (Homebrew)

当我尝试的时候 pip install mysqlclient (https://pypi.org/project/mysqlclient/)我明白了

ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'gcc' failed with exit status 1

根据文档“您可能需要像这样安装python和mysql开发头和库:” $ brew install mysql-connector-c 这会产生另一个错误:

Error: Cannot install mysql-connector-c because conflicting formulae are installed.
  mysql: because both install MySQL client libraries

Please `brew unlink mysql` before continuing.
$ brew unlink mysql
$ brew install mysql-connector-c 
==> Pouring mysql-connector-c-6.1.11.mojave.bottle.tar.gz
?  /usr/local/Cellar/mysql-connector-c/6.1.11: 79 files, 15.3MB
brew link mysql
Error: Could not symlink bin/my_print_defaults
Target /usr/local/bin/my_print_defaults
is a symlink belonging to mysql-connector-c
$ brew link --overwrite mysql

现在我可以从控制台启动mysql了,但是当我更新django,mysite settings.py连接到mysql时,我得到了

ModuleNotFoundError: No module named 'MySQLdb'

以下是相关设置.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', 
        'NAME': 'django',
        'USER': 'root',
        'PASSWORD': 'XXXXXX',
        'HOST': 'localhost', 
        'PORT': '3306',
    }
}

我还根据错误报告检查了mysql\u配置https://bugs.mysql.com/bug.php?id=86971

Usage: /usr/local/bin/mysql_config [OPTIONS]
Compiler: Clang 10.0.0.10001145
Options:
        --cflags         [-I/usr/local/Cellar/mysql/8.0.12/include/mysql ]
        --cxxflags       [-I/usr/local/Cellar/mysql/8.0.12/include/mysql ]
        --include        [-I/usr/local/Cellar/mysql/8.0.12/include/mysql]
        --libs           [-L/usr/local/Cellar/mysql/8.0.12/lib -lmysqlclient -lssl -lcrypto]
        --libs_r         [-L/usr/local/Cellar/mysql/8.0.12/lib -lmysqlclient -lssl -lcrypto]
        --plugindir      [/usr/local/Cellar/mysql/8.0.12/lib/plugin]
        --socket         [/tmp/mysql.sock]
        --port           [0]
        --version        [8.0.12]
        --variable=VAR   VAR is one of:
                pkgincludedir [/usr/local/Cellar/mysql/8.0.12/include/mysql]
                pkglibdir     [/usr/local/Cellar/mysql/8.0.12/lib]
                plugindir     [/usr/local/Cellar/mysql/8.0.12/lib/plugin]

我尝试过很多不同的解决方案,但到目前为止都没有成功。感觉自己像掉进了兔子洞-非常感谢任何帮助;)
我已经在下面几页中查看了建议的解决方案,但还没有解决方案:
mysql python安装mac
错误:安装mysqlclient时命令“x86\u 64-linux-gnu-gcc”
mysql python安装mac
我怀疑这个问题是由于mysql服务器和connector/c同时安装中描述的问题造成的。。。https://dev.mysql.com/doc/refman/5.7/en/c-api-multiple-installations.html 但不知道该怎么办。

4nkexdtk

4nkexdtk1#

ld: library not found for -lssl ->缺少openssl包,最好是openssl开发包。
从这个github问题

brew install openssl
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

相关问题