Khurram Majeed
Khurram Majeed

Reputation: 2391

Installing python 3 on Mac

I had to install python 3.4.1 on my Mac OS 10.9.4 but it doesn't get picked up. First I installed Anaconda python distribution and when I check conda It shows that I have python 3.4.1 installed on my macbook

 khurramsmacbook:~ kmajeed$ conda info 

   Current conda install:

             platform : osx-64
        conda version : 3.5.5
       python version : 3.4.1.final.0
     root environment : /Users/kmajeed/anaconda  (writable)
  default environment : /Users/kmajeed/anaconda
     envs directories : /Users/kmajeed/anaconda/envs
        package cache : /Users/kmajeed/anaconda/pkgs
         channel URLs : http://repo.continuum.io/pkgs/free/osx-64/
                        http://repo.continuum.io/pkgs/pro/osx-64/
          config file : None
    is foreign system : False

But running following commands in terminal shows that I have python 2.7.5 installed

khurramsmacbook:~ kmajeed$ which python
/usr/bin/python
khurramsmacbook:~ kmajeed$ python --version
Python 2.7.5
khurramsmacbook:~ kmajeed$ 

I have also set up my $PATH variable using .bash_profile

khurramsmacbook:~ kmajeed$ $PATH
-bash: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/Users/kmajeed/anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin: No such file or directory

How do I fix this issue?

Upvotes: 0

Views: 13595

Answers (4)

asmeurer
asmeurer

Reputation: 91450

You have Anaconda on your PATH, but it's not first, so the system Python in /usr/bin gets picked up first. Edit your ~/.profile with something like what MattDMo suggested.

Upvotes: 1

Roland Smith
Roland Smith

Reputation: 43495

Python 2.7.5 is probably the one that comes pre-installed with OS X.

What you can do is invoke programs with python3.4 instead of python. In scripts use this as the first line;

#!/usr/bin/env python3.4

In a shell (for scripts without the executable bit set and without the shebang-line above) use;

python3.4 <scriptname>

The python in /usr/bin might be a symbolic link to python2.7. And you could replace that with a symbolic link to python3.4. But I would not recommend that because it will break existing programs that were written for Python 2.7 because of the incompatibilities between Python2 and Python 3.

Upvotes: 5

rady
rady

Reputation: 428

Python 3.3 interpreter should be in the same Directory as python. You just have to A) Change the symbolic link (Not the best choice). B) make a new link that points to python 3 or C) you can use IDLE. IDLE is an ok IDE with a CMD line interface. But its nice because all you have to do is run IDLE and not have to make links or anything. IDLE is also supported by Python as well. The Link for download is here: https://www.python.org/download/

Upvotes: 0

MattDMo
MattDMo

Reputation: 102842

If you want to run Python 3.4.1 when you enter python in Terminal, the following line should be in your .bash_profile:

export PATH=$HOME/anaconda/bin:$PATH

The shell searches your PATH in order, so with your current setting it's still looking in /usr/bin first. With the new setting, it will look in /Users/kmajeed/anaconda/bin first.

Upvotes: 1

Related Questions