我尝试输入pip install mysql-python时如何立即解决此错误

时间:2019-03-27 19:56:16

标签: python mysql homebrew

我一直试图在Mac上安装python-MySQLdb,但我一直收到错误消息。我尝试了很多替代方法来传递该错误。

sudo PATH=/usr/local/Cellar/mysql/bin/:$PATH pip install mysql-python
Password:
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
The directory '/Users/zuhairhallak/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/zuhairhallak/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting mysql-python
  Downloading https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)
    100% |████████████████████████████████| 112kB 2.6MB/s 
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/tmp/pip-install-RtF2js/mysql-python/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 53, in get_config
        libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
      File "setup_posix.py", line 8, in dequote
        if s[0] in "\"'" and s[0] == s[-1]:
    IndexError: string index out of range

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-install-RtF2js/mysql-python/

我也运行了sudo -H pip install mysql-python,并且出现了不同的错误

生成13条警告。   cc -bundle-未定义dynamic_lookup -Wl,-F。 build / temp.macosx-10.14-intel-2.7 / _mysql.o -L / usr / local / Cellar / mysql / 8.0.15 / lib -lmysqlclient -lssl -lcrypto -o build / lib.macosx-10.14-intel-2.7 /_mysql.so   ld:找不到-lssl的库   clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)   错误:命令“ cc”失败,退出状态为1


mysql-python的构建轮失败   为MySQL-python运行setup.py clean 无法建立mysql-python 安装收集的软件包:mysql-python   运行setup.py install for mysql-python ...错误     从命令/ usr / bin / python -u -c“ import setuptools,tokenize; file ='/ private / tmp / pip-install-3A8kOd / mysql-python / setup.py';的完整输出f = getattr(标记,'打开',打开)(文件);代码= f.read()。replace('\ r \ n','\ n'); f.close( ); exec(compile(code, file ,'exec'))“安装--record /private/tmp/pip-record-TUb4up/install-record.txt-单个版本-外部管理的--compile

2 个答案:

答案 0 :(得分:0)

请尝试

brew install mysql
sudo -H pip install mysql-python

答案 1 :(得分:0)

我转到mysql_config文件并将其打开

vi mysql_config

这是正确的。

Create options:
Libs = "- L $ pkglibdir"
Libs = "$ libs -lmysqlclient -lssl -lcrypto"

在终端中运行此命令 1.导出LDFLAGS =“-L / usr / local / opt / openssl / lib” 2.导出CPPFLAGS =“-I / usr / local / opt / openssl / include” 3. pip安装mysql-python