【问题标题】:Mac OS 11.4 Big Sur - fixing python cryptography package in /System/Library/Frameworks/Python.framework/Versions/2.7Mac OS 11.4 Big Sur - 修复 /System/Library/Frameworks/Python.framework/Versions/2.7 中的 python 加密包
【发布时间】:2021-09-18 09:56:49
【问题描述】:

我买了一台 MacBook Pro 13 M1(16 GB RAM,1 TB SSD),我正在尝试设置它以供工作,其中一部分是使用 python 2(是的,我知道它已经报废了,我仍然需要使用它,直到我们完成移植去)。我有一些我想从我的系统 python2 中删除的 python 包(我确定我必须在某个时候在这些上运行 sudo pip install ,我知道这很愚蠢,但是已经完成了)现在我在 Big Sur 我无法删除这些包裹。我尝试禁用 SIP,直到我可以将它们删除(csrutil disable 从恢复中),但现在我收到错误,我无法从只读文件系统中删除文件

sudo pip uninstall cryptography                                                                                                                                                                                            2  14:34
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
WARNING: The directory '/Users/darren/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Found existing installation: cryptography 3.3.2
Uninstalling cryptography-3.3.2:
  Would remove:
    /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography
    /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography-3.3.2-py2.7.egg-info
Proceed (y/n)? y
ERROR: Exception:
Traceback (most recent call last):
  File "/Users/darren/Library/Python/2.7/lib/python/site-packages/pip/_internal/cli/base_command.py", line 223, in _main
    status = self.run(options, args)
  File "/Users/darren/Library/Python/2.7/lib/python/site-packages/pip/_internal/commands/uninstall.py", line 90, in run
    auto_confirm=options.yes, verbose=self.verbosity > 0,
  File "/Users/darren/Library/Python/2.7/lib/python/site-packages/pip/_internal/req/req_install.py", line 686, in uninstall
    uninstalled_pathset.remove(auto_confirm, verbose)
  File "/Users/darren/Library/Python/2.7/lib/python/site-packages/pip/_internal/req/req_uninstall.py", line 403, in remove
    moved.stash(path)
  File "/Users/darren/Library/Python/2.7/lib/python/site-packages/pip/_internal/req/req_uninstall.py", line 292, in stash
    renames(path, new_path)
  File "/Users/darren/Library/Python/2.7/lib/python/site-packages/pip/_internal/utils/misc.py", line 355, in renames
    shutil.move(old, new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 323, in move
    rmtree(src)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 270, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 275, in rmtree
    onerror(os.remove, fullname, sys.exc_info())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 273, in rmtree
    os.remove(fullname)
OSError: [Errno 30] Read-only file system: '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/hazmat/_der.py'

但我无法将 root 重新挂载为读/写,并在尝试时收到此错误:

sudo mount -uw /
mount_apfs: volume could not be mounted: Permission denied
mount: / failed with 66

如果 /System/Library 是只读的,如何从这些文件中删除这些文件?既然 mac os 将这些文件放在只读文件系统中,我是否必须格式化我的系统并从头开始,还是有办法删除它们?

编辑:

所以我在 /System/Library 中破坏了阻止结构运行的包,因此我无法启动和运行我们的东西。主要的是密码学包。所以我要么需要修复这些包,以便fabric 可以运行或删除它们或其他东西。

让这变得如此痛苦的另一部分是我试图在 M1 Mac 上运行 python 2,这意味着要么使用内置的 python,要么使用带有 x86 python2 的 Rosetta,因为我没有找到安装 arm 的方法M1 Mac 上的 python 2(没有来自 python.org 或 brew 的安装程序,因为在 M1 Mac 发货时,python2 已经结束)。

编辑2:

也许我遇到问题的这些软件包确实随 Mac OS 一起提供,因为软件包文件夹的创建时间戳是“Jan 1 01:00:00 2020”,就像同一文件夹中的所有其他文件和文件夹一样。如果是这样,我想我需要以某种方式修复它们。当我尝试从命令行运行 fab 时,我在加密包中收到此错误:

fab
/Users/darren/Library/Python/2.7/lib/python/site-packages/paramiko/transport.py:33: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in the next release.
  from cryptography.hazmat.backends import default_backend
Traceback (most recent call last):
  File "/Users/darren/Library/Python/2.7/bin/fab", line 5, in <module>
    from fabric.main import program
  File "/Users/darren/Library/Python/2.7/lib/python/site-packages/fabric/__init__.py", line 3, in <module>
    from .connection import Config, Connection
  File "/Users/darren/Library/Python/2.7/lib/python/site-packages/fabric/connection.py", line 16, in <module>
    from paramiko.agent import AgentRequestHandler
  File "/Users/darren/Library/Python/2.7/lib/python/site-packages/paramiko/__init__.py", line 22, in <module>
    from paramiko.transport import SecurityOptions, Transport
  File "/Users/darren/Library/Python/2.7/lib/python/site-packages/paramiko/transport.py", line 129, in <module>
    class Transport(threading.Thread, ClosingContextManager):
  File "/Users/darren/Library/Python/2.7/lib/python/site-packages/paramiko/transport.py", line 190, in Transport
    if KexCurve25519.is_available():
  File "/Users/darren/Library/Python/2.7/lib/python/site-packages/paramiko/kex_curve25519.py", line 30, in is_available
    X25519PrivateKey.generate()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/hazmat/primitives/asymmetric/x25519.py", line 39, in generate
    from cryptography.hazmat.backends.openssl.backend import backend
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/hazmat/backends/openssl/__init__.py", line 7, in <module>
    from cryptography.hazmat.backends.openssl.backend import backend
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/hazmat/backends/openssl/backend.py", line 117, in <module>
    from cryptography.hazmat.bindings.openssl import binding
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/hazmat/bindings/openssl/binding.py", line 14, in <module>
    from cryptography.hazmat.bindings._openssl import ffi, lib
ImportError: dlopen(/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/hazmat/bindings/_openssl.so, 2): Symbol not found: _DTLS_client_method
  Referenced from: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/cryptography/hazmat/bindings/_openssl.so
  Expected in: flat namespace

Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/Users/darren/Library/Python/2.7/lib/python/site-packages/paramiko/transport.py", line 120, in _join_lingering_threads
    for thr in _active_threads:
TypeError: 'NoneType' object is not iterable
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/Users/darren/Library/Python/2.7/lib/python/site-packages/paramiko/transport.py", line 120, in _join_lingering_threads
    for thr in _active_threads:
TypeError: 'NoneType' object is not iterable

有其他人遇到过这个问题或有解决方法吗?

【问题讨论】:

  • 你不能,也不应该,也不应该。 不要删除这些文件;如果您不想使用此 Python 安装,请停止使用它。请注意,此 Python 安装是 MacOS 本身的一部分,因此如果您重新安装 MacOS,它仍然会存在。如果没有这些文件,您将无法有效安装 Big Sur。
  • 请注意,sudo pip install 不能像 rm 一样更改这些文件。
  • @nobled, ...此外,您完全可以在 M1 上安装不同的 Python 解释器。 brew 可能不会这样做,但 Nix 完全会。见stackoverflow.com/questions/65653464/…
  • @CharlesDuffy 感谢您的推荐。我以前没有使用或听说过 nix,但我能够通过 nix 安装 python2,然后安装 pip,然后安装密码学,现在 fabric 正在工作!
  • 顺便说一句,您可以告诉 Nix 为您安装 Python 模块(如 pip 或密码学)。 python27.withPackages (p: [p.pip p.cryptography]),例如。 nix-build -E '((import &lt;nixpkgs&gt; {}).python27.withPackages (p: [p.pip p.cryptography]))' 是实际运行它的一种方式。

标签: python macos python-2.7 pip python-cryptography


【解决方案1】:

我能够从 nix 为 Apple Silicon/M1 安装 python2,然后我必须手动安装 pip,它可以让我安装密码学和 cffi(我从 brew 安装了 libffi)。以下是我使用的步骤,我不确定它们是否都是必要的,但这就是我所做的:

  • 安装 Nix
  • 从 nix 安装 python2
    • nix-env -i python-2.7.18
    • 验证您是否在新的终端会话中使用此 python(您需要启动一个新的 shell 以获取更新的路径)
      • 运行which python
      • 如果它没有返回类似/Users/user/.nix-profile/bin/python 的内容,您需要将~/.nix-profile/bin 添加到路径的前面,启动一个新的shell,然后再次运行which python
  • 安装点子
  • 使用brew安装libiffopenssl@1.1
    • 我之前已经完成了这一步,我不能 100% 确定它是否有必要,但我相信它是必要的
    • brew install libiff openssl@1.1
    • 将以下内容添加到您的 .bashrc、.zshrc、.profile 或您设置环境变量的任何位置:
export LDFLAGS="-L$(brew --prefix openssl@1.1)/lib"
export CFLAGS="-I$(brew --prefix openssl@1.1)/include"
  • 使用 pip 安装密码学
    • pip install cryptography

在此之后,我安装了一个带有密码学的功能性 python,然后我能够安装结构(通过pip install fabric==1.14.1,因为 1.14.1 是这个旧项目所需的版本,使用你需要的版本)

编辑: 感谢@CharlesDuffy 的所有帮助,正如他在下面的 cmets 中正确提到的那样,您可以(并且可能应该)从 nix 安装所有依赖项和加密,而不是使用 brew 和 nix 的组合。我在安装 Nix 之前安装了 brew 和依赖项,所以我没有对其进行测试,但它应该工作。

【讨论】:

  • 你也可以让 Nix 安装 libtiff、openssl、加密包等——我个人根本不安装 Homebrew。 (用于在 MacOS 上填充可构建包集的构建步骤存储库也用于 NixOS,这是一个功能齐全的 Linux 发行版——一般来说,人们可能想要的一切都在那里)。
  • 是的,我可能会推荐其他需要这样做的人这样做,但在我听说 Nix 之前,我已经安装了 homebrew、libiff、openssl 等,所以我真的做到了几周前,然后今天刚刚安装了 Nix 和 python2,因为我已经安装了 libiff、openssl 等,我只是用它们试了一下,它工作了,所以我说,“足够好”
猜你喜欢
  • 2016-05-08
  • 2015-05-12
  • 2014-06-13
  • 1970-01-01
  • 1970-01-01
  • 2014-03-18
  • 1970-01-01
  • 1970-01-01
  • 2021-04-28
相关资源
最近更新 更多