Search code examples
python-3.xxcodemacosterminalpip

How to fix messed up Python3 and pip3 env on Mac


For somehow I fully messed up with my python3.

I'm working on a Mac with Ventura 13.2.1, here is some key APPs path:

type: xcode-select -p -> print: "/Applications/Xcode.app/Contents/Developer"
type: which python -> print: "python not found" -> Looks fine to me since I should only need Python3
type: which python3 -> print: "/usr/bin/python3"
type: which pip3 -> print:"/usr/bin/pip3"

Trying to install numpy with pip3 -> type: pip3 install numpy -> print:

Traceback (most recent call last):
  File "/Applications/Xcode.app/Contents/Developer/usr/bin/pip3", line 5, in <module>
    from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'

Kind of wired since I think I already have lots of python3 packages installed under this path: "/Users/<user_name>/Library/Python/3.9/lib/python/site-packages" -> Because from there I can print stuffs from "numpy", "pandas" and many others -> But if I type: which numpy / numpy --version / which pandas / pandas --version -> It will all print "command not found" related stuff.

Thus I wondering both my python3 and pip3 are installed in all different paths, which is occurs in:

/Applications/Xcode.app/Contents/Developer/usr/bin
or 
/usr/bin
or 
/Users/<user_name>/Library

In this case how I can fully clean my python3 and pip3 and let it be pointed correctly in the Mac system under xcode, or this is something else?

Thanks

All in the descriptions


Solution

  • To use python, you may add a soft link to python3 with link -s /usr/bin/python3 /usr/bin/python.

    The best way is to use pyenv to manage your python environment. https://github.com/pyenv/pyenv . It has the instruction to make the installation simple.

    You can create many python environments such as py37, anaconda, py39, project, test and etc.

    Just use pyenv activate py39 to activate python 3.9 environment which you created.