Python 在 Macbook 上安装失败

Python Installation is Broken on Macbook

所以我认为我的 Python 框架完全坏了。 我知道这一点是因为我的脚本在 Windows 10 机器上运行没有任何问题,当我尝试使用 which python 检查 python 的版本时,我收到一条错误的选项消息。当我尝试 运行 任何 python 脚本时,我得到这个:

 richardbarret@1152-MBP  ~/Git/SalesforceCLI/Python/Cases   master ⍟3  python read_all_sev1_cases.py                                                    ✔  1316  10:34:36
Traceback (most recent call last):
  File "read_all_sev1_cases.py", line 14, in <module>
    import simple_salesforce
  File "/Users/richardbarret/Library/Python/2.7/lib/python/site-packages/simple_salesforce/__init__.py", line 4, in <module>
    from .api import Salesforce, SFType
  File "/Users/richardbarret/Library/Python/2.7/lib/python/site-packages/simple_salesforce/api.py", line 12, in <module>
    from urllib.parse import urljoin, urlparse
ImportError: No module named parse
 richardbarret@1152-MBP  ~/Git/SalesforceCLI/Python/Cases   master ⍟3  which python                                                                   1 ↵  1317  10:34:41
type: bad option: -l
 richardbarret@1152-MBP  ~/Git/SalesforceCLI/Python/Cases   master ⍟3  python -V                                                                      1 ↵  1318  10:34:49
Python 2.7.16
 richardbarret@1152-MBP  ~/Git/SalesforceCLI/Python/Cases   master ⍟3  pip -V                                                                           ✔  1319  10:34:52
pip 20.0.2 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

此外,我最近尝试用brew卸载并重新安装,而之前它可以工作但我无法通过pip安装fire模块。修复是卸载它,现在......我想我已经破坏了框架只是为了安装一个模块。我的 macbook 现在对于本地 pythonic 开发几乎完全没用,它阻碍了我的工作流程。

好吧,既然有人投了反对票并且没有提供解释,我将尽可能详细。

在我的 Macbook 上,我尝试 运行 与我的 Windows 机器一起工作的 python 脚本:

PS C:\Users\richard.barrett\Git\Salesforce-CLI\Python\Cases> python -V
Python 3.8.0
PS C:\Users\richard.barrett\Git\Salesforce-CLI\Python\Cases> python .\read_all_handover_cases.py
The file does not exist encryption on secrets.json not in use
00DE0000000JFpb!AQwAQExSYpskesZsmLXq9jYeojeBC1px0ojrhLuxMYHpCBJgz6iM5jVqZxmFzp4sQHy6DvXhnNsQnw.0JGNolxziUpWJfdNI
        0               1                 2        3   ...     9      10     11             12
0  2910831  Technical Case  Aleksandr Dobdin  Pending  ...  false  false  false  Sev3 (Normal)
1  3362385  Technical Case   Bradley Shirley  Pending  ...  false  false  false     Sev4 (Low)
2  3492261  Technical Case  Othmane Madjoudj  Pending  ...  false  false  false  Sev3 (Normal)

[3 rows x 13 columns]

这很好,我希望在我的 Macbook 上也能看到。但是,由于某些奇怪的原因,我的 Python 无法正常工作,它指向 macbook 上的旧版本。我尝试 运行 相同的脚本并得到以下结果:

 richardbarret@1152-MBP  ~/Git/SalesforceCLI/Python/Cases   master ⍟3  python read_all_handover_cases.py                                                ✔  1320  10:35:06
Traceback (most recent call last):
  File "read_all_handover_cases.py", line 14, in <module>
    import simple_salesforce
  File "/Users/richardbarret/Library/Python/2.7/lib/python/site-packages/simple_salesforce/__init__.py", line 4, in <module>
    from .api import Salesforce, SFType
  File "/Users/richardbarret/Library/Python/2.7/lib/python/site-packages/simple_salesforce/api.py", line 12, in <module>
    from urllib.parse import urljoin, urlparse
