首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用“pip install mysql-python”,但是它不工作,如何修复它?

问使用“pip install mysql-python”,但是它不工作,如何修复它?
EN

Stack Overflow用户
提问于 2017-06-27 15:13:50
回答 1查看 908关注 0票数 0

我是Python新手,我想安装mysqldb模块来连接我的数据库,我已经尝试了"pip install mysql-python",终端显示:

代码语言:javascript
复制
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/

如何解决这个问题?这是什么意思?谢谢!

EN

回答 1

Stack Overflow用户

发布于 2017-06-27 16:53:09

当您安装任何依赖于项目的python库时,请始终在相应的虚拟环境中安装这些库。

代码语言:javascript
复制
1. pip install virtualenv

这将安装virtualenv,现在创建一个名为install的虚拟环境

代码语言:javascript
复制
2. virtualenv miscellaneous

这将在工作目录中创建一个名为directory的虚拟环境

代码语言:javascript
复制
3. source miscellaneous/bin/activate

这将启动虚拟环境,现在您要安装的任何库都将安装在此环境中

代码语言:javascript
复制
4. pip install MySQL-python
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44774292

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档