运行py文件报错:ImportError: No module named MySQLdb
https://stackoverflow.com/questions/25459386/mac-os-x-environmenterror-mysql-config-not-found
高手给的建议:
-
You installed python
-
You did brew install mysql
-
You did export PATH=$PATH:/usr/local/mysql/bin
And finally, you did pip install MySQL-Python
后来又报错:Mac OS X - EnvironmentError: mysql_config not found
mac用brew安装mysql
happymmdeMacBook-Pro:~ happymm$ brew install mysql
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
ship sloc
==> Updated Formulae
anjuta certbot dmd exploitdb gdal gtk-doc kakoune midnight-commander smartmontools
bdw-gc cglm e2fsprogs eye-d3 gnu-tar hydra libxml2 paket uriparser
binaryen confluent-oss evince fn gradle itstool mackup php
==> Deleted Formulae
gnome-doc-utils rock
==> Downloading https://homebrew.bintray.com/bottles/mysql-8.0.13.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring mysql-8.0.13.high_sierra.bottle.tar.gz
==> /usr/local/Cellar/mysql/8.0.13/bin/mysqld --initialize-insecure --user=happymm --basedir=/usr/local/Cellar/mysql/8.0.13 --datadir=/usr/local/var/mysql --tmpdir=/tmp
==> 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
To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start
==> Summary
? /usr/local/Cellar/mysql/8.0.13: 267 files, 237MB
安装完了后,怎么还是报错?
后来我按照提示语: mysql.server start
启动了服务,在运行py文件就不报错了
安装完后pip list查看mysql相关的包,不知道我上面的安装步骤是对应的下面哪个?
mysql-connector-python 8.0.13
mysqlclient 1.3.14
PyMySQL 0.9.3
安装指定版本的依赖包
python2.7依赖包的版本,不对,也会导致报错,安装过程中发现有提示版本不兼容,
卸载 pip uninstall 包名
安装指定版本 pip install 包名==版本号
如果提示权限有问题就加上 sudo 后,命令如:sudo pip install 包名==版本号