Xcode Python -太多层次的符号链接



试图设置Xcode为python开发只是因为我遇到了一个问题。

我遵循这个教程:在XCode 10中运行Python代码!(2018)虽然UI在项目的初始创建中有点不同,但我能够找到我正在寻找的东西。

python3:/usr/bin/python3路径

在遵循指令并运行代码后,我遇到了这个错误:

2021-08-10 14:20:54.227437-0500 python3[5828:364044] Failed to open macho file at /Library/Developer/CommandLineTools/usr/bin/python3 for reading: Too many levels of symbolic links
/Library/Developer/CommandLineTools/usr/bin/python3: can't open file 'testingPython.py': [Errno 1] Operation not permitted
Program ended with exit code: 2

我检查了/usr/bin目录,我没有看到任何代表python3的符号链接

lrwxr-xr-x     1 root   wheel        74 Jan  1  2020 pydoc -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pydoc2.7
lrwxr-xr-x     1 root   wheel        74 Jan  1  2020 pydoc2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pydoc2.7
lrwxr-xr-x     1 root   wheel        75 Jan  1  2020 python -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x     1 root   wheel        82 Jan  1  2020 python-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
lrwxr-xr-x     1 root   wheel        75 Jan  1  2020 python2 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x     1 root   wheel        75 Jan  1  2020 python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x     1 root   wheel        82 Jan  1  2020 python2.7-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
-rwxr-xr-x     1 root   wheel    137616 Jan  1  2020 python3
lrwxr-xr-x     1 root   wheel        76 Jan  1  2020 pythonw -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
lrwxr-xr-x     1 root   wheel        76 Jan  1  2020 pythonw2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7

所以我决定检查Homebrew:brew info python3

得到了这个

python@3.9: stable 3.9.5 (bottled)
Interpreted, interactive, object-oriented programming language
https://www.python.org/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/python@3.9.rb
License: Python-2.0
==> Dependencies
Build: pkg-config ✘
Required: gdbm ✘, mpdecimal ✘, openssl@1.1 ✔, readline ✘, sqlite ✘, xz ✘
==> Caveats
Python has been installed as
/opt/homebrew/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/opt/homebrew/opt/python@3.9/libexec/bin
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/opt/homebrew/lib/python3.9/site-packages
tkinter is no longer included with this formula, but it is available separately:
brew install python-tk@3.9
See: https://docs.brew.sh/Homebrew-and-Python

它提到没有安装,所以我试着重新安装,得到一个警告:

Warning: The post-install step did not complete successfully
You can try again using:
brew postinstall python@3.9

所以我试着安装后,得到相同的响应

所以我进入并手动删除了/opt/homebrew.bin和整个文件夹/opt/homebrew/python@3.9中所有的Homebrew python3的符号链接

再次运行构建,得到相同的错误输出

重新安装python3:brew install python3

Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
Updated 2 formulae.
==> Downloading https://ghcr.io/v2/homebrew/core/python/3.9/manifests/3.9.6
Already downloaded: /Users/dmconklin/Library/Caches/Homebrew/downloads/497333c6ca5bfe88a2fd95008a6b111ac766162ed5900db38c7529dbd33e2859--python@3.9-3.9.6.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/python/3.9/blobs/sha256:36bdb8151cdc242487b9d3e6d6f305057b5699b4f6ac6905fc875e11b4ac2f3b
Already downloaded: /Users/dmconklin/Library/Caches/Homebrew/downloads/19520443760763aaa669f5ffeafb108cb2ba3b2b10f674bc4dc179b05f30ef3f--python@3.9--3.9.6.arm64_big_sur.bottle.tar.gz
==> Pouring python@3.9--3.9.6.arm64_big_sur.bottle.tar.gz
Warning: This keg was marked linked already, continuing anyway
==> /opt/homebrew/Cellar/python@3.9/3.9.6/bin/python3 -m ensurepip
==> /opt/homebrew/Cellar/python@3.9/3.9.6/bin/python3 -m pip install -v --no-deps --no-index --upgrade --isolated --target=/opt/homebrew/lib/python3.9/site-packages /opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python
==> Caveats
Python has been installed as
/opt/homebrew/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/opt/homebrew/opt/python@3.9/libexec/bin
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/opt/homebrew/lib/python3.9/site-packages
tkinter is no longer included with this formula, but it is available separately:
brew install python-tk@3.9
See: https://docs.brew.sh/Homebrew-and-Python
==> Summary
🍺  /opt/homebrew/Cellar/python@3.9/3.9.6: 3,080 files, 56.5MB

