1

i am still new to python and really need some help understanding an issue i am facing.

I have supposedly installed python3 successfully and i have ran a couple of projects with python but my problem is there are 3 different python paths on my machine and i dont know which one i am using.

i first did this: which -a python3

/Library/Frameworks/Python.framework/Versions/3.8/bin/python3

/usr/local/bin/python3

/usr/bin/python3

Then i cd into each one of these files and did this ls -ld python3

lrwxr-xr-x  1 root  admin  9 26 Jan  2020 python3 -> python3.8
lrwxr-xr-x  1 *******  admin  40 24 Mar 09:22 python3 -> ../Cellar/[email protected]/3.9.2_2/bin/python3
-rwxr-xr-x  1 root  wheel  31488 22 Sep  2020 python3

Can someone explain to me what these mean and also why are they not pointing to the same file?

here is my ~/.bash_profile

# Setting PATH for Python 3.8
# The original version is saved in .bash_profile.pysave

alias python=python3

# Add Visual Studio Code (code)
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"

export ANDROID_SDK=/Users/*****/Library/Android/sdk

export PATH=/Users/*******/Library/Android/sdk/platform-tools:$PATH

export WORKON_HOME=$HOME/.virtualenvs

export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3

source /usr/local/bin/virtualenvwrapper.sh

I am using a Mac with macOS Catalina as my operating system and bash as my shell.

8
  • 1
    I think it usually means you have multiple installation of python3 from multiple sources such as from Brew, binary release, etc. and their folder containing their own executable python3 are saved in different locations Commented Mar 29, 2021 at 5:29
  • It's clear from the paths that you are on macOS, but going forward, mentioning your platform and how exactly you installed Python would be good details to include in any question of this type. Commented Mar 29, 2021 at 5:35
  • If you are on Zsh, the contents of your .bash_profile won't matter at all. Perhaps also indicate which shell you are using (echo "$SHELL") Commented Mar 29, 2021 at 5:36
  • @tripleee what do you mean by on Zsh? Commented Mar 29, 2021 at 5:44
  • 1
    @tripleee updated my bash_profile and added my OS and shell inside the quesiton Commented Mar 29, 2021 at 5:51

1 Answer 1

1

You have a system-installed python3 (probably 3.8.2 if you are on Big Sur) in /usr/bin/python3 and a Homebrew-installed one in /usr/local/bin/python3 which is a symlink to the real location where brew installed it. This is all quite normal, though if the system-installed Python 3 was sufficient for your needs, installing another copy with Homebrew was redundant as such. But this is all quite normal; your system needs a particular version to exist, and you should not touch that, but you are free to install a non-system version in parallel and use that for your personal needs if you want to.

You can use the explicit paths to run any particular version (try /usr/bin/python3 --version and /usr/local/bin/python3 --version) but usually you don't want or need to. Out of the box, your PATH is ordered so that /usr/local/bin takes precedence over /usr/bin, so that locally installed versions shadow the system default versions in regular use.

As an aside, you have the Visual Studio Code path added twice, and you don't need to export PATH multiple times (or actually at all, as the system startup files will already have marked this variable for export).

Sign up to request clarification or add additional context in comments.

19 Comments

Hi, thank you for getting back to me. I am actually using macOS Catalina not Big Sur. That is true i have downloaded python a while ago from the python website then i read a couple of comments that suggested i install using brew since when a update occurs brew updates it automatically. when i run /usr/local/bin/python3 --version i get Python 3.9.2 and when i run /usr/bin/python3 --version i get Python 3.7.3. what about this path /Library/Frameworks/Python.framework/Versions/3.8/bin/python3 does it take precendence over the others? also when i get its python version its 3.8.1
I can see no reason to do that.
Whichever makes sense for your use case. For new development targeting new installations of Python, using the newer version makes sense; but if you are developing for a user base or platform where you need to support 3.8, using that makes more sense. If you can't decide one way or the other, probably use the newer version for now, since you are less likely to bump into problems when you find something online and try it out.
Yes, remove that from .bash_profile and at the shell prompt PATH=${PATH#*:} or more verbosely PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Visual Studio Code.app/Contents/Resources/app/bin" (the latter also removes the duplicate from the end of the PATH)
I use different Python versions for different projects. Some stuff I work on needs to be compatible back to 3.6. I use pyenv to keep multiple versions available but don't particularly like its overall model so I create a new local virtualenv manually for each version for each project that needs to be tested on multiple versions.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.