错误:无法为 pymssql 构建***,这是在 Mac M1 中安装基于 pyproject.toml 的项目所必需的

Posted

技术标签:

【中文标题】错误:无法为 pymssql 构建***,这是在 Mac M1 中安装基于 pyproject.toml 的项目所必需的【英文标题】:ERROR: Could not build wheels for pymssql, which is required to install pyproject.toml-based projects In Mac M1 【发布时间】:2022-01-16 21:08:33 【问题描述】:

我正在使用带有 M1 芯片的 MacBook,似乎有很多东西没有针对它进行优化。pyodbc 不适合我,所以我想使用 pymssql。 不过,我在尝试运行 pip install pymssql 时遇到了这个问题。

错误如下。

  Using cached pymssql-2.2.2.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: Command errored out with exit status 1:
Your project path and someinfo about it.

Complete output (25 lines):
  setup.py: platform.system() => Darwin
  setup.py: platform.architecture() => ('64bit', '')
  setup.py: platform.libc_ver() => ('', '')
  setup.py: include_dirs => []
  setup.py: library_dirs => []
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.9-universal2-3.9
  creating build/lib.macosx-10.9-universal2-3.9/pymssql
  copying src/pymssql/__init__.py -> build/lib.macosx-10.9-universal2-3.9/pymssql
  running build_ext
  cythoning src/pymssql/_mssql.pyx to src/pymssql/_mssql.c
  cythoning src/pymssql/_pymssql.pyx to src/pymssql/_pymssql.c
  building 'pymssql._mssql' extension
  creating build/temp.macosx-10.9-universal2-3.9
  creating build/temp.macosx-10.9-universal2-3.9/src
  creating build/temp.macosx-10.9-universal2-3.9/src/pymssql
  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -I/Users/lakshayrohilla/SMS Project Files /cracs-backend/.venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c src/pymssql/_mssql.c -o build/temp.macosx-10.9-universal2-3.9/src/pymssql/_mssql.o -DMSDBLIB
  src/pymssql/_mssql.c:682:10: fatal error: 'sqlfront.h' file not found
  #include "sqlfront.h"
           ^~~~~~~~~~~~
  1 error generated.
  error: command '/usr/bin/gcc' failed with exit code 1
  ----------------------------------------
  **ERROR: Failed building wheel for pymssql**
Failed to build pymssql
**ERROR: Could not build wheels for pymssql, which is required to install pyproject.toml-based projects**

【问题讨论】:

【参考方案1】:

在尝试解决此问题的大量解决方案时,似乎对我有用。 我提供下面的代码来解决这个问题。

重要提示: 根据您的系统更改路径。

1. brew install freetds
2. brew install openssl
3. export LDFLAGS="-L/opt/homebrew/Cellar/freetds/1.3.3/lib -L/opt/homebrew/Cellar/openssl@1.1/1.1.1l_1/lib"
4. export CFLAGS="-I/opt/homebrew/Cellar/freetds/1.3.3/include" 
5. pip install pymssql

只需运行上述命令,它应该可以解决您的问题,因为它对我来说很有效。

【讨论】:

【参考方案2】:

运行以下命令解决了我的问题

$ brew install freetds openssl
$ echo 'export LDFLAGS="-L/opt/homebrew/opt/freetds/lib -L/opt/homebrew/opt/openssl@3/lib"' >> ~/.zshrc
$ echo 'export CFLAGS="-I/opt/homebrew/opt/freetds/include"' >> ~/.zshrc
$ echo 'export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"' >> ~/.zshrc
$ source ~/.zshrc
$ pip3 install pymssql

【讨论】:

以上是关于错误:无法为 pymssql 构建***,这是在 Mac M1 中安装基于 pyproject.toml 的项目所必需的的主要内容,如果未能解决你的问题,请参考以下文章

在 OS X 上构建 pymssql

pymssql 连接失败,出现“无法识别排序规则”

pymssql,无法执行EXEC命令sql

python pymssql 错误:18456,b'DB-Lib 错误消息 20010,严重性 8:\n无法分配足够的内存

无法使用带有 Windows 身份验证的 pymssql 进行连接

pymssql.connect 错误 - 意外的关键字参数“服务器”