Reputation: 25099
I wanted to update my python 2.6.1 to 3.x on mac but I was wondering if it's possible to do it using the terminal or I have to download the installer from python website?
I am asking this question because the installer is not updating my terminal python version.
Upvotes: 194
Views: 853752
Reputation: 11612
Install or Update your current Python version to latest on Mac.
/bin/bash -c "$(curl -fsSL
https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
pyenv
- this is a Python version managerbrew install pyenv
pyenv
(if needed) to capture newer Python versionsbrew upgrade pyenv
pyenv install -l
Here's a more helpful version of the above. This lists only the release versions of the specified Python Version. That is, 3.13.*
pylist() {
pyenv install -l | grep '^[ ]*'${1}'.*[0-9]$'
}
Place the above in your ~/.bashrc
, ~/.zshrc
(for zsh), or just paste it in a terminal window. Then use it like pylist <python version>
Example:
❯ pylist 3.13
3.13.0
3.13.0
, or use :latest
for the latest release version.pyenv install 3.13:latest
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init --path)"\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc
pyenv global 3.13.0
pyenv versions
Output:
❯ pyenv versions
system
* 3.13.0 (set by /Users/.../.pyenv/version)
❯ python3 --version
Python 3.13.0
For more info refer
Upvotes: 1
Reputation: 1
The command python3
points to a specific version of python installed. You will need to update the symbolic link of python3
to your desired version
ls -l /usr/local/bin/python*
list all versions of python installedsudo unlink /usr/local/bin/python3
to unlink the current version of python.sudo ln -s /usr/local/bin/python3.10 /usr/local/bin/python3
to change the default python3 to Python 3.10.python --version
pointing to the legacy python because we did not update the symbolic link for it.Upvotes: 0
Reputation: 421
Install or Update your current Python version to latest or any custom version in MAC OS
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
pyenv
this is a python version managerbrew install pyenv
pyenv install -l
pyenv install 3.12.2
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init --path)"\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc
pyenv global 3.12.2
pyenv versions
Output:
❯ pyenv versions
system
* 3.12.2 (set by /Users/oliverpaul/.pyenv/version)
❯ python3 --version
Python 3.12.2
For more info refer
Upvotes: 9
Reputation: 1858
An alternative way to deal with this. This approach allows not just upgrades but downgrades too.
Use asdf
which allows you to have and switch between multiple versions of the same executable.
brew install asdf
asdf plugin add python
asdf install python 3.12.0 (or whichever version you need)
asdf global python 3.12.0
which python
I used this to use a specific version of python with my Pycharm. I recommend checking asdf docs.
Upvotes: 0
Reputation: 5893
For developers who stay away from Homebrew, you can install it via its installer to any location you want.
https://www.python.org/downloads/
Upvotes: 0
Reputation: 6893
Both python 2x and 3x can stay installed in a MAC. Mac comes with python 2x version. To check the default python version in your MAC, open the terminal and type-
python --version
However to check, if you have already installed any of python 3x versions, you need to type
python3 --version
If you don't then go ahead and install it with the installer. Go the the python's official site(https://www.python.org/downloads/), download the latest version
and install it.
Now restart the terminal and check again with both commands-
Upvotes: 114
Reputation: 9
Install Home brew /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Install python 3 brew install python3 && cp /usr/local/bin/python3 /usr/local/bin/python
Update python to latest version ln -s -f /usr/local/bin/python[your-latest-version-just-installed] /usr/local/bin/python
Upvotes: 0
Reputation: 1
Install JDK latest Version
export $JAVA_HOME=/usr
export $PATH=${JAVA_HOME}/bin:$PATH
java --version
sudo apt install python3.9
python3 --version
Upvotes: -11
Reputation: 4497
brew install python
--> install the latest Python.ls -l /usr/local/bin/python*
--> List all Python versions installed on your system.ln -s -f /usr/local/bin/python[your-latest-version-just-installed] /usr/local/bin/python
--> Change default Python version to the latest version.ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python
python --version
--> Check Python version default again.Ref: https://dev.to/malwarebo/how-to-set-python3-as-a-default-python-version-on-mac-4jjf
Upvotes: 114
Reputation: 156
Sometimes when you install Python from the install wizard on MAC it will not link to your bash profile. Since you are using homebrew, just to brew install python
This would install the latest version of Python and then to link them brew link [email protected]
Upvotes: 2
Reputation: 4400
I recommend using pyenv to manage your local python versions (both 2.x and 3.x) instead of installing new versions directly with homebrew or building new python versions from source manually. Essentially, pyenv
can do two key things for you:
pyenv install 3.8.1
will install python 3.8.1 under ~/.pyenv/versions/3.8.1
.PATH
) with shims so that when you do pyenv local 3.8.1
, calling python
will invoke the new interpreter instead of your system python.The pyenv
repo is pretty detailed on how to install for different systems and what it's actually doing, but here's the basic steps for mac:
homebrew
if you don't already have it and use it to install pyenv
with brew install pyenv
.bash_profile
file to include:if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
Now install some python using pyenv and then switch to it with the pyenv local
command (you can see all your versions with pyenv versions
).
pyenv install 3.8.1 && pyenv local 3.8.1
Note: you may need to create a new shell or reload your bash_profile
in your current shell for the pyenv initialization to do its thing (set up shims).
With this setup, you'll be able to keep your system macosx python and switch to whatever new version of python you want available through pyenv
.
Upvotes: 6
Reputation: 9
If it were me, I would just leave it as it is. Use python3 and pip3 to run your files since python and python3 can coexist.
brew install python3 && cp /usr/local/bin/python3 /usr/local/bin/python
You can use the above line but it might have unintended consequences.
Upvotes: 0
Reputation: 9
On a mac use the following in the terminal to update python if you have anaconda:
conda update python
Upvotes: -2
Reputation: 21
Its always best to use homebrew to update or install python. In terminal type:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)
This will install homebrew (it takes sometime depending on your internet speed)
Then, in terminal, type
brew update
This will first update brew (you don't have to do that if you already have the latest version)
then type
brew upgrade python
This brew will update python to the latest viable version.
That should do it.
Upvotes: 2
Reputation: 651
This article helped me to make the right choices eventually since mac 10.14.6 by default came with python 2.7* and I had to upgrade to 3.7.*
brew install python3
brew update && brew upgrade python
alias python=/usr/local/bin/python3
Referred The right and wrong way to set Python 3 as default on a Mac article
Upvotes: 53
Reputation: 1
Instal aws cli via homebrew package manager. It is the simplest and easiest method.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
This will install aws cli on your mac
Upvotes: 0
Reputation: 105
I was having the same problem, but then after a bit of research I tried
brew install python3 && cp /usr/local/bin/python3 /usr/local/bin/python
in terminal
A warning message will pop-up saying that python 3.7.0
. is already installed but it's not linked
so type the command brew link python
and hit enter and hope things work right for you
Upvotes: 3
Reputation: 47
First, install Homebrew (The missing package manager for macOS) if you haven': Type this in your terminal
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Now you can update your Python to python 3 by this command
brew install python3 && cp /usr/local/bin/python3 /usr/local/bin/python
Python 2 and python 3 can coexist so to open python 3, type python3
instead of python
That's the easiest and the best way.
Upvotes: -1
Reputation: 32154
using Homebrew just do:
brew install python3 && cp /usr/local/bin/python3 /usr/local/bin/python
done :)
Upvotes: 52
Reputation: 141
Python 2.7 and 3 can co-exist.
Python version shows on terminal is 2.7, but you can invoke it using "python3", see this:
PeiwenMAC:git Peiwen$ python --version
Python 2.7.2
PeiwenMAC:git Peiwen$ python3
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Upvotes: 14
Reputation: 31
Echoing above on not messing with OS X install. Have been faced with a couple of reinstalls thinking I could beat the system. The 3.1 install Scott Griffiths offers above works fine with Yosemite, for any Beta testers out there.. Yosemite has Python 2.7.6 as part of OS install, and typing "python3.1" from terminal launches Python 3.1. Same for Python 3.4 (install here).
Upvotes: 0
Reputation: 841
I wanted to achieve the same today. The Mac with Snow Leopard comes with Python 2.6.1 version.
Since multiple Python versions can coexist, I downloaded Python 3.2.3 from: http://www.python.org/getit/
After installation the newer Python will be available under the Application folder and the IDE there uses 3.2.3 version of Python.
From the shell, python3 works with the newer version. That serves the purpose :)
Upvotes: 0
Reputation: 10665
I personally wouldn't mess around with OSX's python like they said. My personally preference for stuff like this is just using MacPorts and installing the versions I want via command line. MacPorts puts everything into a separate direction (under /opt I believe), so it doesn't override or directly interfere with the regular system. It has all the usually features of any package management utilities if you are familiar with Linux distros.
I would also suggest installing python_select via MacPorts and using that to select which python you want "active" (it will change the symlinks to point to the version you want). So at any time you can switch back to the Apple maintained version of python that came with OSX or you can switch to any of the ones installed via MacPorts.
Upvotes: 3
Reputation: 21925
The default Python on OS X shouldn't be messed with as it's used by the OS itself. If your default is 2.6.1 then you must have Snow Leopard.
If you just install from the standard 3.1 disk image then you can invoke it using python3.1
from the terminal (you don't have to do any extra steps for this to work) and you can leave the plain python
as 2.6.1.
Upvotes: 125
Reputation: 840
I believe Python 3 can coexist with Python 2. Try invoking it using "python3" or "python3.1". If it fails, you might need to uninstall 2.6 before installing 3.1.
Upvotes: 6