使用「;pip安装mysql python“;但它没有';不行,怎么修

使用「;pip安装mysql python“;但它没有';不行,怎么修,python,mysql,Python,Mysql,我是Python新手,我想安装mysqldb模块连接到我的数据库,我已经尝试了“pip安装mysql Python”,终端显示: sudo pip install mysql-python The directory '/Users/suoliyun/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please ch

我是Python新手,我想安装mysqldb模块连接到我的数据库,我已经尝试了“pip安装mysql Python”,终端显示:

sudo pip install mysql-python
The directory '/Users/suoliyun/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/suoliyun/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 MySQL-python-1.2.5.zip (108kB)
    100% |████████████████████████████████| 112kB 1.9MB/s 
Installing collected packages: mysql-python
  Running setup.py install for mysql-python ... error
    Complete output from command /Users/suoliyun/Library/Enthought/Canopy/edm/envs/User/Resources/Python.app/Contents/MacOS/Python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-DCyMvD/mysql-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-1dVZC1-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.6-x86_64-2.7
    copying _mysql_exceptions.py -> build/lib.macosx-10.6-x86_64-2.7
    creating build/lib.macosx-10.6-x86_64-2.7/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.6-x86_64-2.7/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.6-x86_64-2.7/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.6-x86_64-2.7/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.6-x86_64-2.7/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.6-x86_64-2.7/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.6-x86_64-2.7/MySQLdb
    creating build/lib.macosx-10.6-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.6-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.6-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.6-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.6-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.6-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.6-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.6-x86_64-2.7/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.macosx-10.6-x86_64-2.7
    gcc -fno-strict-aliasing -fno-common -dynamic -g -arch x86_64 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql/5.7.18_1/include/mysql -I/Users/suoliyun/Library/Enthought/Canopy/edm/envs/User/include/python2.7 -c _mysql.c -o build/temp.macosx-10.6-x86_64-2.7/_mysql.o
    _mysql.c:1589:10: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
            if (how < 0 || how >= sizeof(row_converters)) {
                ~~~ ^ ~
    1 warning generated.
    gcc -bundle -undefined dynamic_lookup -g -arch x86_64 -headerpad_max_install_names -arch x86_64 build/temp.macosx-10.6-x86_64-2.7/_mysql.o -L/usr/local/Cellar/mysql/5.7.18_1/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.6-x86_64-2.7/_mysql.so
    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

    ----------------------------------------
Command "/Users/*/Library/Enthought/Canopy/edm/envs/User/Resources/Python.app/Contents/MacOS/Python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-DCyMvD/mysql-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-1dVZC1-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-build-DCyMvD/mysql-python/
sudopip安装mysql-python
目录“/Users/suoliyun/Library/Caches/pip/http”或其父目录不属于当前用户,缓存已被禁用。请检查该目录的权限和所有者。如果使用sudo执行pip,您可能需要sudo的-H标志。
当前用户不拥有目录“/Users/suoliyun/Library/Caches/pip”或其父目录,并且已禁用缓存控制盘。检查该目录的权限和所有者。如果使用sudo执行pip,您可能需要sudo的-H标志。
收集mysql-python
下载MySQL-python-1.2.5.zip(108kB)
100% |████████████████████████████████| 112kB 1.9MB/s
安装收集的软件包:mysql-python
正在运行针对mysql python的setup.py安装。。。错误
从command/Users/suoliyun/Library/enthund/Canopy/edm/envs/User/Resources/Python.app/Contents/MacOS/Python-u-c“导入设置工具,标记化;uu文件uuu=”/private/tmp/pip build DCyMvD/mysql Python/setup.py';f=getattr(标记化,'open',打开)(u文件);code=f.read().替换('\r\n','f.close());exec(编译(代码,_文件_,‘exec’)“安装--record/tmp/pip-1dVZC1-record/install-record.txt--外部管理的单一版本--编译:
正在运行的安装
运行构建
运行build\u py
创建构建
创建build/lib.macosx-10.6-x86_64-2.7
正在复制_mysql_exceptions.py->build/lib.macosx-10.6-x86_64-2.7
创建build/lib.macosx-10.6-x86_64-2.7/MySQLdb
正在复制MySQLdb/uuu init_uuuu.py->build/lib.macosx-10.6-x86_64-2.7/MySQLdb
正在复制MySQLdb/converters.py->build/lib.macosx-10.6-x86_64-2.7/MySQLdb
正在复制MySQLdb/connections.py->build/lib.macosx-10.6-x86_64-2.7/MySQLdb
正在复制MySQLdb/cursors.py->build/lib.macosx-10.6-x86_64-2.7/MySQLdb
正在复制MySQLdb/release.py->build/lib.macosx-10.6-x86_64-2.7/MySQLdb
正在复制MySQLdb/times.py->build/lib.macosx-10.6-x86_64-2.7/MySQLdb
创建build/lib.macosx-10.6-x86_64-2.7/MySQLdb/constants
正在复制MySQLdb/constants/_init__.py->build/lib.macosx-10.6-x86_64-2.7/MySQLdb/constants
正在复制MySQLdb/constants/CR.py->build/lib.macosx-10.6-x86_64-2.7/MySQLdb/constants
正在复制MySQLdb/constants/FIELD_TYPE.py->build/lib.macosx-10.6-x86_64-2.7/MySQLdb/constants
正在复制MySQLdb/constants/ER.py->build/lib.macosx-10.6-x86_64-2.7/MySQLdb/constants
正在复制MySQLdb/constants/FLAG.py->build/lib.macosx-10.6-x86_64-2.7/MySQLdb/constants
正在复制MySQLdb/constants/REFRESH.py->build/lib.macosx-10.6-x86_64-2.7/MySQLdb/constants
正在复制MySQLdb/constants/CLIENT.py->build/lib.macosx-10.6-x86_64-2.7/MySQLdb/constants
运行build_ext
正在生成“\u mysql”扩展
创建构建/临时macosx-10.6-x86_64-2.7
gcc-fno严格别名-fno common-dynamic-g-arch x86_64-DNDEBUG-g-fwrapv-O3-Wall-Wstrict原型-Dversion_info=(1,2,5,'final',1)-D_version_uu=1.2.5-I/usr/local/ceral/mysql/5.7.18_1/include/mysql-I/Users/suoliyun/Library/enthund/cord/edm/envs/User/include/python2.7-c-o build/temp.macosx-10.64_x86.0
_mysql.c:1589:10:警告:未签名表达式<0的比较始终为false[-wtautologic compare]
if(how<0 | | how>=sizeof(row|u转换器)){
~~~ ^ ~
生成1个警告。
gcc-bundle-undefined dynamic_lookup-g-arch x86_64-headerpad_max_install_names-arch x86_64 build/temp.macosx-10.6-x86_64-2.7/_mysql.o-L/usr/local/ceral/mysql/5.7.18_1/lib-lmysqlcl-lcrypto-build/lib/lib.macosx-10.6-x86_64-2.7//mysql.so
ld:找不到-lssl的库
叮当声:错误:链接器命令失败,退出代码为1(使用-v查看调用)
错误:命令“gcc”失败,退出状态为1
----------------------------------------
命令“/Users/*/Library/enthund/Canopy/edm/envs/User/Resources/Python.app/Contents/MacOS/Python-u-c”导入setuptools,tokenize;_u-file_uuu='/private/tmp/pip-build-DCyMvD/mysql-Python/setup.py';f=getattr(tokenize,'open',',open)(u-file_u);code=f.read().replace('\r\n','n');f.close();exec(compile,u-file);'exec)“安装--record/tmp/pip-1dVZC1-record/install-record.txt--外部管理的单一版本--编译”在/private/tmp/pip build DCyMvD/mysql python中失败,错误代码为1/
怎么解决?这是什么意思?
谢谢!

无论何时安装任何依赖于项目的python库,请始终在各自的虚拟环境中安装这些库

1. pip install virtualenv
这将安装virtualenv,现在创建一个名为miscellaneous的虚拟环境 这将在工作目录中创建名为miscellaneous的虚拟环境 这将启动虚拟环境,现在您要安装的任何库都将安装在此环境中
您是否安装了OpenSSL?因为它抱怨
ld:library-not found for-lssl
存在
gcc
的依赖性问题。请使用安装
gcc
解决问题。如果您是linux,您可以像
sudo-apt-get-install-gcc
一样安装。类似问题:从日志中,它是OSX。请确保安装了xcode。xcode将在暂停所需的包,如gcc等。
2. virtualenv miscellaneous
3. source miscellaneous/bin/activate
4. pip install MySQL-python