Score:1

Why doesnt creating a sym link from python to python 3 work?

cn flag

My goal is to make sure that python refers to python3 in my mac terminal. What i have tried so far are the following two attempts

1. Adding an alias in .zshrc

alias python=python3

after re sourcing my .zshrc file this allowed me to type python --version and get python3.

This does not work for scripts as they specify #!/usr/bin/env python and completely ignore my aliases.

2. Adding a symlink from /usr/local/bin/python to /usr/bin/python3

This is when it gets weird. Here are the output of a few commands

python --version -> python 2.7

which python -> python /usr/local/bin/python

/usr/local/bin/python --version -> python 2.7

ls -l /usr/local/bin/python -> /usr/local/bin/python -> /usr/bin/python3

/usr/bin/python3 --version -> python 3.8

What is going wrong here? Why is the symlink apparently correct but the wrong version of python is still showing when using it?

I found a similar question on an old apple but the answer doesn't really address the weirdness of the symlink, nor doesnt it solve the problem.

I'd really like to understand why this is happening AND find a solutionn or a proper way to get my main python version to be python 3.

Thanks!

tilleyc avatar
us flag
Is it too impractical to just update your scripts to point to the version you want? For example, change `#!/usr/bin/env python` to `#!/usr/bin/env python3`? Unless you’re sure of everything that makes use of a particular version, changing it by completely disallowing it via soft links or something could have unintended consequences.
Nicola Pedretti avatar
cn flag
I can do that, and that is what i ended up doing. I am still curious about the weirdness with symlinks tho. any ideas ?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.