欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

安装 pymssql 2.2.8 报错 有大用 有大大用 有大大大用

python3.12 安装 pymssql 2.2.8 会报错,,,降低 Python 版本
使用 Python 3.10 或 3.11 创建虚拟环境,然后 强制安装 
pymssql==2.2.8

1)  py -3.11 -m venv .venv311 #这一行命令是在cmd或powershell窗口中执行的python命令
 
.\.venv310\Scripts\activate #这一行命令也是在cmd或powershell窗口中执行的python命令
# 上两行是可行的,OK的,但是命令行实在不方便
#
所以我没有 通过 上两行的命令创建和激活python3.11的环境,
# 我是 通过 pycharm 创建 3.11 的虚拟环境,见 /node-admin/23200
2) pip install pymssql==2.2.8   # 强制安装 pymssql 2.2.8




下面的可以不看了,即使看,也是为了了解原理罢了

(.venv) PS C:\Users\shipingzhong\PycharmProjects\pythonProject> pip3 install pymssql==2.2.8

(.venv) PS C:\Users\shipingzhong\PycharmProjects\pythonProject> pip3 install pymssql==2.2.8                                           

Collecting pymssql==2.2.8

  Downloading pymssql-2.2.8.tar.gz (171 kB)

  Installing build dependencies ... done

  Getting requirements to build wheel ... done

  Preparing metadata (pyproject.toml) ... done

