【发布时间】:2014-03-04 15:34:32
【问题描述】:
RedHat 是我的操作系统。默认情况下,它运行python2.6。但是,我需要安装python2.7。我在this post 之后安装了它。现在,当我跑步时:
$ python -V
Python 2.7.5
然而
$ sudo python -V
Python 2.6.6
所以,我在安装库时遇到了问题。
我尝试通过以下方式安装mysql-connector:
pip install mysql-connector-python- 关注installation guide for source distribution
- 关注installation guide for binary distribution
但是,python 2.7 版本上没有安装 mysql-connector 模块。如果我跑:
$ python
>>> import mysql.connector
ImportError: No module named mysql.connector
如何在 python 2.7 版上安装 mysql 模块?
编辑
附加信息:
$ which pip
/usr/bin/pip
$ sudo which pip
/usr/bin/pip
$ which easy_install
/opt/rh/python27/root/usr/bin/easy_install
$ sudo which easy_install
/usr/bin/easy_install
/usr/bin/ $ ls -al pip
-rwxr-xr-x. 1 root root 281 Feb 7 11:07 pip
/opt/rh/python27/root/usr/bin $ ls -al easy_install
-rwxr-xr-x. 1 root root 344 Aug 16 11:40 easy_install
【问题讨论】:
-
类似于 this answer。
-
可以在python 2.6中导入mysql.connector吗?也许问题不在于多个 python 版本,而在于您尝试导入的方式?
标签: python python-2.7 pip mysql-python mysql-connector