无法在Mac上安装异步SQLlalchemy(致命错误:#include "Python.h" 找不到'Python.h'文件)



我试图在虚拟环境中安装async-sqlalchemy,但在安装asyncpg软件包时出错。

我重新安装了python,进行了自制程序升级,但没有帮助。

其他输入:

  • macOS蒙特利12.4
  • 苹果M1 Max
  • python是使用自制软件安装的
  • 标头位置:/opt/homebrew/Frameworks/Python.framework/Headers/Python.h
  • Python 3.8.9安装在虚拟环境中

错误文本:

(venv) ➜  project1 git:(main) ✗ pip install async-sqlalchemy
pip install async-sqlalchemy
Collecting async-sqlalchemy
Using cached async_sqlalchemy-1.0.0-py3-none-any.whl (2.1 kB)
Collecting sqlalchemy
Using cached SQLAlchemy-1.4.40.tar.gz (8.3 MB)
Preparing metadata (setup.py) ... done
Collecting asyncpg
Using cached asyncpg-0.26.0.tar.gz (809 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Collecting aiomysql
Using cached aiomysql-0.1.1-py3-none-any.whl (43 kB)
Collecting PyMySQL>=1.0
Using cached PyMySQL-1.0.2-py3-none-any.whl (43 kB)
Building wheels for collected packages: asyncpg, sqlalchemy
Building wheel for asyncpg (pyproject.toml) ... error
error: subprocess-exited-with-error

× Building wheel for asyncpg (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [10 lines of output]
running bdist_wheel
running build
running build_py
running build_ext
building 'asyncpg.pgproto.pgproto' extension
asyncpg/pgproto/pgproto.c:31:10: fatal error: 'Python.h' file not found
#include "Python.h"
^~~~~~~~~~
1 error generated.
error: command '/usr/bin/clang' failed with exit code 1
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for asyncpg
Building wheel for sqlalchemy (setup.py) ... done
Created wheel for sqlalchemy: filename=SQLAlchemy-1.4.40-cp38-cp38-macosx_10_14_arm64.whl size=1563095 sha256=dec89820eeaacf37173105593f3bd9762e66d86bec9d058b6e16a2a6b0905467
Stored in directory: /Users/[user_name deleted_intentionally]/Library/Caches/pip/wheels/b6/24/79/b40cf000cb96fbda45242a556ce18006f8ca34712487c09a90
Successfully built sqlalchemy
Failed to build asyncpg

我也面临着同样的问题,并进行了大量的研究。终于在我的另一个python项目中发现了问题

源venv/bin/激活

处于活动状态。所以我已经从另一个项目中停用,然后再次重新运行安装。

最新更新