ImportError: No module named parse

当我查找错误时,它说我 运行正在使用旧版本的 Python。我通过 brew 重新安装了它,在所有补丁与 python fire 模块一起工作之前......我没有问题并且可以 运行 我的脚本在 CLI 中很好。

此外,这里是 python 每当我尝试使用 pip 安装某些东西时崩溃:

Process:               Python [56510]
Path:                  /usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python
Identifier:            Python
Version:               3.7.7 (3.7.7)
Code Type:             X86-64 (Native)
Parent Process:        zsh [46993]
Responsible:           iTerm2 [838]
User ID:               502

Date/Time:             2020-04-24 11:47:24.835 -0500
OS Version:            Mac OS X 10.15.4 (19E287)
Report Version:        12
Anonymous UUID:        229910A5-BB3B-6822-3072-5658F7AEAFD4

Sleep/Wake UUID:       7FFE90BD-04FC-4B46-85DE-012621D1B4B4

Time Awake Since Boot: 59000 seconds
Time Since Wake:       4600 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Application Specific Information:
/usr/lib/libcrypto.dylib
abort() called
Invalid dylib load. Clients should not load the unversioned libcrypto dylib as it does not have a stable ABI.

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x00007fff734d933a __pthread_kill + 10

虽然我以前一直有这个问题,但当我尝试调用一个未标记为可执行文件的脚本时 python3 some_script_needing_version_3.py

是的,这是一个损坏的 Python 框架。 我理解为什么人们对它投反对票,因为它基本上是在说我没有安装模块。但是,我将它们安装在版本 Python 2.7 中,这是 Macbook 随附的版本。每次我用 pip 安装它时,它都会说要求已经满足。但是,我在 python3.7 上使用 运行 的应用程序,因此是的......我没有为 Python3.7 安装模块。但是,每次我 运行 pip3python3 python 都会崩溃。

我使用 Brew 来帮助管理一些事情。 我不得不清理一些东西 运行ning brew doctor 和 brew cleanup。 然后我不得不修复我的 macbook 上所有损坏的符号链接并删除一些损坏的库​​,这些库不允许我分别 运行 pip3 或 python3。此外,我不得不通过 brew 卸载 openssl 并在 python 中卸载加密,从而将以下行添加到我的 .zshrc 配置文件中。

将此添加到您的 Shell 个人资料中: export DYLD_LIBRARY_PATH=/usr/local/opt/openssl/lib:$DYLD_LIBRARY_PATH

修复步骤: 1. 卸载 Openssl 并用 Brew 重新安装并卸载 Cryptography

brew uninstall openssl
brew install openssl 
pip uninstall cryptography
  1. 运行 Brew Doctor && Brew Cleanup 以获取损坏的符号链接和错误目录的列表:
brew doctor
brew cleanup

如果您不使用,请删除任何有权限问题的坏目录:

sudo rm -rf /directory/list/bad/from/brew/doctor/

对我来说,我有一个完整的目录列表,我必须删除这些目录。我将它们保存到一个文件中,然后 运行 针对该文件执行以下操作。我将所有坏目录保存到一个名为 doctor.log 的文件中,然后递归地将它们从我的系统中删除。

for i in $(cat doctor.log); do sudo rm -rf $i; done

之后,我处理了系统上所有错误的符号链接。 Link 从以下内容中识别出所有错误的符号链接:

brew doctor check_for_bad_python_symlink
brew doctor check_for_broken_symlinks

修复它们:

brew link --overwrite <package>

之后,您应该可以使用 pip3 和 运行 未标记为 python3 可执行脚本的脚本进行安装。这解决了我的问题,现在我可以 运行 使用 python3 了。此外,找出这一点的一个好方法是通过指定 python 和 python3 并以交互方式使用模块来使用以下内容。出于某种奇怪的原因,2020 年及以下版本的 MacBook 附带 Python2.7(已知问题)。唯一的解决方法是指定路径 and/or 仅使用 python 作为别名。