我无法使用 pip 安装 mysql-connector-python

I cannot install mysql-connector-python using pip

我正在尝试安装 mysql-connector-python==1.0.12 作为我的项目自动安装的一部分,但我从 pip install 收到以下错误:

Collecting mysql-connector-python==1.0.12 (from -r /tmp/requirements.txt (line 20))
Could not find a version that satisfies the requirement mysql-connector-python==1.0.12 (from -r /tmp/requirements.txt (line 20)) (from versions: )
No matching distribution found for mysql-connector-python==1.0.12 (from -r /tmp/requirements.txt (line 20))

直到几天前它还运行良好。我调查了一下,发现了以下 issue in bitbucket.org。具体来说,以下日期为 28/12/2015 的评论:

That should be blank, per PEP 470 using PyPI to link to a package not hosted by PyPI for automated installers to download (the /simple/ index) was deprecated and scheduled for removal. Maintainers of the affected packages were emailed 3 months ago. The removal happened earlier today (a bug caused some oackages like Twisted which were hosted on PyPI to also have their links removed but that has been remedied). The maintainers of MySQL-connector-python should either upload to PyPI or direct their users to use either -f or --extra-index-url with a repository they maintain.

如何才能顺利安装mysql-connector-python==1.0.12运行? 我需要建立自己的存储库吗?

有很多解决方案,例如托管私有存储库,但最快的方法是将 requirements.txt 文件更改为从 mysql 的 cdn 下载。

即,更改:

mysql-connector-python==1.0.12

https://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.1.15.tar.gz

对于所有像我这样不得不google需求文件如何工作的懒人

就这样做...

echo https://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.1.3.tar.gz >> requirements.txt

然后这个。

sudo -H pip install -r ./requirements.txt

检查一下。

pip list | grep mysql

它应该输出:

mysql-connector-python (2.1.3)

快乐的日子感谢@Amnon

如果您使用的是 setup.py 脚本,请保留 install_requies 中列出的依赖项,但将属性 depedency_links 添加到带有列表的设置函数中,并将 url 到包里面。如:

setup(
    dependency_links=['http://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.1.4.zip']
)

Packages Not On PyPI 文档中指定了更多内容。

以上 link 对我不起作用,或者在尝试安装到 AWS Beanstalk 时不起作用。但是下面的 link 确实有效:

https://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.0.4.zip#md5=3df394d89300db95163f17c843ef49df

为我工作使用

pip install mysql-connector-python-rf

这里有更多信息https://github.com/travis-ci/travis-ci/issues/5369

红帽/美分OS

sudo yum install python-devel mysql-devel
sudo pip3 install mysql-connector

对于其他 OS,参见 mysqlclient

对于requirements.txt mysql-connector-python~=8.0.5