Building wheels for collected packages: pymssql

  Building wheel for pymssql (pyproject.toml) ... error

  error: subprocess-exited-with-error


  × Building wheel for pymssql (pyproject.toml) did not run successfully.

  │ exit code: 1

  ╰─> [127 lines of output]

      <string>:32: SetuptoolsDeprecationWarning: The test command is disabled and references to it are deprecated.

      !!


              ********************************************************************************

              Please remove any references to `setuptools.command.test` in all supported versions of the affected package.


              This deprecation is overdue, please update your project and remove deprecated

              calls to avoid build errors in the future.

              ********************************************************************************


      !!

      C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\_distutils\dist.py:289: UserWarning: Unknown distribution option: 'tests_require'

        warnings.warn(msg)

      C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\dist.py:759: SetuptoolsDeprecationWarning: License classifiers are deprecated.

      !!


              ********************************************************************************

              Please consider removing the following classifiers in favor of a SPDX license expression:


              License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)


              See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details.

              ********************************************************************************


      !!

        self._finalize_license_expression()

      setup.py: platform.system() => Windows

      setup.py: platform.architecture() => ('64bit', 'WindowsPE')

      setup.py: include_dirs => []

      setup.py: library_dirs => []

      running bdist_wheel

      running build

      running build_py

      creating build\lib.win-amd64-cpython-312\pymssql

      copying src\pymssql\__init__.py -> build\lib.win-amd64-cpython-312\pymssql

      running build_ext

      warning: src\pymssql\_mssql.pyx:82:0: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310

      warning: src\pymssql\_mssql.pyx:264:4: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310

      warning: src\pymssql\_mssql.pyx:333:4: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310

      warning: src\pymssql\_mssql.pyx:831:8: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310

      warning: src\pymssql\_mssql.pyx:919:8: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310

      warning: src\pymssql\_mssql.pyx:1005:12: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310

      warning: src\pymssql\_mssql.pyx:1379:16: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310

      warning: src\pymssql\_mssql.pyx:1713:8: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310


      Error compiling Cython file:

      ------------------------------------------------------------

      ...


              elif dbtype == SQLINT4:

                  return int(<int>(<DBINT *>data)[0])


              elif dbtype == SQLINT8:

                  return long(<PY_LONG_LONG>(<PY_LONG_LONG *>data)[0])

                         ^

      ------------------------------------------------------------


      src\pymssql\_mssql.pyx:847:19: undeclared name not builtin: long

      Compiling src\pymssql\_mssql.pyx because it changed.

      [1/1] Cythonizing src\pymssql\_mssql.pyx

      Traceback (most recent call last):

        File "C:\Users\shipingzhong\PycharmProjects\pythonProject\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>

          main()

        File "C:\Users\shipingzhong\PycharmProjects\pythonProject\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main

          json_out['return_val'] = hook(**hook_input['kwargs'])

                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        File "C:\Users\shipingzhong\PycharmProjects\pythonProject\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 251, in build_wheel

          return _build_backend().build_wheel(wheel_directory, config_settings,

                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\build_meta.py", line 435, in build_wheel

          return _build(['bdist_wheel', '--dist-info-dir', str(metadata_directory)])

                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\build_meta.py", line 423, in _build

          return self._build_with_temp_dir(

                 ^^^^^^^^^^^^^^^^^^^^^^^^^^

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\build_meta.py", line 404, in _build_with_temp_dir

          self.run_setup()

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\build_meta.py", line 512, in run_setup

          super().run_setup(setup_script=setup_script)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\build_meta.py", line 317, in run_setup

          exec(code, locals())

        File "<string>", line 289, in <module>

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\__init__.py", line 115, in setup

          return distutils.core.setup(**attrs)

                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 186, in setup

          return run_commands(dist)

                 ^^^^^^^^^^^^^^^^^^

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 202, in run_commands

          dist.run_commands()

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 1002, in run_commands

          self.run_command(cmd)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\dist.py", line 1102, in run_command

          super().run_command(command)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 1021, in run_command

          cmd_obj.run()

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\command\bdist_wheel.py", line 370, in run

          self.run_command("build")

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 357, in run_command

          self.distribution.run_command(command)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\dist.py", line 1102, in run_command

          super().run_command(command)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 1021, in run_command

          cmd_obj.run()

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\_distutils\command\build.py", line 135, in run

          self.run_command(cmd_name)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 357, in run_command

          self.distribution.run_command(command)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\dist.py", line 1102, in run_command

          super().run_command(command)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 1021, in run_command

          cmd_obj.run()

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\_distutils\command\build_ext.py", line 368, in run

          self.build_extensions()

        File "<string>", line 181, in build_extensions

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\_distutils\command\build_ext.py", line 484, in build_extensions

          self._build_extensions_serial()

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\setuptools\_distutils\command\build_ext.py", line 510, in _build_extensions_serial

          self.build_extension(ext)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\Cython\Distutils\build_ext.py", line 131, in build_extension

          new_ext = cythonize(

                    ^^^^^^^^^^

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\Cython\Build\Dependencies.py", line 1159, in cythonize

          cythonize_one(*args)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-rz0y_hsq\overlay\Lib\site-packages\Cython\Build\Dependencies.py", line 1303, in cythonize_one

          raise CompileError(None, pyx_file)

      Cython.Compiler.Errors.CompileError: src\pymssql\_mssql.pyx

      [end of output]


  note: This error originates from a subprocess, and is likely not a problem with pip.

  ERROR: Failed building wheel for pymssql

Failed to build pymssql


[notice] A new release of pip is available: 24.3.1 -> 25.2

[notice] To update, run: python.exe -m pip install --upgrade pip

ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (pymssql)

(.venv) PS C:\Users\shipingzhong\PycharmProjects\pythonProject>  python.exe -m pip install --upgrade pip

Requirement already satisfied: pip in c:\users\shipingzhong\pycharmprojects\pythonproject\.venv\lib\site-packages (24.3.1)

Collecting pip

  Downloading pip-25.2-py3-none-any.whl.metadata (4.7 kB)

Downloading pip-25.2-py3-none-any.whl (1.8 MB)

   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 4.1 MB/s eta 0:00:00

Installing collected packages: pip

  Attempting uninstall: pip

    Found existing installation: pip 24.3.1

    Uninstalling pip-24.3.1:

      Successfully uninstalled pip-24.3.1

Successfully installed pip-25.2

(.venv) PS C:\Users\shipingzhong\PycharmProjects\pythonProject> pip3 install pymssql==2.2.8             

Collecting pymssql==2.2.8

  Using cached pymssql-2.2.8.tar.gz (171 kB)

  Installing build dependencies ... done

  Getting requirements to build wheel ... done

  Preparing metadata (pyproject.toml) ... done

Building wheels for collected packages: pymssql

  Building wheel for pymssql (pyproject.toml) ... error

  error: subprocess-exited-with-error


  × Building wheel for pymssql (pyproject.toml) did not run successfully.

  │ exit code: 1

  ╰─> [127 lines of output]

      <string>:32: SetuptoolsDeprecationWarning: The test command is disabled and references to it are deprecated.

      !!


              ********************************************************************************

              Please remove any references to `setuptools.command.test` in all supported versions of the affected package.


              This deprecation is overdue, please update your project and remove deprecated

              calls to avoid build errors in the future.

              ********************************************************************************


      !!

      C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\_distutils\dist.py:289: UserWarning: Unknown distribution option: 'tests_require'

        warnings.warn(msg)

      C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\dist.py:759: SetuptoolsDeprecationWarning: License classifiers are deprecated.

      !!


              ********************************************************************************

              Please consider removing the following classifiers in favor of a SPDX license expression:


              License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)


              See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details.

              ********************************************************************************


      !!

        self._finalize_license_expression()

      setup.py: platform.system() => Windows

      setup.py: platform.architecture() => ('64bit', 'WindowsPE')

      setup.py: include_dirs => []

      setup.py: library_dirs => []

      running bdist_wheel

      running build

      running build_py

      creating build\lib.win-amd64-cpython-312\pymssql

      copying src\pymssql\__init__.py -> build\lib.win-amd64-cpython-312\pymssql

      running build_ext

      warning: src\pymssql\_mssql.pyx:82:0: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310

      warning: src\pymssql\_mssql.pyx:264:4: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310

      warning: src\pymssql\_mssql.pyx:333:4: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310

      warning: src\pymssql\_mssql.pyx:831:8: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310

      warning: src\pymssql\_mssql.pyx:919:8: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310

      warning: src\pymssql\_mssql.pyx:1005:12: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310

      warning: src\pymssql\_mssql.pyx:1379:16: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310

      warning: src\pymssql\_mssql.pyx:1713:8: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310


      Error compiling Cython file:

      ------------------------------------------------------------

      ...


              elif dbtype == SQLINT4:

                  return int(<int>(<DBINT *>data)[0])


              elif dbtype == SQLINT8:

                  return long(<PY_LONG_LONG>(<PY_LONG_LONG *>data)[0])

                         ^

      ------------------------------------------------------------


      src\pymssql\_mssql.pyx:847:19: undeclared name not builtin: long

      Compiling src\pymssql\_mssql.pyx because it changed.

      [1/1] Cythonizing src\pymssql\_mssql.pyx

      Traceback (most recent call last):

        File "C:\Users\shipingzhong\PycharmProjects\pythonProject\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 389, in <module>

          main()

        File "C:\Users\shipingzhong\PycharmProjects\pythonProject\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 373, in main

          json_out["return_val"] = hook(**hook_input["kwargs"])

                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        File "C:\Users\shipingzhong\PycharmProjects\pythonProject\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 280, in build_wheel

          return _build_backend().build_wheel(

                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\build_meta.py", line 435, in build_wheel

          return _build(['bdist_wheel', '--dist-info-dir', str(metadata_directory)])

                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\build_meta.py", line 423, in _build

          return self._build_with_temp_dir(

                 ^^^^^^^^^^^^^^^^^^^^^^^^^^

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\build_meta.py", line 404, in _build_with_temp_dir

          self.run_setup()

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\build_meta.py", line 512, in run_setup

          super().run_setup(setup_script=setup_script)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\build_meta.py", line 317, in run_setup

          exec(code, locals())

        File "<string>", line 289, in <module>

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\__init__.py", line 115, in setup

          return distutils.core.setup(**attrs)

                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 186, in setup

          return run_commands(dist)

                 ^^^^^^^^^^^^^^^^^^

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 202, in run_commands

          dist.run_commands()

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 1002, in run_commands

          self.run_command(cmd)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\dist.py", line 1102, in run_command

          super().run_command(command)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 1021, in run_command

          cmd_obj.run()

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\command\bdist_wheel.py", line 370, in run

          self.run_command("build")

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 357, in run_command

          self.distribution.run_command(command)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\dist.py", line 1102, in run_command

          super().run_command(command)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 1021, in run_command

          cmd_obj.run()

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\_distutils\command\build.py", line 135, in run

          self.run_command(cmd_name)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 357, in run_command

          self.distribution.run_command(command)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\dist.py", line 1102, in run_command

          super().run_command(command)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 1021, in run_command

          cmd_obj.run()

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\_distutils\command\build_ext.py", line 368, in run

          self.build_extensions()

        File "<string>", line 181, in build_extensions

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\_distutils\command\build_ext.py", line 484, in build_extensions

          self._build_extensions_serial()

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\setuptools\_distutils\command\build_ext.py", line 510, in _build_extensions_serial

          self.build_extension(ext)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\Cython\Distutils\build_ext.py", line 131, in build_extension

          new_ext = cythonize(

                    ^^^^^^^^^^

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\Cython\Build\Dependencies.py", line 1159, in cythonize

          cythonize_one(*args)

        File "C:\Users\shipingzhong\AppData\Local\Temp\pip-build-env-jo3enh5_\overlay\Lib\site-packages\Cython\Build\Dependencies.py", line 1303, in cythonize_one

          raise CompileError(None, pyx_file)

      Cython.Compiler.Errors.CompileError: src\pymssql\_mssql.pyx

      [end of output]


  note: This error originates from a subprocess, and is likely not a problem with pip.

  ERROR: Failed building wheel for pymssql

Failed to build pymssql

error: failed-wheel-build-for-install


× Failed to build installable wheels for some pyproject.toml based projects

╰─> pymssql

你这个报错是典型的 pymssql 旧版本在新 Python(3.12)下编译失败 的情况。核心问题在于:

  1. pymssql 2.2.8 的 Cython 代码中使用了 long 类型,而 Python 3.x 中已经没有 long(Python 2 时代的类型)。

  2. 你用的是 Python 3.12,而 pymssql 2.2.8 发布时还没考虑 Python 3.12 的兼容性。

  3. 所以源码安装会失败(Failed building wheel)。


解决方案

1️⃣ 升级 pymssql 到兼容 Python 3.12 的版本

目前最新版本是 2.3.7,它对 Python 3.10+ 有更好支持:

pip install --upgrade pip wheel setuptools pip install pymssql==2.3.7


注意:2.3.x 系列的二进制 wheel 对 Windows 支持较好,通常可以直接安装。


2️⃣ 如果必须使用旧版本 2.2.8

你有两个选择:

  1. 降低 Python 版本
    使用 Python 3.10 或 3.11 创建虚拟环境,然后安装
    pymssql==2.2.8

    py -3.10 -m venv .venv310 .\.venv310\Scripts\activate pip install pymssql==2.2.8


  2. 手动修改源码(不推荐)
    _mssql.pyx 里的 long 改成 int,然后重新编译,但这比较麻烦。


3️⃣ Windows 下快速安装二进制 wheel

你也可以直接下载预编译好的 wheel:

  1. 打开 PyPI pymssqlUnofficial Windows Binaries

  2. 下载对应 Python 版本和架构的 .whl 文件

  3. 安装:

pip install C:\path\to\pymssql‑2.3.7‑cp312‑cp312‑win_amd64.whl



总结

  • 你的问题是 Python 3.12 + pymssql 2.2.8 不兼容

  • 推荐升级到 pymssql 2.3.7 或降低 Python 版本到 3.10/3.11。

  • 在 Windows 上安装二进制 wheel 可以避免编译问题。


如果你愿意,我可以帮你写一条 确保 Python 3.12 下可以直接成功安装 pymssql 的完整命令,省去各种报错。

你希望我直接给这条命令吗?



普通分类: