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)?
This worked for me:
Python 3.x
python3
Python 2.x
python
in terminal
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
.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.