【问题标题】:Xcode Python - Too many levels of symbolic linksXcode Python - 符号链接的级别太多
【发布时间】:2021-10-14 09:48:31
【问题描述】:

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

我遵循了这个教程:Run Python Code in XCode 10! (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

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

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

Xcode Settings 也试过这个 Xcode Settings

相同的结果,符号链接的级别太多

另请注意,编辑方案时无法访问 python3

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

【问题讨论】:

  • 找到显示python3 可执行文件的实际路径的设置,并将其从/usr/bin/python3 更改为/opt/homebrew/bin/python3。这有帮助吗? /usr/bin/python3 是 Python 的系统版本。您想要 Homebrew 版本。
  • @MattDMo 它没有
  • @MattDMo @DMConklin macOS 不是 Linux。永远不要碰/usr/bin/。事实上,除非禁用 SIP,否则您无法将内容链接到那里。
  • @Simba 我从不建议与/usr/bin 搞混。我只是说他们应该在 XCode 设置中更改 python 解释器路径。我已经使用 OSX/macOS 十多年了,我知道 /usr/bin。不过,就您的观点而言,如果您确实需要新的系统范围的二进制文件或链接,/usr/local/bin 是您的最佳选择。

标签: python-3.x macos homebrew symlink xcode12


【解决方案1】:

您正在寻找错误的解决方案。

  1. /usr/bin/python3 从未存在过,即使是 /usr/bin/python2 的交付也将在未来的 macOS 版本中退出 macOS。建议使用pyenvconda 安装python。

  2. 你在自制软件中搞砸了 Python。 Homebrew 包 python 旨在作为其他 brewed 包的依赖项。默认链接的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。

【讨论】:

  • 删除文件夹后,我已经重新安装了 python。 brew install pythonbrew install python3 相同 此外,/opt/homebrew/bin/python3 在编辑方案时不是可选择的可执行文件,在将其添加到 External Build Tool Configuration 下的构建工具字段时,路径也不会产生任何结果我通常使用 VSCode for python,这只是我想看看我是否可以为未来工作,当我终于开始学习并快速学习时大声笑
猜你喜欢
  • 1970-01-01
  • 2012-09-26
  • 2015-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-12
  • 1970-01-01
相关资源
最近更新 更多