如果这是一个简单的解决方案,请提前道歉,我已经找到了一个没有运气的答案。
我试图在亚马逊的Linux AMI上安装mysql-connector [-python]软件包。出于我的目的,我想使用Python 3.4。我已经用yum安装了Python 3.4和pip-3.4,并且已经成功安装了几个软件包:
pip-3.4 list
给出
numpy (1.11.1)
pip (6.1.1)
setuptools (25.1.4)
virtualenv (15.0.2)
然而,当我尝试:
sudo pip-3.4 install mysql-connector-python
我得到了
Collecting mysql-connector-python
Could not find a version that satisfies the requirement mysql-connector-python (from versions: )
No matching distribution found for mysql-connector-python
sudo pip-3.4 install mysql-connector-python --allow-external mysql-connector-python
给出了同样的错误。谷歌搜索建议我使用sudo pip-3.4 install mysql-connector-python-rf --allow-external mysql-connector-python-rf
,但这会产生错误:
Collecting mysql-connector-python-rf
Using cached mysql-connector-python-rf-2.1.3.tar.gz
Installing collected packages: mysql-connector-python-rf
Running setup.py install for mysql-connector-python-rf
Complete output from command /usr/bin/python3.4 -c "import setuptools, tokenize;__file__='/tmp/pip-build-hotls6f7/mysql-connector-python-rf/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-wzpbgx5g-record/install-record.txt --single-version-externally-managed --compile:
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: -c --help [cmd1 cmd2 ...]
or: -c --help-commands
or: -c cmd --help
error: option --single-version-externally-managed not recognized
----------------------------------------
Command "/usr/bin/python3.4 -c "import setuptools, tokenize;__file__='/tmp/pip-build-hotls6f7/mysql-connector-python-rf/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-wzpbgx5g-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-hotls6f7/mysql-connector-python-rf
我尝试了很多东西,例如
echo https://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.1.3.tar.gz >> requirements.txt
sudo -H pip-3.4 install -r ./requirements.txt
给出了类似的错误,
sudo pip-3.4 install https://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.1.3.tar.gz
会产生相同的error: option --single-version-externally-managed not recognized
错误。我还应该注意,pip建议我使用sudo pip-3.4 install --upgrade pip
进行升级,但是当我这样做时,pip会完全中断,即使pip-3.4 list
或pip-3.4 --version
也会给我pkg_resources.VersionConflict: (pip 8.1.2 (/usr/local/lib/python3.4/site-packages), Requirement.parse('pip==6.1.1'))
。
我对于该怎么做有点失落,我们将非常感谢任何帮助。
答案 0 :(得分:4)
在这里回答我自己的问题,我知道它并没有解决我直接遇到的问题,但我设法安装了mysql-connector,以便在Python3(.4)中,import mysql.connector
不会给出任何错误。这是我做的:
wget http://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.0.4.zip#md5=3df394d89300db95163f17c843ef49df
unzip mysql-connector-python-2.0.4.zip
cd mysql-connector-python-2.0.4
sudo python3 setup.py install
现在,在Python3中:
>>>import mysql.connector
>>>
我仍然很好奇为什么我之前收到错误error: option --single-version-externally-managed not recognized
。我猜这是setuptools
的问题,但我已将其升级到最新版本(以及virtualenv
)。