Glam Prestige Journal

Bright entertainment trends with youth appeal.

something very wrong is happening with my environment set up. As I am trying to learn, I decided to reinstall Mac OSX El Capitan on my Macbook Pro and start installing and configuring stuff from scratch. Shell I am using is ZSH and I have configured it a bit with Oh-My-ZShell.

My $PATH and Python:

~ ❯ echo $PATH
/Users/edchigliak/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/edchigliak/bin
~ ❯ python --version
Python 2.7.10
~ ❯

Screenshot below clearly shows that there are two Python2's installed in /usr/bin and a Homebrewed Python3 in /usr/local/bin.

Terminal screenshot of Python2 and Python3 paths

Here is the result of printenv (only entries related to PATH and SHELL):

PATH=/Users/edchigliak/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/edchigliak/bin
PWD=/Users/edchigliak
SHELL=/usr/local/bin/zsh
SHLVL=2
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.lRGo5iu4NA/Listeners
TERM=screen-256color
ZSH=/Users/edchigliak/.oh-my-zsh
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
_=/usr/bin/printenv

First entry in my .zshrc:

export PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/bin 

Many thanks!

5

2 Answers

Only binaries named exactly python will be considered when you type python at the shell prompt.

If you want python to execute python3, the simple way to accomplish that is to set a function or alias in your personal shell startup files.

You absolutely mustn't make python point to python3 system-wide because this will break some OS and third-party tools which require python to be Python version 2. The two are mutually incompatible languages (or dialects, if you prefer).

To review what's happening here, when you type command at the prompt, the shell iterates through the directories in your PATH and looks for an executable file named exactly command in each, until it finds one, or runs out of places to look. It will simply ignore any files with other names, even if they would happen to be similar, like xcommand or commandante or command3.xx. If you have an alias or a function, that will be used instead, though your PATH will perhaps then be consulted to locate other commands called by your alias or function.

2

The shell searches PATH for exact matches. When you type in python, it tries to find an executable matching ^python$; ^python...$ is not the same.

In your case, it could be there is no python in /usr/local/bin or perhaps there's a permissions issue with it, which would make it be skipped.

1) If there is no python in /usr/local/bin:

You could use sudo ln -s /usr/local/bin/python3.6 /usr/local/bin/python to create a soft link python pointing to the Python interpreter you want to use. Because /usr/local/bin is searched first for your PATH, the shell should now find this link.

2) If file exists in /usr/local/bin but doesn't have execute permission, try sudo chmod a+x /usr/local/bin/python.

Can't think of other problems right now.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy