1

I was installing, uninstalling and reinstalling pythons on my mac, and I think things are screwed up a little.

At first by default, terminal ran Python 3.5 when I typed

$python

, but after doing some things, it installed 2.7 and now the terminal runs python 2.7 instead of 3.5

I installed python 3.5 form http://python.org/.

When I open up bash_profile

$vim ~/.bash_profile

This is what shows up

# virtualenv
export WORKON_HOME=~/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh


# Setting PATH for Python 3.5
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH

Now when I type:

$ python

This shows up:

Python 2.7.11 (default, Jun 23 2016, 17:25:20) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

How can I reset all the python stuff(remove older versions, etc) to the factory version that i had when I first bought Mac(python3.5)?

3
  • What's the value of $PATH Commented Jun 23, 2016 at 8:50
  • Are you getting this within a virtualenv? Commented Jun 23, 2016 at 8:52
  • Personally I created a symbolic link in /usr/bin called python3 which points to the real python 3 binary. I then use the #! line to use python3. You contradict yourself. First you say "I installed python 3.5 form python.org", but at the end you say "the factory version that i had when I first bought Mac(python3.5)". It is more than likely that 2.7 was installed. 3.5 and 2.7 can co-exist quite happily on OS X if you use the symbolic link. Commented Jun 23, 2016 at 9:02

3 Answers 3

10

This worked for me:

Python 3.x

python3

Python 2.x

python

in terminal

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

Comments

1

To see what command is actually going to run when you type python at the prompt, check the top result of:

type -a python

This will list any aliases as well as taking into account the full PATH definition. To figure out why python 2 is getting precedence over python 3, be sure to check your ~/.bashrc file if it exists as well as your ~/.bash_profile.

Comments

0

To check your Python binaries, run:

$ which -a python python2 python3

Then check which python path comes first.

Then either set your $PATH or $PYTHONPATH (then reload your shell), or use python2 or python3 command instead.

You can also use following workaround:

PATH="/usr/bin:$PATH" ./python_script.py

where /usr/bin is pointing to the right Python binary.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.