mac 安装mysqlclient失败解决方法

2020-09-14  本文已影响0人  Ballpenww

执行安装报错

$ pip install mysqlclient
....
      File "setup_posix.py", line 26, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/f0/wcdxffsj375_dfjw0qwhvwm80000gn/T/pip-install-e8aa82/mysqlclient/

处理方法:

说明: 我使用的mysql@5.7版本

  1. 安装mysql@5.7
brew install mysql@5.7
  1. 这是执行mysql是找不到对应命令的
  2. 执行brew info mysql@5.7查看对应的说明文档,里面说的告诉了我们解决方案
➜  ~ brew info mysql@5.7
mysql@5.7: stable 5.7.26 (bottled) [keg-only]
Open source relational database management system
https://dev.mysql.com/doc/refman/5.7/en/
/usr/local/Cellar/mysql@5.7/5.7.26 (320 files, 231.8MB)
  Poured from bottle on 2020-09-05 at 07:51:59
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql@5.7.rb
==> Dependencies
Build: cmake ✘
Required: openssl ✔
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

mysql@5.7 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have mysql@5.7 first in your PATH run:
  echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc

For compilers to find mysql@5.7 you may need to set:
  export LDFLAGS="-L/usr/local/opt/mysql@5.7/lib"
  export CPPFLAGS="-I/usr/local/opt/mysql@5.7/include"


To have launchd start mysql@5.7 now and restart at login:
  brew services start mysql@5.7
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/mysql@5.7/bin/mysql.server start

其中可以看到

If you need to have mysql@5.7 first in your PATH run:
  echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc`

For compilers to find mysql@5.7 you may need to set:
  export LDFLAGS="-L/usr/local/opt/mysql@5.7/lib"
  export CPPFLAGS="-I/usr/local/opt/mysql@5.7/include"

将这些语句添加到~/.zshrc中,执行source ~/.zshrc或者zsh
直接进入你的virtualenv环境,执行对应的安装即可:

➜  ✗ source venv/bin/activate
(venv) ➜   ✗ pip3 install mysqlclient==2.0.1
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Collecting mysqlclient==2.0.1
  Downloading http://mirrors.aliyun.com/pypi/packages/a5/e1/e5f2b231c05dc51d9d87fa5066f90d1405345c54b14b0b11a1c859020f21/mysqlclient-2.0.1.tar.gz (87kB)
    100% |████████████████████████████████| 92kB 978kB/s
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (setup.py) ... done
  Stored in directory: /Users/lixiaotong/Library/Caches/pip/wheels/12/50/39/04e1a898e2c01e86484fff6d8f2db2023b23cdc0988b6356d3
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.0.1
You are using pip version 19.0.3, however version 20.2.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
上一篇 下一篇

猜你喜欢

热点阅读