Python Mac OS X - 环境错误:找不到 mysql_config
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25459386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mac OS X - EnvironmentError: mysql_config not found
提问by daniel_c05
First off, yeah, I've already seen this:
首先,是的,我已经看到了这个:
pip install mysql-python fails with EnvironmentError: mysql_config not found
pip install mysql-python 失败并出现 EnvironmentError: mysql_config not found
The problem
问题
I am trying to use Django on a Google App Engine project. However, I haven't been able to get started as the server fails to start properly due to:
我正在尝试在 Google App Engine 项目上使用 Django。但是,由于服务器无法正常启动,我一直无法启动:
ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
I did some research and it all pointed to having to install Mysql-python, as apparently it isn't on my system. I actually tried uninstalling it and got this:
我做了一些研究,这一切都表明必须安装 Mysql-python,因为它显然不在我的系统上。我实际上尝试卸载它并得到这个:
Cannot uninstall requirement mysql-python, not installed
Whenever I actually do try to install via:
每当我确实尝试通过以下方式安装时:
sudo pip install MySQL-python
I get an error stating:
我收到一条错误消息:
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
I've already tried running:
我已经试过运行:
export PATH=$PATH:/usr/local/mysql/bin
but that didn't seem to help, as I ran the installation command again and it still failed.
但这似乎没有帮助,因为我再次运行安装命令,但它仍然失败。
Any ideas?
有任何想法吗?
Please note I'm not in a virtualenv.
请注意,我不在 virtualenv 中。
采纳答案by daniel_c05
Ok, well, first of all, let me check if I am on the same page as you:
好吧,首先,让我检查一下我是否和你在同一页面上:
- 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(orpip3 install mysqlclientif using python 3)
- 你安装了python
- 你做到了
brew install mysql - 你做到了
export PATH=$PATH:/usr/local/mysql/bin - 最后,你做到了
pip install MySQL-Python(或者pip3 install mysqlclient如果使用 python 3)
If you did all those steps in the same order, and you still got an error, read on to the end, if, however, you did not follow these exact steps try, following them from the very beginning.
如果您按照相同的顺序执行了所有这些步骤,但仍然出现错误,请继续阅读,但是,如果您没有按照这些确切的步骤进行操作,请尝试从一开始就按照它们进行操作。
So, you followed the steps, and you're still geting an error, well, there are a few things you could try:
所以,您按照步骤操作,但仍然出现错误,好吧,您可以尝试以下几点:
Try running
which mysql_configfrom bash. It probably won't be found. That's why the build isn't finding it either. Try runninglocate mysql_configand see if anything comes back. The path to this binary needs to be either in your shell's $PATH environment variable, or it needs to be explicitly in the setup.py file for the module assuming it's looking in some specific place for that file.Instead of using MySQL-Python, try using 'mysql-connector-python', it can be installed using
pip install mysql-connector-python. More information on this can be found hereand here.Manually find the location of 'mysql/bin', 'mysql_config', and 'MySQL-Python', and add all these to the $PATH environment variable.
If all above steps fail, then you could try installing 'mysql' using MacPorts, in which case the file 'mysql_config' would actually be called 'mysql_config5', and in this case, you would have to do this after installing:
export PATH=$PATH:/opt/local/lib/mysql5/bin. You can find more details here.
尝试
which mysql_config从 bash运行。应该是找不到了。这就是为什么构建也没有找到它的原因。尝试运行locate mysql_config,看看是否有任何返回。这个二进制文件的路径要么在你的 shell 的 $PATH 环境变量中,要么在模块的 setup.py 文件中显式地存在,假设它在某个特定的地方寻找那个文件。不要使用 MySQL-Python,尝试使用 'mysql-connector-python',它可以使用
pip install mysql-connector-python. 可以在此处和此处找到有关这方面的更多信息。手动找到'mysql/bin'、'mysql_config'和'MySQL-Python'的位置,并将这些都添加到$PATH环境变量中。
如果以上所有步骤都失败,那么您可以尝试使用 MacPorts 安装 'mysql',在这种情况下,文件 'mysql_config' 实际上将被称为 'mysql_config5',在这种情况下,您必须在安装后执行此操作:
export PATH=$PATH:/opt/local/lib/mysql5/bin。您可以在此处找到更多详细信息。
Note1: I've seen some people saying that installing python-devand libmysqlclient-devalso helped, however I do not know if these packages are available on Mac OS.
注1:我看到有人说安装python-dev和安装libmysqlclient-dev也有帮助,但是我不知道这些软件包是否在 Mac OS 上可用。
Note2: Also, make sure to try running the commands as root.
注意 2:另外,请确保尝试以 root 身份运行命令。
I got my answers from (besides my brain) these places (maybe you could have a look at them, to see if it would help): 1, 2, 3, 4.
我从(除了我的大脑)这些地方得到了我的答案(也许你可以看看它们,看看它是否有帮助):1, 2, 3, 4。
I hoped I helped, and would be happy to know if any of this worked, or not. Good luck.
我希望我有所帮助,并且很高兴知道这是否有效。祝你好运。
回答by J.Mark
Install brew or apt-get is also not easy for me so I downloaded mysql via: https://dev.mysql.com/downloads/connector/python/, installed it. So I can find mysql_config int this directory: /usr/local/mysql/bin
安装 brew 或 apt-get 对我来说也不容易,所以我通过以下方式下载了 mysql:https: //dev.mysql.com/downloads/connector/python/ 并安装了它。所以我可以在这个目录中找到mysql_config:/usr/local/mysql/bin
the next step is:
下一步是:
- export PATH=$PATH:/usr/local/mysql/bin
- pip install MySQL-python==1.2.5
- 导出 PATH=$PATH:/usr/local/mysql/bin
- pip 安装 MySQL-python==1.2.5
回答by AndreL
Also this happens when I was installing mysqlclient,
当我安装 mysqlclient 时也会发生这种情况,
$ pip install mysqlclient
As user3429036 said,
正如用户 3429036 所说,
$ brew install mysql
回答by Trevor James Oluotch
I had been debugging this problem forever - 3 hours 17 mins. What particularly annoyed me was that I already had sql installed on my system through prior uni work but pip/pip3 wasn't recognising it. These threads above and many other I scoured the internet for were helpful in eluminating the problem but didn't actually solve things.
我一直在调试这个问题 - 3 小时 17 分钟。特别让我恼火的是,我已经通过之前的 uni 工作在我的系统上安装了 sql,但 pip/pip3 没有识别它。上面的这些线程以及我在互联网上搜索的许多其他线程有助于阐明问题,但实际上并没有解决问题。
ANSWER
回答
Pip is looking for mysql binaries in the Homebrew Directory which is located relative to Macintosh HD@
Pip 正在 Homebrew 目录中寻找 mysql 二进制文件,该目录相对于Macintosh HD@
/usr/local/Cellar/
so I found that this requires you making a few changes
所以我发现这需要你做一些改变
step 1: Download MySql if not already done so https://dev.mysql.com/downloads/
第 1 步:如果尚未下载 MySql,请下载https://dev.mysql.com/downloads/
Step 2: Locate it relative to Macintosh HDand cd
步骤 2:相对于Macintosh HD和 cd定位它
/usr/local/mysql/bin
Step 3: Once there open terminal and use a text editor of choice - I'm a neovim guy myself so I typed (doesn't automatically come with Mac... another story for another day)
第 3 步:一旦打开终端并使用选择的文本编辑器 - 我自己是一个 Neovim 人,所以我输入了(Mac 不会自动附带......改天再讲另一个故事)
nvim mysql_config
Step 4: You will see at approx line 112
第 4 步:您将在大约第 112 行看到
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
Change to
改成
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
*you'll notice that this file has read-only access so if your using vim or neovim
*您会注意到此文件具有只读访问权限,因此如果您使用 vim 或 neovim
:w !sudo tee %
Step 5: Head to the home directory and edit the .bash_profile file
第 5 步:前往主目录并编辑 .bash_profile 文件
cd ~
Then
然后
nvim .bash_profile
and add
并添加
export PATH="/usr/local/mysql/bin:$PATH"
to the file then save
到文件然后保存
Step 6: relative to Macintosh HDlocate paths and add to it
第 6 步:相对于Macintosh HD定位路径并添加到其中
cd /private/etc/
then
然后
nvim paths
and add
并添加
/usr/local/mysql/bin
*you'll again notice that this file has read-only access so if your using vim or neovim
*您会再次注意到此文件具有只读访问权限,因此如果您使用 vim 或 neovim
:w !sudo tee %
then
然后
cd ~
then refresh the terminal with your changes by running
然后通过运行使用您的更改刷新终端
source .bash_profile
Finally
最后
pip3 install mysqlclient
And Viola. Remember it's a vibe.
还有中提琴。记住这是一种氛围。
回答by Arun
If you don't want to install full mysql, we can fix this by just installing mysqlclient
brew install mysqlclient
Once cmd is completed it will ask to add below line to ~/.bash_profile:
如果您不想安装完整的 mysql,我们可以通过安装 mysqlclient 来解决此问题。
brew install mysqlclient
一旦 cmd 完成,它会要求将以下行添加到~/.bash_profile:
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
Close terminal and start new terminal and proceed with pip install mysqlclient
关闭终端并启动新终端并继续 pip install mysqlclient
回答by Zhanwen Chen
This answer is for MacOS users who did not install from brewbut rather from the official .dmg/.pkg. That installer fails to edit your PATH, causing things to break out of the box:
此答案适用于未brew从官方安装而是从官方安装的 MacOS 用户.dmg/.pkg。该安装程序无法编辑您的PATH,导致事情开箱即用:
- All MySQL commands like
mysql,mysqladmin,mysql_config, etc cannot be found, and as a result: - the "MySQL Preference Pane"fails to appear in System Preferences, and
- you cannot install any API that communicates with MySQL, including
mysqlclient
- 无法找到所有 MySQL 命令,如
mysql、mysqladmin、mysql_config等,因此: - 在“MySQL的预置面板”未出现在系统偏好设置,
- 您不能安装任何与 MySQL 通信的 API,包括
mysqlclient
What you have to do is appending the MySQL binfolder (typically /usr/local/mysql/binin your PATHby adding this line in your ~/.bash_profilefile:
您需要做的是附加 MySQLbin文件夹(通常/usr/local/mysql/bin在您PATH的~/.bash_profile文件中添加以下行:
export PATH="/usr/local/mysql/bin/:$PATH"
export PATH="/usr/local/mysql/bin/:$PATH"
You should then reload your ~/.bash_profilefor the change to take effect in your current Terminal session:
然后您应该重新加载您~/.bash_profile的更改以在您当前的终端会话中生效:
source ~/.bash_profile
source ~/.bash_profile
Before installing mysqlclient, however, you need to accept the XcodeBuild license:
mysqlclient但是,在安装之前,您需要接受 XcodeBuild 许可证:
sudo xcodebuild -license
sudo xcodebuild -license
Follow their directions to sign away your family, after which you should be able to install mysqlclientwithout issue:
按照他们的指示离开您的家人,之后您应该可以mysqlclient毫无问题地安装:
pip install mysqlclient
pip install mysqlclient
After installing that, you must do one more thing to fix a runtime bug that ships with MySQL (Dynamic Library libmysqlclient.dylibnot found), by adding this line to your system dynamic libraries path:
安装后,您必须再做一件事来修复 MySQL 附带的运行时错误(未找到动态库libmysqlclient.dylib),方法是将此行添加到您的系统动态库路径中:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/:$DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/:$DYLD_LIBRARY_PATH
回答by azmirfakkri
I am running Python 3.6 on MacOS Catalina. My issue was that I tried to install mysqlclient==1.4.2.post1and it keeps throwing mysql_config not found error.
我在 MacOS Catalina 上运行 Python 3.6。我的问题是我尝试安装mysqlclient==1.4.2.post1并且它不断抛出 mysql_config not found 错误。
This is the steps I took to solve the issue.
这是我为解决问题而采取的步骤。
- Install mysql-connector-c using brew (if you have mysql already install unlink first
brew unlink mysql) -brew install mysql-connector-c - Open mysql_config and edit the file around line 112
- 使用 brew 安装 mysql-connector-c(如果您已经安装了 mysql 取消链接
brew unlink mysql) -brew install mysql-connector-c - 打开 mysql_config 并编辑第 112 行附近的文件
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
brew info openssl- this will give you more information on what needs to be done about putting openssl in PATH- in relation to step 3, you need to do this to put openssl in PATH -
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile - for compilers to find openssl -
export LDFLAGS="-L/usr/local/opt/openssl/lib" - for compilers to find openssl -
export CPPFLAGS="-I/usr/local/opt/openssl/include"
brew info openssl- 这将为您提供有关将 openssl 放入 PATH 需要做什么的更多信息- 关于第 3 步,您需要这样做才能将 openssl 放在 PATH 中 -
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile - 让编译器找到 openssl -
export LDFLAGS="-L/usr/local/opt/openssl/lib" - 让编译器找到 openssl -
export CPPFLAGS="-I/usr/local/opt/openssl/include"
回答by mohammed_ayaz
If you have installed mysql using Homebrewby specifying a version then mysql_configwould be present here. - /usr/local/Cellar/[email protected]/5.6.47/bin
如果您通过指定版本使用Homebrew安装了 mysql ,则此处将显示mysql_config。- /usr/local/Cellar/[email protected]/5.6.47/bin
you can find the path of the sql bin by using ls command in /usr/local/directory
可以在/usr/local/目录下使用ls命令找到sql bin的路径
/usr/local/Cellar/[email protected]/5.6.47/bin
Add the path to bash profile like this.
像这样添加bash配置文件的路径。
nano ~/.bash_profile
export PATH="/usr/local/Cellar/[email protected]/5.6.47/bin:$PATH"

