cython在windows下long格式的处理 2022-05-20

本文探讨了在Windows环境下使用Cython时,由于long类型的差异性,如何正确处理类型定义,以确保代码的兼容性。通过实例说明了修改类型名称的必要性和步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于cython中,long在linux和windows下的含义不同,因此在windows中需要修改一下对应的类型名称,如下图所示。

在这里插入图片描述

PS F:\TB0723> pip install pymssql==2.2.7 Looking in indexes: https://mirrors.aliyun.com/pypi/simple Collecting pymssql==2.2.7 Using cached https://mirrors.aliyun.com/pypi/packages/64/68/c1ba0fabf98ebe9d22afc23c6b6803553b28911ed36bb53b8be93feb2446/pymssql-2.2.7.tar.gz (170 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 ╰─> [188 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\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\_distutils\dist.py:289: UserWarning: Unknown distribution option: 'tests_require' warnings.warn(msg) C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\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-313\pymssql copying src\pymssql\__init__.py -> build\lib.win-amd64-cpython-313\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 Error compiling Cython file: ------------------------------------------------------------ ... cdef void init_mssql(): if dbinit() == FAIL: raise MSSQLDriverException("dbinit() failed") dberrhandle(err_handler) ^ ------------------------------------------------------------ src\pymssql\_mssql.pyx:2173:16: Cannot assign type 'int (DBPROCESS *, int, int, int, char *, char *) except? -1 nogil' to 'EHANDLEFUNC' (alias of 'int (*)(DBPROCESS *, int, int, int, char *, char *) noexcept'). Exception values are incompatible. Suggest adding 'noexcept' to the type of 'err_handler'. Error compiling Cython file: ------------------------------------------------------------ ... cdef void init_mssql(): if dbinit() == FAIL: raise MSSQLDriverException("dbinit() failed") dberrhandle(err_handler) dbmsghandle(msg_handler) ^ ------------------------------------------------------------ src\pymssql\_mssql.pyx:2174:16: Cannot assign type 'int (DBPROCESS *, DBINT, int, int, char *, char *, char *, LINE_T) except? -1 nogil' to 'MHANDLEFUNC' ( alias of 'int (*)(DBPROCESS *, DBINT, int, int, char *, char *, char *, int) noexcept'). Exception values are incompatible. Suggest adding 'noexcept' to the type of 'msg_handler'. Compiling src\pymssql\_mssql.pyx because it changed. [1/1] Cythonizing src\pymssql\_mssql.pyx Traceback (most recent call last): File "C:\Python313\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 389, in <module> main() ~~~~^^ File "C:\Python313\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:\Python313\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 280, in build_wheel return _build_backend().build_wheel( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ wheel_directory, config_settings, metadata_directory ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\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\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\build_meta.py", line 423, in _build return self._build_with_temp_dir( ~~~~~~~~~~~~~~~~~~~~~~~~~^ cmd, ^^^^ ...<3 lines>... self._arbitrary_args(config_settings), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\build_meta.py", line 404, in _build_with_temp_dir self.run_setup() ~~~~~~~~~~~~~~^^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\build_meta.py", line 512, in run_setup super().run_setup(setup_script=setup_script) ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\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\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\__init__.py", line 115, in setup return distutils.core.setup(**attrs) ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 186, in setup return run_commands(dist) File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 202, in run_commands dist.run_commands() ~~~~~~~~~~~~~~~~~^^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 1002, in run_commands self.run_command(cmd) ~~~~~~~~~~~~~~~~^^^^^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\dist.py", line 1102, in run_command super().run_command(command) ~~~~~~~~~~~~~~~~~~~^^^^^^^^^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 1021, in run_command cmd_obj.run() ~~~~~~~~~~~^^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\command\bdist_wheel.py", line 370, in run self.run_command("build") ~~~~~~~~~~~~~~~~^^^^^^^^^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 357, in run_command self.distribution.run_command(command) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\dist.py", line 1102, in run_command super().run_command(command) ~~~~~~~~~~~~~~~~~~~^^^^^^^^^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 1021, in run_command cmd_obj.run() ~~~~~~~~~~~^^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\_distutils\command\build.py", line 135, in run self.run_command(cmd_name) ~~~~~~~~~~~~~~~~^^^^^^^^^^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 357, in run_command self.distribution.run_command(command) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\dist.py", line 1102, in run_command super().run_command(command) ~~~~~~~~~~~~~~~~~~~^^^^^^^^^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 1021, in run_command cmd_obj.run() ~~~~~~~~~~~^^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\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\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\_distutils\command\build_ext.py", line 484, in build_extensions self._build_extensions_serial() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\setuptools\_distutils\command\build_ext.py", line 510, in _build_extensions_serial self.build_extension(ext) ~~~~~~~~~~~~~~~~~~~~^^^^^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\Cython\Distutils\build_ext.py", line 131, in build_extension new_ext = cythonize( ~~~~~~~~~^ ext,force=self.force, quiet=self.verbose == 0, **options ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ )[0] ^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\Cython\Build\Dependencies.py", line 1154, in cythonize cythonize_one(*args) ~~~~~~~~~~~~~^^^^^^^ File "C:\Users\86293\AppData\Local\Temp\pip-build-env-fvhg86yf\overlay\Lib\site-packages\Cython\Build\Dependencies.py", line 1298, 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 to build installable wheels for some pyproject.toml based projects (pymssql) 在PyCharm中安装失败
最新发布
07-24
Requirement already satisfied: setuptools>=0.7 in ./.venv/lib/python3.9/site-packages (from APScheduler==3.7.0->-r requirements.txt (line 4)) (80.9.0) Requirement already satisfied: gevent in ./.venv/lib/python3.9/site-packages (from grequests==0.6.0->-r requirements.txt (line 40)) (25.5.1) Requirement already satisfied: numpy>=1.15.4 in ./.venv/lib/python3.9/site-packages (from pandas==1.1.5->-r requirements.txt (line 58)) (2.0.2) Requirement already satisfied: scikit-learn in ./.venv/lib/python3.9/site-packages (from sklearn==0.0->-r requirements.txt (line 79)) (1.6.1) INFO: pip is looking at multiple versions of gevent to determine which version is compatible with other requirements. This could take a while. Collecting gevent (from grequests==0.6.0->-r requirements.txt (line 40)) Downloading gevent-25.4.2.tar.gz (6.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.3/6.3 MB 10.8 MB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Downloading gevent-25.4.1.tar.gz (6.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.3/6.3 MB 7.4 MB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Downloading gevent-24.11.1.tar.gz (6.0 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.0/6.0 MB 11.8 MB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Downloading gevent-24.10.3.tar.gz (6.1 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.1/6.1 MB 7.4 MB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> [39 lines of output] Compiling src/gevent/resolver/cares.pyx because it changed. [1/1] Cythonizing src/gevent/resolver/cares.pyx Error compiling Cython file: ------------------------------------------------------------ ... cdef tuple integer_types if sys.version_info[0] >= 3: integer_types = int, else: integer_types = (int, long) ^ ------------------------------------------------------------ src/gevent/libev/corecext.pyx:69:26: undeclared name not builtin: long Compiling src/gevent/libev/corecext.pyx because it changed. [1/1] Cythonizing src/gevent/libev/corecext.pyx Traceback (most recent call last): File "/Users/didi/code/doraemon-api/.venv/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 389, in <module> main() File "/Users/didi/code/doraemon-api/.venv/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 373, in main json_out["return_val"] = hook(**hook_input["kwargs"]) File "/Users/didi/code/doraemon-api/.venv/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 143, in get_requires_for_build_wheel return hook(config_settings) File "/private/var/folders/cf/1231crpx4hsf3vf_6wtb6ybw0000ks/T/pip-build-env-i9_0xwq3/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 331, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=[]) File "/private/var/folders/cf/1231crpx4hsf3vf_6wtb6ybw0000ks/T/pip-build-env-i9_0xwq3/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 301, in _get_build_requires self.run_setup() File "/private/var/folders/cf/1231crpx4hsf3vf_6wtb6ybw0000ks/T/pip-build-env-i9_0xwq3/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 317, in run_setup exec(code, locals()) File "<string>", line 54, in <module> File "/private/var/folders/cf/1231crpx4hsf3vf_6wtb6ybw0000ks/T/pip-install-p6p1o97m/gevent_804a446da2d9472bb3cfb9a391265401/_setuputils.py", line 249, in cythonize1 new_ext = cythonize( File "/private/var/folders/cf/1231crpx4hsf3vf_6wtb6ybw0000ks/T/pip-build-env-i9_0xwq3/overlay/lib/python3.9/site-packages/Cython/Build/Dependencies.py", line 1154, in cythonize cythonize_one(*args) File "/private/var/folders/cf/1231crpx4hsf3vf_6wtb6ybw0000ks/T/pip-build-env-i9_0xwq3/overlay/lib/python3.9/site-packages/Cython/Build/Dependencies.py", line 1298, in cythonize_one raise CompileError(None, pyx_file) Cython.Compiler.Errors.CompileError: src/gevent/libev/corecext.pyx [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip.
06-17
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值