brew info python3

python@3.9: stable 3.9.6 (bottled)
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/opt/homebrew/Cellar/python@3.9/3.9.6 (3,080 files, 56.5MB) *
Poured from bottle on 2021-08-10 at 15:29:26
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/python@3.9.rb
License: Python-2.0
==> Dependencies
Build: pkg-config ✘
Required: gdbm ✔, mpdecimal ✔, openssl@1.1 ✔, readline ✔, sqlite ✔, xz ✔
==> Caveats
Python has been installed as
/opt/homebrew/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/opt/homebrew/opt/python@3.9/libexec/bin
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/opt/homebrew/lib/python3.9/site-packages
tkinter is no longer included with this formula, but it is available separately:
brew install python-tk@3.9
See: https://docs.brew.sh/Homebrew-and-Python

在之后,我仍然有相同的错误,关于符号链接的层次太多

我不知道还能做什么,也不知道该去哪里找。

发现:

lrwxr-xr-x   1 dmconklin  admin      8 Jun 28 03:57 2to3 -> 2to3-3.9
-rwxr-xr-x   1 dmconklin  admin    169 Aug 10 15:29 2to3-3.9
lrwxr-xr-x   1 dmconklin  admin      7 Jun 28 03:57 idle3 -> idle3.9
-rwxr-xr-x   1 dmconklin  admin    167 Aug 10 15:29 idle3.9
-rwxr-xr-x   1 dmconklin  admin    247 Aug 10 15:29 pip3
-rwxr-xr-x   1 dmconklin  admin    247 Aug 10 15:29 pip3.9
lrwxr-xr-x   1 dmconklin  admin      8 Jun 28 03:57 pydoc3 -> pydoc3.9
-rwxr-xr-x   1 dmconklin  admin    152 Aug 10 15:29 pydoc3.9
lrwxr-xr-x   1 dmconklin  admin      9 Jun 28 03:57 python3 -> python3.9
lrwxr-xr-x   1 dmconklin  admin     16 Jun 28 03:57 python3-config -> python3.9-config
-rwxr-xr-x   1 dmconklin  admin  69168 Aug 10 15:29 python3.9
-rwxr-xr-x   1 dmconklin  admin   2111 Aug 10 15:29 python3.9-config

in:/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/bin

我试图使用该文件路径直接python3.9而不是python3在/usr/bin/,仍然得到相同的输出在Xcode

Xcode设置我也试过这个Xcode设置

同样的结果,太多的符号链接

还要注意,当编辑

方案时,python3是不可访问的/opt/组装/bin/opt/自酿酒酒窖/python@3.9/3.9.6/框架/Python.framework/版本/3.9/bin

我也遇到过这个问题。我在/opt/homebrew/bin文件夹中创建了一个指向python3的链接,并解决了此警报。

cd /opt/homebrew/bin
ln python3 xcodePython3  // any name you'd like to use

然后在"Edit scheme"中选择"Executable"到/opt/homebrew/bin文件夹,选择xcodePython3.

你找错方向了。

  1. /usr/bin/python3从未存在过,甚至/usr/bin/python2也将在未来的macOS版本中退出macOS。建议安装pyenvconda版本的python。

  2. 你把Python搞砸了。自制包python被设计为其他自制包的依赖项。默认的链接python包应该是python,但不是python@3.9这样的版本。

    brew unlink python@3.9
    brew install python
    brew link python # this may be unneeded, run it anyway
    

对于您的项目,如果需要python3,请选择/opt/homebrew/bin/python3。但是对于包含许多第三方python包的大型项目,请使用虚拟环境。

顺便说一句,你们用Xcode编写python ?切换到VSCode或Pycharm

最新更新