python - 强制setuptools使用dependency_links来安装mysqlclient

标签 python setuptools

我使用的是 Windows,我需要安装 here 中的 WHL 文件。这是我在 setup.py 中的内容:

install_requires=['mysqlclient==1.3.7',
...
dependency_links=['https://pypi.python.org/packages/cp27/m/mysqlclient/mysqlclient-1.3.7-cp27-none-win32.whl#md5=e9e726fd6f1912af78e2bf6ab56c02f3',]

但是,setuptools 正在下载 tar.gz 文件并尝试构建,这在我的系统上不起作用。我关注了this solution并改变了我的install_requires使用mysqlclient<=1.3.7 ,但我仍然遇到同样的问题。这是输出:

Searching for mysqlclient<=1.3.7
Reading https://pypi.python.org/packages/cp27/P/Pillow/Pillow-2.7.0-cp27-none-win32.whl#md5=ebc4ef88a8dd39ed484206323a8d557a
Reading https://pypi.python.org/packages/cp27/m/mysqlclient/mysqlclient-1.3.7-cp27-none-win32.whl#md5=e9e726fd6f1912af78e2bf6ab56c02f3
Reading http://pypi.python.org/simple/mysqlclient/
Best match: mysqlclient 1.3.7
Downloading https://pypi.python.org/packages/source/m/mysqlclient/mysqlclient-1.3.7.tar.gz#md5=2ec5a96cbd9fd6ef343fa9b581a67fc4
Processing mysqlclient-1.3.7.tar.gz
Running mysqlclient-1.3.7\setup.py -q bdist_egg --dist-dir c:\users\uuu\appdata\local\temp\easy_install-wt7fkw\mysqlclient-1.3.7\egg-dist-tmp-ubrs4f
error: Setup script exited with error: Unable to find vcvarsall.bat

使用 dependency_links 中的链接安装 Pillow 没有任何问题。有没有办法强制 setup.py 使用依赖链接?

最佳答案

我最终手动安装了该软件包作为安装后的一部分:

from setuptools.command.install import install as _install
import pip

class install(_install):
  def run(self):
    _install.do_egg_install(self)

    # Even when dependeny link to mysqlclient is specified, setuptools still installs
    # from pypi, which does not work on Windows.  Therefore, manually install mysqlclient
    if os.name == 'nt':
      pip.main(['install', 'https://pypi.python.org/packages/cp27/m/mysqlclient/mysqlclient-1.3.7-cp27-none-win32.whl#md5=e9e726fd6f1912af78e2bf6ab56c02f3'])
    else:
      pip.main(['install', 'mysqlclient==1.3.7'])

setup(
      cmdclass={'install': install},
...
)

other answers调用 _install.run(),但这对我不起作用。我必须使用do_egg_install()

关于python - 强制setuptools使用dependency_links来安装mysqlclient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36755969/

相关文章:

python - entry_points 不使用 pip 创建自定义脚本,仅使用 Python 中的 easy_install

python - 安装工具警告 : Failed to find the configured license file 'L'

python - 如何为版本 2 和版本 3 设置不同的 PYTHONPATH?

python - 在 Windows 上导入 mpl_toolkits.basemap?

python - 未安装 PyQt5 模块 "QtQuick"

python - 如何让 setuptools 安装不在 PyPI 上的包?

python - 机器人已启动,但/start 命令没有执行任何操作

python - 创建三个类而不是两个 - keras 库

pip 安装包不是来自 pypi,其名称与 pypi 中的名称相同(+ 具有来自 pypi 的依赖项)

Python打包: catering to different audiences