[Python] How to correctly install and set up path configurations for python and pip?

Discussão em 'Python' iniciado por Stack, Abril 12, 2025.

  1. Stack

    Stack Membro Participativo

    I have multiple versions of python and pip installed. Using python3 in the terminal runs python 3.9.6, whereas pip runs python 3.12.9; so, I can use pip3 to install a package (for example, newtworkx), but running a python script will show an error message stating that the (networkx) package could not be imported. Below are some details.

    The contents of my .bashrc:

    export PATH="/Library/Frameworks/Python.framework/Versions:$PATH"

    The contents of my .bash_profile are empty.

    The contents of my .zprofile:

    # Setting PATH for Python 3.9 # The original version is saved in .zprofile.pysave PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}" export PATH

    The contents of my .zshrc:

    export PATH="/Library/Frameworks/Python.framework/Versions:$PATH"

    These are the specs for the python3 and pip3 via terminal (alias?):

    $ python3 --version Python 3.9.6

    $ which python3 /usr/local/bin/python3

    $ pip3 --version pip 24.3.1 from /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pip (python 3.12)

    $ which pip3 /usr/local/bin/pip3

    $ cd /usr/local/bin $ ls 2to3 pydoc3.12 python3.13-intel64 2to3-3.12 pydoc3.13 python3.13t 2to3-3.9 pydoc3.9 python3.13t-config idle3 python3 python3.13t-intel64 idle3.12 python3-config python3.9 idle3.13 python3-intel64 python3.9-config idle3.9 python3.12 python3.9-intel64 pip3 python3.12-config python3t pip3.12 python3.12-intel64 python3t-config pip3.13 python3.13 python3t-intel64 pydoc3 python3.13-config

    $ cd /Library/Frameworks/Python.framework/Versions/ Owners-MacBook-Pro:Versions owner$ ls 3.12 3.13 3.9 Current

    In case it matters, I prefer the bash shell to the z shell as my default. I on running on Mac Sequoia 15.3.2. I can think of a couple possible ways to fix this, but am not sure about them; these are below:

    Possible solutions:

    1. Is there a way to edit the contents of my .bashrc and/or .bash_profile (and/or .zprofile and/or .zshrc) such that pip3 will point to the correct version as determined by the pointer of python3?
    2. Delete all python3 installations (except for the default version that comes with the laptop), and install different versions of python in different virtual environments venv. But isn't pip outside of the virtual environment that contains different python environments? How would I install this properly?

    Small Note: I realize it is not good practice to install multiple versions of python globally on the system. I had downloaded different versions of python as pkg files from the official website so that I could test them to ensure compatibility between different packages once python and pip were properly configured, but I did not open and install python from the pkg files. I paid a local IT place to install python correctly on my machine - with path configurations and profile edits - with the expectation that they would pick one version of python and that I could later test different versions; these were all installed globally when I picked my laptop up.

    Continue reading...

Compartilhe esta Página