【原创】MacOS 安装 pymssql 报错

相关环境

MacOS 10.15.6
Python 3.7.6
pip3 20.2.2

问题描述

使用 pip 安装  pymssql 时报错如下:

Looking in indexes: https://pypi.douban.com/simple
Collecting pymssql
  Downloading https://pypi.doubanio.com/packages/2e/81/99562b93d75f3fc5956fa65decfb35b38a4ee97cf93c1d0d3cb799fffb99/pymssql-2.1.4.tar.gz (691 kB)
     |████████████████████████████████| 691 kB 3.6 MB/s 
    ERROR: Command errored out with exit status 1:
     command: /Users/jiangzhuolin/PycharmProjects/MDM_Project_Scripts/venv/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/yg/txmcr9zn44v60jryrcvv1yq80000gn/T/pip-install-ges15ule/pymssql/setup.py'"'"'; __file__='"'"'/private/var/folders/yg/txmcr9zn44v60jryrcvv1yq80000gn/T/pip-install-ges15ule/pymssql/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/yg/txmcr9zn44v60jryrcvv1yq80000gn/T/pip-pip-egg-info-5x0k9d7j
         cwd: /private/var/folders/yg/txmcr9zn44v60jryrcvv1yq80000gn/T/pip-install-ges15ule/pymssql/
    Complete output (7 lines):
    /Users/jiangzhuolin/PycharmProjects/MDM_Project_Scripts/venv/lib/python3.7/site-packages/setuptools/dist.py:44: DistDeprecationWarning: Do not call this function
      warnings.warn("Do not call this function", DistDeprecationWarning)
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/yg/txmcr9zn44v60jryrcvv1yq80000gn/T/pip-install-ges15ule/pymssql/setup.py", line 88, in <module>
        from Cython.Distutils import build_ext as _build_ext
    ModuleNotFoundError: No module named 'Cython'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

问题原因

这是因为 pymssql 依赖于 Cython 实现,因此,如果未安装 Cython 则会报此错误。

解决方法

1、升级 pip

(venv) ➜  MDM_Project_Scripts git:(retrigger_mq) ✗ python3 -m pip install --upgrade pip 
Collecting pip
  Using cached pip-20.2.2-py2.py3-none-any.whl (1.5 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.1.1
    Uninstalling pip-20.1.1:
      Successfully uninstalled pip-20.1.1
Successfully installed pip-20.2.2

2、安装 cython

(venv) ➜  MDM_Project_Scripts git:(retrigger_mq) ✗ python3 -m pip install cython -i https://pypi.douban.com/simple
Looking in indexes: https://pypi.douban.com/simple
Collecting cython
  Downloading https://pypi.doubanio.com/packages/2b/4d/899fb0967be8b02bdbc47f892b48f576f9c2d28f7d49710bcecf9ed1c705/Cython-0.29.21-cp37-cp37m-macosx_10_9_x86_64.whl (1.9 MB)
     |████████████████████████████████| 1.9 MB 1.2 MB/s 
Installing collected packages: cython
Successfully installed cython-0.29.21

3、安装 pymssql

(venv) ➜  MDM_Project_Scripts git:(retrigger_mq) ✗ pip3 install pymssql -i https://pypi.douban.com/simple
Looking in indexes: https://pypi.douban.com/simple
Collecting pymssql
  Downloading https://pypi.doubanio.com/packages/2e/81/99562b93d75f3fc5956fa65decfb35b38a4ee97cf93c1d0d3cb799fffb99/pymssql-2.1.4.tar.gz (691 kB)
     |████████████████████████████████| 691 kB 3.1 MB/s
Using legacy 'setup.py install' for pymssql, since package 'wheel' is not installed.
Installing collected packages: pymssql
    Running setup.py install for pymssql ... done
Successfully installed pymssql-2.1.4

问题解决

附录

参考

https://stackoverflow.com/questions/54390275/modulenotfounderror-no-module-named-cython
https://stackoverflow.com/questions/60043297/modulenotfounderror-no-module-named-cython-during-pycocotools-install-after-c

You may also like...

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注