如何< Python.h>在Xcode中#include

hrirmatl  于 2022-11-19  发布在  Python
关注(0)|答案(1)|浏览(118)

#include <Python.h>此代码的错误为'Python.h' file not found
我用brew安装了python,结果如下所示。python的路径已经写入$PATH

MacBook-Pro test % python --version
Python 3.10.8
MacBook-Pro test % brew search python
==> Formulae
app-engine-python                    python-tk@3.11
boost-python3                        python-tk@3.9
bpython                              python-typing-extensions
gst-python                           python-yq
ipython                              python@3.10 ✔
libpython-tabulate                   python@3.11
micropython                          python@3.7
ptpython                             python@3.8
python-build                         python@3.9
python-gdbm@3.11                     reorder-python-imports
python-launcher                      wxpython
python-lsp-server                    pythran
python-markdown                      jython
python-tabulate                      cython
python-tk@3.10

==> Casks
awips-python                         mysql-connector-python

If you meant "python" specifically:
It was migrated from homebrew/cask to homebrew/core.
MacBook-Pro test % echo $PATH
/usr/local/opt/python@3.10/libexec/bin:/Users/fanxuezhou/opt/anaconda3/bin:/Users/fanxuezhou/opt/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin

如果有人能告诉我如何在Xcode中使用Python.h,或者我如何通过命令行编译代码?

MacBook-Pro test % gcc main.cpp -o test 
main.cpp:9:10: fatal error: 'Python.h' file not found
#include <Python.h>
         ^~~~~~~~~~
1 error generated.

The error message of Xcode

1aaf6o9v

1aaf6o9v1#

我已经通过使用g++解决了这个问题,

g++ main.cpp -o test -I /usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/include/ -L /usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib  -l python3.10

相关问题