Skip to content

Instantly share code, notes, and snippets.

@MuhsinFatih
Last active April 18, 2024 08:10
Show Gist options
  • Save MuhsinFatih/ee0154199803babb449b5bb98d3475f7 to your computer and use it in GitHub Desktop.
Save MuhsinFatih/ee0154199803babb449b5bb98d3475f7 to your computer and use it in GitHub Desktop.
How to recover from messed up python installation on mac, and never have to mess with apple's shitty python confusion factory

I am assuming you are here because like me, you installed a bazillion different python interpreters on mac and the whole thing is a spagetti. Today, I finally fixed my python installation. Whatever I install for python2 or python3 using pip JUST.WORKS.. My god! finally.

What the hell?

Here is what I had messed up, which you also probably did:

  • I had too many different python interpreters
  • Too many different symlinks which I lost track of
  • almost no package I installed with pip worked without a headache
  • any attempt to fix using online resources made it worse.

Let's set things right

  • First, remove all the python packages you installed. I am not sure if this is really necessary, but I did it just so I get a fresh start
pip uninstall -y -r <(pip freeze)

(source: https://stackoverflow.com/a/49200334/2770195)

  • Also remove pip cache because why not:
~/Library/Caches/pip
  • Now remove pip
pip uninstall pip
  • Remove all the third party python installations: Careful! Don't delete anything under the /System/ folder. Otherwise you WILL have to reinstall macos, it WILL crash, don't do it.
sudo rm -rf /Library/Frameworks/Python.framework
sudo rm -rf "/Applications/Python 2.7"
cd /usr/local/bin/
ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7' | awk '{print $9}' | tr -d @ | xargs rm

(source: https://stackoverflow.com/a/3819829/2770195 but I changed it a bit to remove python3 too)

  • Remove python path stuff
    Edit whatever shell profile you have, like .bash_profile or .zshrc and .zprofile or whichever shell you are using (If you don't know what I'm talking about then it's .bash_profile):
    Delete all lines that have Python.framework in it. In other words, delete old paths related to python.
nano .bash_profile

(source: https://stackoverflow.com/a/3819829/2770195 again)

  • If you have anaconda installed, get rid of that too:
rm -rf ~/anaconda*

(source: https://docs.anaconda.com/anaconda/install/uninstall/)

So far all this was standard. What's important is how you install the new version. Here's the fun part: if you already messed up your python environment, then there is a good chance you messed up permissions with some packages too. Thus any attempt to install new python versions will seem to work fine for now, but will be a brat later on. That's why the next step is so important:

  • Fix old package permissions:
sudo chown -R $USER /usr/local/bin/*

Basically, everything in this folder is supposed to NOT require root priviliges, which if they do they give pip a hard time later on. That's why we made everything belong to us

Let's install the one and only python2 we will use!:

(don't worry we will get to python3 as well)
Now that you fixed the permissions, you can go ahead and install a python2 interpreter that will NOT ever require sudo with pip and hence will install your packages just fine: Here is the trick: We are NOT using easy_install. Got it? No easy_install. It's the devil. brew is love, use brew:

  • If you don't have brew installed (firstly you should be ashamed of yourself):
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Go to your .profile file again

nano .bash_profile

and add these lines:

⚠ (If you're using macos on arm, add these two lines instead):

export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
export PATH="/opt/homebrew/opt/python@2/libexec/bin:$PATH"
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
export PATH="/usr/local/opt/python@2/libexec/bin:$PATH"

[UPDATE: crossed python2 installation as it is no longer relevant]
now install python2 using brew: brew install python@2 (this will also install pip)
(source: https://docs.python-guide.org/starting/install/osx/)

Install python3

brew install python

(this installs latests python, which is right now python3. Also installs pip)

Ok, if you haven't screwed up anything so far, you should be able to use pip with a peace of mind. I just tried a bunch of packages like numpy and plotly they all worked right away

Golden rule

If you want to maintain the serenity that you have just gained, you have to remember one rule: Never ever use sudo pip install. sudo is the biggest source of confusion with python packages as it screws up the permissions. This is not only true for python, but also nodejs for example, and other environments. There are a lot of posts online that use sudo pip to install packages in their instructions. Always omit the sudo part of that instruction. If you ever accidentally use sudo pip, come back here and apply the steps related to permissions again

gg wp. Now do me a favor and end aging before I die. Just saying. Have fun.

@tcabeen
Copy link

tcabeen commented Apr 10, 2021

Joke's on you. I screwed up my system so bad, pip doesn't work, only pip3.

...wait, that means the joke's actually on me. Aw dang.

@Ndawakh
Copy link

Ndawakh commented Apr 26, 2021

even pip does not work for me, how can I fix that?

@loisgh
Copy link

loisgh commented Apr 27, 2021 via email

@Ndawakh
Copy link

Ndawakh commented Apr 28, 2021

Can you be more specific about what "not working" means? Do you get a command not found error? If so, just add pip to your path. If you are not sure of the path, do which pip in a terminal. BTW this assumes you are on mac or linux. One little tip to note. If you are on a mac and you are installing via homebrew, your python version will be included in the name. For example, I'm using python3.9. When I go to install, I use the command. "pip3.9 install ..." I hope this helps. Lois

-----------------------------------------From: "Ndawakh" To: "MuhsinFatih" Cc: "Lois", "Mention" Sent: Monday April 26 2021 2:02:17PM Subject: Re: MuhsinFatih/pythondoneright.md @Ndawakh commented on this gist. ------------------------- even pip does not work for me, how can I fix that? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub [1], or unsubscribe [2]. Links: ------ [1] https://gist.github.com/ee0154199803babb449b5bb98d3475f7#gistcomment-3720519 [2] https://github.com/notifications/unsubscribe-auth/AAJAFOU3WQFYDETMT4K7XATTKWTCPANCNFSM4NGYFMTA

I have Ubuntu
I tried using the first command "pip uninstall -y -r <(pip freeze)" but I kept getting
Command 'pip' not found, but there are 18 similar ones.
so I changed "pip" to "pip3" and now I get a different type of error
Command 'pip' not found, but there are 18 similar ones. ERROR: You must give at least one requirement to uninstall (see "pip help uninstall")

@MuhsinFatih
Copy link
Author

@Ndawakh can you do this:

What's the output of the following?:

which python
which python2
which python3
which pip
which pip2
which pip3

pip2 -V
pip3 -V

@Ndawakh
Copy link

Ndawakh commented May 5, 2021

I tried ech one of them, some did not give any output (which pip, which pip2, which pip3)

/usr/bin/python
$ which python2
/usr/bin/python2
$ which python3
/usr/bin/python3
$ which pip
$ which pip2
$ which pip3
/usr/bin/pip3
$ pip2 -V

Command 'pip2' not found, did you mean:

  command 'nip2' from deb nip2 (8.7.0-1)
  command 'pip3' from deb python3-pip (20.0.2-5ubuntu1.3)
  command 'pipx' from deb pipx (0.12.3.1-2ubuntu1)

Try: sudo apt install <deb name>

$ pip3 -V
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)```

@amurfey
Copy link

amurfey commented May 5, 2021

Thanks! This was helpful advice to get my environment cleaned up and working again!

@MuhsinFatih
Copy link
Author

Thanks! This was helpful advice to get my environment cleaned up and working again!

Awesome! Glad to hear!

@MuhsinFatih
Copy link
Author

MuhsinFatih commented May 5, 2021

I tried ech one of them, some did not give any output (which pip, which pip2, which pip3)

/usr/bin/python
$ which python2
/usr/bin/python2
$ which python3
/usr/bin/python3
$ which pip
$ which pip2
$ which pip3
/usr/bin/pip3
$ pip2 -V

Command 'pip2' not found, did you mean:

  command 'nip2' from deb nip2 (8.7.0-1)
  command 'pip3' from deb python3-pip (20.0.2-5ubuntu1.3)
  command 'pipx' from deb pipx (0.12.3.1-2ubuntu1)

Try: sudo apt install <deb name>

$ pip3 -V
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)```

Oh no, looks like you're on a linux machine. Sorry I missed that detail earlier. You're following the wrong guide, this is for macos. For linux I would suggest deleting all python installations (google it) and simply installing via apt install or by installing miniconda. But before you install anything new, I would strongly suggest that you make sure you deleted all python related things (all those which commands and stuff I posted should return nothing or did you mean questions). Things are a lot easier on linux side though so you should be good

@andymeadows
Copy link

If you're still trying to install python 2.7 from brew, you MAY want to add these instructions: https://stackoverflow.com/a/63725223

@Maxhirez
Copy link

Just an added note-don't get suckered into using MaxTotalSecurity. I ran a scan today and it marked a bunch of modules I'd been working with as late as this morning as "unsigned" and broke days of work. I'm hoping a Time Machine backup will set things right but I don't know what else it broke.
Screen Shot 2021-06-09 at 7 41 17 PM

@Tarek-Bohdima
Copy link

Tarek-Bohdima commented Jun 11, 2021

messed up pip for python 2.7.16 and upgraded it to pip v 21.1.2

Specs:

macOs BigSur

Iterm2 with ohmyzsh

preinstalled with python2.7.16 & python 3.9.5

Problem :

i upgraded pip without pyenv , so now both pip and pip3 refer to python 3.9.5

i made an alias for python 3.9.5 to be default in .zshrc file

i also used pip to install flask

Questions :

Do i donwgrade pip for python2.7.16?

Or re install python2.7.16 with its pip?

i know i must have used pyenv but; is it possible now ? after 2 versions already installed?

➜  ~ pyenv versions
* system (set by /Users/johnDoe/.pyenv/version)
➜  ~ python2 --version
Python 2.7.16
➜  ~ python3 --version
Python 3.9.5
➜  ~ pip --version
pip 21.1.2 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
➜  ~ pip3 --version
pip 21.1.2 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
➜  ~ pip freeze
click==8.0.1
Flask==2.0.1
itsdangerous==2.0.1
Jinja2==3.0.1
MarkupSafe==2.0.1
Werkzeug==2.0.1

➜  ~ where python
python: aliased to /usr/local/bin/python3
/usr/bin/python
➜  ~ where python3
/usr/local/bin/python3
/usr/local/bin/python3
/usr/bin/python3
➜  ~ where pip
pip: aliased to /usr/local/bin/pip3
/usr/local/bin/pip
/usr/local/bin/pip
➜  ~ where pip3
/usr/local/bin/pip3
/usr/local/bin/pip3
/usr/bin/pip3
➜  ~ which pip
pip: aliased to /usr/local/bin/pip3
➜  ~ which pip3
/usr/local/bin/pip3
➜  ~ which python
python: aliased to /usr/local/bin/python3
➜  ~ which python3
/usr/local/bin/python3
➜  ~ which python2
/usr/bin/python2
➜  ~ where flask
/usr/local/bin/flask
/usr/local/bin/flask
➜  ~ which flask
/usr/local/bin/flask
➜  ~ python2 -m pip list
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named pip
➜  ~ python2 pip --version
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'pip': [Errno 2] No such file or directory
➜  ~ python2 -m pip install "pip<21.0"
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named pip

@MuhsinFatih
Copy link
Author

@tariqywsf having multiple versions is fine. The 'preinstalled' python2 you mentioned seems to be the system installation. I wouldn't touch that at all. If you installed a package, that's fine too. I wrote this post a while ago when python2 was still relevant and at this point noone cares about python2 so it's not even going to affect you. Just make sure to not use sudo pip install ... ever. Sudo with pip is the biggest source of confusion as it screws up the permissions. I noticed now that I hadn't made that clear in the post. I'm updating it now

@Tarek-Bohdima
Copy link

duely noted , and appreciate your answer, i got my answer , Thanks alot

@apb514
Copy link

apb514 commented Aug 17, 2021

I had the wrong interpreter selected in Pycharm and accidentally installed a bunch of packages into my system folder as well @LosiGH. Would somebody with a clean install of a Mac system python be able to share what comes installed by the system? Perhaps we can pip uninstall everything not on that list?

@MuhsinFatih
Copy link
Author

@apb514 only the files under /System are dependencies for macos. You should be fine deleting anything else related to python. It can only break your own environments, but if you're after a clean start you need to do that anyway.

Also since writing this gist a lot has changed. Python2 is no longer relevant, and also I'm strongly convinced that miniconda is the way to go since it can compile c++ dependencies automatically and allows you to manage multiple python versions very easily, and more importantly to me it has better dependency management (conda export is 1000x better than pip freeze). Installing and using miniconda is pretty straightforward, but I can modify the last part of the gist to reflect that. Let me know how that sounds

@nathansmithbz
Copy link

nathansmithbz commented Dec 13, 2021

Stumbled across this when looking for ways to get a fresh start with my Python env! I've dipped in and out a few times, probably changed path variables, used different installation methods including homebrew installed conda etc and almost definitely used sudo when I shouldn't have. I am desperately looking for a way to just wipe everything clean and start again! Even that is proving to be difficult.

If i try

pip uninstall -y -r <(pip freeze)

I get the following:

➜  ~ pip uninstall -y -r <(pip freeze)
Uninstalling pyobjc-framework-AppleScriptObjC-2.5.1:
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip/_internal/cli/base_command.py", line 143, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip/_internal/commands/uninstall.py", line 75, in run
    auto_confirm=options.yes, verbose=self.verbosity > 0,
  File "/Library/Python/2.7/site-packages/pip/_internal/req/req_install.py", line 683, in uninstall
    uninstalled_pathset.remove(auto_confirm, verbose)
  File "/Library/Python/2.7/site-packages/pip/_internal/req/req_uninstall.py", line 224, in remove
    renames(path, new_path)
  File "/Library/Python/2.7/site-packages/pip/_internal/utils/misc.py", line 280, in renames
    shutil.move(old, new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 322, in move
    copytree(src, real_dst, symlinks=True)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 231, in copytree
    raise Error, errors
Error: [('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC/_metadata.pyc', '/private/var/folders/3m/n5hb9vv96nz0qw_91kyndjww0000gn/T/pip-uninstall-MZTpjX/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC/_metadata.pyc', "[Errno 1] Operation not permitted: '/private/var/folders/3m/n5hb9vv96nz0qw_91kyndjww0000gn/T/pip-uninstall-MZTpjX/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC/_metadata.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC/_metadata.py', '/private/var/folders/3m/n5hb9vv96nz0qw_91kyndjww0000gn/T/pip-uninstall-MZTpjX/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC/_metadata.py', "[Errno 1] Operation not permitted: '/private/var/folders/3m/n5hb9vv96nz0qw_91kyndjww0000gn/T/pip-uninstall-MZTpjX/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC/_metadata.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC/__init__.py', '/private/var/folders/3m/n5hb9vv96nz0qw_91kyndjww0000gn/T/pip-uninstall-MZTpjX/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC/__init__.py', "[Errno 1] Operation not permitted: '/private/var/folders/3m/n5hb9vv96nz0qw_91kyndjww0000gn/T/pip-uninstall-MZTpjX/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC/__init__.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC/__init__.pyc', '/private/var/folders/3m/n5hb9vv96nz0qw_91kyndjww0000gn/T/pip-uninstall-MZTpjX/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC/__init__.pyc', "[Errno 1] Operation not permitted: '/private/var/folders/3m/n5hb9vv96nz0qw_91kyndjww0000gn/T/pip-uninstall-MZTpjX/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC/__init__.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC', '/private/var/folders/3m/n5hb9vv96nz0qw_91kyndjww0000gn/T/pip-uninstall-MZTpjX/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC', "[Errno 1] Operation not permitted: '/private/var/folders/3m/n5hb9vv96nz0qw_91kyndjww0000gn/T/pip-uninstall-MZTpjX/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/AppleScriptObjC'")]
➜  ~ 
➜  ~ which python
which python2
which python3
which pip
which pip2
which pip3


pip -V
pip2 -V
pip3 -V
/usr/bin/python
/usr/bin/python2
/usr/local/bin/python3
/usr/local/bin/pip
/usr/local/bin/pip2
/usr/local/bin/pip3
pip 18.1 from /Library/Python/2.7/site-packages/pip (python 2.7)
pip 18.1 from /Library/Python/2.7/site-packages/pip (python 2.7)
pip 21.3.1 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
➜  ~ 

Any ideas where to go from here?

@arosielle
Copy link

arosielle commented Feb 28, 2022

After a day of frustration, most of what you listed worked. There was one failure (can't remember) which I ignored and carried on. Yay. You rock!

@aceabhinavam
Copy link

aceabhinavam commented Mar 21, 2022

I am on the same boat, want to clean my mac of all the useless pieces I installed. I am following your guide and while trying to run the following command -
ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7' | awk '{print $9}' | tr -d @ | xargs rm
I get this error

rm: 2to3: Permission denied
rm: 2to3-2: Permission denied
rm: 2to3-2.7: Permission denied
rm: easy_install: Permission denied
rm: easy_install-2.7: Permission denied
rm: idle: Permission denied

appreciate any help here!

@jahmal21000
Copy link

I have also trouble installing phyton 2.7 on Monterey 12.3 to the path /System/Library/Frameworks/Python.framework/Versions/2.7/Python

@MuhsinFatih
Copy link
Author

Any ideas where to go from here?

@nathansmithbz You should be fine skipping the pip uninstall since we're manually deleting everything that's python-related later in the other steps. My approach was to nuke everything using every possible option I can quickly think of. Probably 30-50% of the steps are redundant but harms not.

After a day of frustration, most of what you listed worked. There was one failure (can't remember) which I ignored and carried on. Yay. You rock!

@arosielle Thanks! Just like my answer right above, some of the steps are actually redundant so ignoring errors should be fine in most cases

I am on the same boat, want to clean my mac of all the useless pieces I installed. I am following your guide and while trying to run the following command - I get this error

@aceabhinavam Try sudo xargs rm at the end of that command. Or xargs sudo rm? I don't really know. One of these should work

@svahora
Copy link

svahora commented May 6, 2022

I'm trying to fix my install as well. Most of the time when I'm using VS Code to install packages it gives me an error and I end up spending hours trying to fix it all just to install a simple python library. Afterwards I usually give up :(
The following is what I have for those queries requested to others:

SV$ which python
/usr/bin/python
SV$ which python2
/usr/bin/python2
SV$ which python3
/usr/bin/python3
SV$ which pip
/usr/local/bin/pip
SV$ which pip2
/
SV$ which pip3
/usr/bin/pip3
SV$ pip2 -V
-bash: pip2: command not found
SV$ pip3 -V
pip 19.0.3 from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)
SV$ pip -V
-bash: /usr/local/bin/pip: /usr/local/opt/python/bin/python3.7: bad interpreter: No such file or directory

@AllPinkyNoBrain
Copy link

thankyou thankyou thankyou thankyou !!!

I was going mad with all this (and I'd stupidly thrown in an upgrade to Monterey in the midst of my madness). This has made my day!
:-)

@crukundo
Copy link

Just incase anyone finds this in 2022, and can't install python2 with homebrew, some of the threads here (https://stackoverflow.com/questions/60298514/how-to-reinstall-python2-from-homebrew) might help. I used pyenv and reinstalled pip independently on python2 and 3

@Tyler-Pickett
Copy link

After running pip uninstall -y -r <(pip freeze)

I get this error code, everything up to gets deleted. PermissionError: [Errno 13] Permission denied: '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/site-packages/__pycache__/six.cpython-37.pyc'

Even though I am admin, I come up as staff when I run ls -la

@dasheck0
Copy link

dasheck0 commented Oct 3, 2022

Thought my system was beyond repair. This actually fixed it. Thank you so much!

@gpmilliken
Copy link

Thanks - got some traceback errors along the way but this worked and the madness of installed modules not being found has stopped.

Thank you.

@cwilby
Copy link

cwilby commented Nov 21, 2022

Some considerations for macOS on ARM:

and add these lines:

export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
export PATH="/usr/local/opt/python@2/libexec/bin:$PATH"

translates as

and add these lines:

export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
export PATH="/opt/homebrew/opt/python@2/libexec/bin:$PATH"

@MuhsinFatih
Copy link
Author

Thanks @cwilby, I just checked and the path is as you said on my mac (arm). Updated the gist

@armouti
Copy link

armouti commented Jan 23, 2023

this is outdated
brew install python@2 will return
Error: No available formula with the name "python@2"
because it has been removed by homebrew Homebrew/homebrew-core#49796

@MuhsinFatih
Copy link
Author

this is outdated brew install python@2 will return Error: No available formula with the name "python@2" because it has been removed by homebrew Homebrew/homebrew-core#49796

@armouti replace that with just python and you should be good. Noone uses python2 anymore

@yin-ori
Copy link

yin-ori commented Feb 10, 2023

I installed pyenv virtualvenv after I had to completely resetup my setup. which pip/pip3/python/python3 all direct to the correct environment path, though, once I try to install packages it will still create packages in a path of homebrew library for python3.10 (which I don't even have anymore) - I am not sure if its something wrong along with my .zshcr zprofile bash or something else and cannot find anything that works for me on the internet either. $PATH will give me
zsh: no such file or directory: /Users/MYUSERNAME/.pyenv/shims:/Users/MYUSERNAME/.pyenv/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/go/bin:/Library/Apple/usr/bin

see also this: python packages installed to wrong path

btw even if I delete the folder it will recreate itself upon installation :(

@UncleBob2
Copy link

Thank you so much for sharing your knowledge. I had lot of issues with "pip install TTS" and was getting lots of warnings

WARNING: Skipping /usr/local/lib/python3.11/site-packages/PyYAML-6.0-py3.11.egg-info due to invalid metadata entry 'name'
WARNING: Skipping /usr/local/lib/python3.11/site-packages/numpy-1.24.2-py3.11.egg-info due to invalid metadata entry 'name'
WARNING: Skipping /usr/local/lib/python3.11/site-packages/PyYAML-6.0-py3.11.egg-info due to invalid metadata entry 'name'
WARNING: Skipping /usr/local/lib/python3.11/site-packages/numpy-1.24.2-py3.11.egg-info due to invalid metadata entry 'name'
WARNING: Skipping /usr/local/lib/python3.11/site-packages/PyYAML-6.0-py3.11.egg-info due to invalid metadata entry 'name'
WARNING: Skipping /usr/local/lib/python3.11/site-packages/numpy-1.24.2-py3.11.egg-info due to invalid metadata entry 'name'"
WARNING: Skipping /usr/local/lib/python3.11/site-packages/PyYAML-6.0-py3.11.egg-info due to invalid metadata entry 'name'
WARNING: Skipping /usr/local/lib/python3.11/site-packages/numpy-1.24.2-py3.11.egg-info due to invalid metadata entry 'name'
WARNING: Skipping /usr/local/lib/python3.11/site-packages/PyYAML-6.0-py3.11.egg-info due to invalid metadata entry 'name'
WARNING: Skipping /usr/local/lib/python3.11/site-packages/PyYAML-6.0-py3.11.egg-info due to invalid metadata entry 'name'

Everything seems to be working now. Many thanks

@MaxistheSpy
Copy link

this is outdated brew install python@2 will return Error: No available formula with the name "python@2" because it has been removed by homebrew Homebrew/homebrew-core#49796

@armouti replace that with just python and you should be good. Noone uses python2 anymore

any chance you could update the gude then, since homebrew doesnt even support this installation its confusing

@MuhsinFatih
Copy link
Author

this is outdated brew install python@2 will return Error: No available formula with the name "python@2" because it has been removed by homebrew Homebrew/homebrew-core#49796

@armouti replace that with just python and you should be good. Noone uses python2 anymore

any chance you could update the gude then, since homebrew doesnt even support this installation its confusing

done.

@dwqualia
Copy link

I followed this exactly on Ventura 13.3 but I keep getting this error?

WARNING: Skipping /usr/local/lib/python3.11/site-packages/PyYAML-6.0-py3.11.egg-info due to invalid metadata entry 'name'

How can I fix this?

@brownj47
Copy link

I am having the same issue as @dwqualia. Could it be an issue with the PyYAML-6.0 package?

@MuhsinFatih
Copy link
Author

@brownj47 @dwqualia probably an issue with pyyaml. you can install a different version of python. 3.11 is the latest python so some packages might be unstable.

brew install python@3.10

@Drjacky
Copy link

Drjacky commented Jun 4, 2023

@brownj47 @dwqualia probably an issue with pyyaml. you can install a different version of python. 3.11 is the latest python so some packages might be unstable.

brew install python@3.10

I'm on the latest 3.11.3 and still have the issue.

@alessandraluz
Copy link

Oh. my. god. thank you for avoiding my impending life ending, by helping me with this incredible step by step!!!

@victorazzam
Copy link

To fix the PyYAML issue:

  1. Uninstall it with pythonXXX -m pip uninstall -y pyyaml
  2. Erase its path with rm -r /opt/homebrew/lib/pythonXXX/site-packages/PyYAML*

For both commands, replace XXX with the correct Python version for which the problem occurs.

@MichaelDerrenbacher
Copy link

Thank you for this! I had a patchwork python env, and this helped me get everything freshly installed

@gumbolastima
Copy link

I had a problem following these instructions, where removing the frameworks gave lots of "permission denied" errors. To solve it, I changed the command

ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7' | awk '{print $9}' | tr -d @ | xargs rm

to

sudo sh -c "ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7' | awk '{print \$9}' | tr -d @ | xargs rm"

@rudraksh97
Copy link

This thread saved me. I had to complete a python assignment for an interview and libraries weren't just installing. Big thanks!!

@mshonichev
Copy link

mshonichev commented Feb 8, 2024

I'm not sure how I got here, but this is huge!

gg indeed!

@drumstick90
Copy link

Thank you so much!
I also think installing packages by VSC isn't a good idea, I'd rather stick to pip install

@jdbohrman
Copy link

You are a fucking champ.

@franco-stuart
Copy link

With pip freeze, I get this error:

Traceback (most recent call last):
  File "/opt/homebrew/bin/pip", line 5, in <module>
    from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'

@FetchFast
Copy link

Shouldn't containers make all of this unnecessary?

@Awesomeguys900
Copy link

I actually love you so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment