简体   繁体   中英

Python Installation is Broken on Macbook

So I think my Python Framework is completely broken. I know this because my scripts work on a Windows 10 Machine without any issue, and when I try to check the version of python with which python I get a bad option message. When I try to run any python scripts I get this:

 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)

Furthermore, I recently tried uninstalling and re-installing with brew, whereas before it was working but I was unable to install the fire module through pip. The fix was to uninstall it, and now...I think I have broken the framework just to install one module. My macbook is almost completely useless right now for local pythonic development and it is hindering my workflows.

Okay so since someone down-voted it and didn't provide an explanation I am going to be as verbose as possible.

On my Macbook I try to run a python script that works with my Windows Machine:

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]

Which is nice and what I would expect to see as well on my Macbook. However, for some odd reason my Python is not working and it is pointing to an older version on the macbook. I try to run the same script and I get the following:

 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

When I looked up the error it was saying I was running an old version of Python. I reinstalled it via brew, before all of the patch to to work with the python fire module...I had no issues and could run my scripts just fine from within the CLI.

Also, here is the python crash anytime I try to install something with 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

Though I have always had that issue from before, when I would try to invoke a script that was not marked as executable with python3 some_script_needing_version_3.py .

So yeah it was a broken Python Framework. I understand why people have downvoted it because it is basically saying that I don't have the modules installed. However, I had them installed with Version Python 2.7, which is what a Macbook is shipped with. Every time I would install it with pip it would say requirements already met. However, the apps I am using run on python3.7, and as such yes...I did not have the modules installed for Python3.7. However, every time I would run pip3 or python3 python would crash.

I used Brew to help manage some things. I had to one clean up some stuff running brew doctor and brew cleanup. Then I had to fix all of the broken symlinks on my macbook and delete some Libraries that were broken, that were not allowing me to run pip3 or python3 respectively. Furthermore, I had to uninstall openssl via brew and also uninstall cryptography in python, thereby adding the following line to my .zshrc profile.

Add this into your Shell Profile: export DYLD_LIBRARY_PATH=/usr/local/opt/openssl/lib:$DYLD_LIBRARY_PATH

Steps to Fix: 1. Uninstall Openssl and Reinstall it with Brew and Uninstall Cryptography

brew uninstall openssl
brew install openssl 
pip uninstall cryptography
  1. Run Brew Doctor && Brew Cleanup to get a list of broken symlinks and bad directories:
brew doctor
brew cleanup

Delete any bad directories with permission issues if you are not using:

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

For me, I had a whole list of directories that were bad that I had to remove. I saved them to a file and ran the following against that file. I saved all of the bad directories to a file called doctor.log and then recursively deleted them from my system.

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

Afterward, I dealt with all of my bad symlinks on the system. Link any and all bad symlinks after identifying them from the following:

brew doctor check_for_bad_python_symlink
brew doctor check_for_broken_symlinks

Fix them with:

brew link --overwrite <package>

Afterward you should be able to install things with pip3 and run scripts not marked as executable with python3 . This fixed my issue and now I can run things with python3. Furthermore, a good way to find this out is to use the following by specifying python and python3 and working with the modules interactively. For some odd reason MacBooks 2020 and less ship with Python2.7 (Known Issue). The only fix is to specify the paths and/or just work with python as an alias.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM