Mac OS 11.4 Big Sur - 在 /System/Library/Frameworks/Python.framework/Versions/2.7 中修复 python 密码包

Mac OS 11.4 Big Sur - fixing python cryptography package in /System/Library/Frameworks/Python.framework/Versions/2.7

我购买了 MacBook Pro 13 M1(16 GB 内存,1 TB 固态硬盘),我正在尝试对其进行工作设置,其中一部分是使用 python 2 (是的,我知道它的生命已经结束,我仍然需要使用它直到我们完成移植)。我有一些 python 包我想从我的系统 python2 中删除(我确定我必须在某些时候在这些包上安装 运行 sudo pip install,我知道是愚蠢的,但已经完成了)现在我在大苏尔我不能删除这些包。我尝试禁用 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 重新挂载为 read/write,并且在尝试时出现此错误:

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

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

编辑:

所以我在 /System/Library 中破坏了阻止织物 运行ning 的包裹,所以我无法把我们的东西起来 运行ning。主要的是密码学包。所以我要么需要修复这些包,以便 fabric 可以 运行 或删除它们或其他东西。

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

编辑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

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

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

  • 安装尼克斯
  • 从 nix 安装 python2
    • nix-env -i python-2.7.18
    • 验证您是否在新的终端会话中使用此 python(您需要启动一个新的 shell 以获取更新的路径)
      • 运行 which python
      • 如果它没有 return 类似 /Users/user/.nix-profile/bin/python 的东西,您需要将 ~/.nix-profile/bin 添加到路径的前面,开始一个新的 shell,然后运行 which python 再次
  • 安装pip
  • 使用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 的所有帮助,正如他在下面的评论中正确提到的那样,您可以(并且可能应该)从 nix 安装所有依赖项和密码术,而不是使用 brew 和 nix 的组合。我在安装 Nix 之前安装了 brew 和依赖项,所以我还没有测试它,但它 应该 工作。