1

I have followed instructions in examples like this, and this.

I have this line in my ~/.bashrc file

export python="/usr/local/bin/python3.6"

This lines in my ~/.bash_aliases file

alias python='/usr/local/bin/python3.6'

This is my PATH variable

/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Wireshark.app/Contents/MacOS

And I still have the following python version and path

User$ which python
/usr/bin/python
User$ python --version
Python 2.7.10

I have also already tried exiting the terminal and reopening

Here is what is within the directories /usr/local/bin/python3.6* and /usr/bin/python*

User$ /usr/local/bin/python3.6
python3.6          python3.6-config   python3.6m-config  
python3.6-32       python3.6m         
User$ /usr/bin/python
python            python2.6-config  pythonw           
python-config     python2.7         pythonw2.6        
python2.6         python2.7-config  pythonw2.7 

Thank-you

Alex
  • 15
  • 6

2 Answers2

1

I think the problem may be, you started a login shell which looks for ~/.bash_profile, and ~/.bash_aliases is not sourced in ~/.bash_profile. So the alias command in ~/.bash_aliases was never executed. You can check this by invoking alias python.

BTW, export a variable named python is pointless in your case since it will never be used.

Apropos which ~/.bash* files is read, you can reference man bash at the INVOCATION chapter. Here is some of them.

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.

alzee
  • 463
  • 2
  • 10
  • Thank-you. That fixed my python version, but not which python my terminal says is being returned. `User$ which python /usr/bin/python User$ python --version Python 3.6.4` – Alex Mar 19 '18 at 03:01
  • `which` only print first match by default, with `-a`, it will print all. In your case, `which -a python` should print 2 matches, the alias and /usr/bin/python. /usr/local/bin/python3.6 won't match because it's filename is `python3.6`, not `python` – alzee Mar 19 '18 at 03:14
0

Copy those into your .bash_profile file, which is what terminal sessions in OS X look for. Also, as others have mentioned, exporting python as an environment variable will not do anything- the alias should be enough.

avigil
  • 2,218
  • 11
  • 18
  • Thank-you. That fixed my python version, but not which python my terminal says is being returned. User$ which python /usr/bin/python User$ python --version Python 3.6.4 – Alex Mar 19 '18 at 02:08