How to change python3 version on mac to 3.10.10
Asked Answered
A

7

20

I am currently running python 3.9.13 on my mac. I wanted to update my version to 3.10.10

I tried running

brew install python

However it says that "python 3.10.10 is already installed"!

When i run

python3 --version

in the terminal it says that i am still on "python 3.9.13"

So my question is, how do i change the python version from 3.9.13 to 3.10.10? I already deleted python 3.9 from my applications and python 3.10 is the only one that is still there.

I also tried to install python 3.10.10 from the website and installing it. However it does not work. Python 3.10.10 is being installed successfully but the version is still the same when i check it.

Applied answered 10/2, 2023 at 19:20 Comment(0)
Q
25

you can use pyenv to work with multiple python environments

things to do:

  1. install pyenv : brew install pyenvofficial installation guide
  2. install particular python: pyenv install 3.10.10
  3. set python3.10.10 to gloabal python env: pyenv global 3.10.10

and can start using python 3.10.10 version

in my opinion, if you are not good with the terminal or how python is configured in mac system, it is better to leave the original system Python as it is. and use a separate Python manager to help you manage the different Python version independently if something wrong goes then it only affect the environment not the system

Quintessa answered 10/2, 2023 at 19:43 Comment(2)
If your python3 --version is still not 3.10.10 after executing pyenv global 3,10.10, maybe you need to modify your .zshrc or .bashrc to update your PATH correctly, add these lines into it. export PATH="$HOME/.pyenv/bin:$PATH" eval "$(pyenv init --path)" eval "$(pyenv init -)"Adal
@HuXixi yes, it is only for zshrc, all these step is mentioned in the official installtion guide and for other environment also , so will keep solution to this nowQuintessa
A
5

Let me add some additional information to the first point of the accepted answer.

If you have already executed pyenv global 3.10.10, but python3 --version still shows an older version (such as 3.9), it might be because pyenv is not correctly configured in your shell environment, or the system's PATH environment variable is not properly updated. Here are some steps to resolve this issue:

1. Ensure pyenv is Properly Installed and Initialized

First, make sure you have correctly installed pyenv, and that the initialization script for pyenv has been added to your shell configuration file.

For zsh Users:

Edit the ~/.zshrc file:

nano ~/.zshrc

Add the following lines (if not already added):

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"

For bash Users:

Edit the ~/.bashrc or ~/.bash_profile file:

nano ~/.bashrc

Add the following lines (if not already added):

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"

2. Reload the Shell Configuration File

Save the file and exit the editor, then reload the configuration file:

For zsh Users:

source ~/.zshrc

For bash Users:

source ~/.bashrc

3. Confirm pyenv Configuration

Run the following command to ensure pyenv is correctly configured:

pyenv versions

You should see output similar to the following, where 3.10.10 has an asterisk indicating it is the global version:

* 3.10.10 (set by /Users/hu/.pyenv/version)
  system

4. Check the PATH Environment Variable

Ensure that the pyenv shims directory is at the front of the PATH environment variable. Run the following command to check the PATH:

echo $PATH

Ensure the output includes a path like ~/.pyenv/shims, and that it appears before other Python paths.

5. Verify the python3 Version

Finally, verify the python3 version:

python3 --version

You should see the version Python 3.10.10.

6. Additional Checks

If the above steps still do not resolve the issue, you can try the following command to ensure the pyenv shims are up to date:

pyenv rehash

Also, ensure there are no other Python installation paths interfering:

which python3

It should point to ~/.pyenv/shims/python3.

By following these steps, you should be able to successfully set pyenv to use version 3.10.10 as the default python3.


Adal answered 19/5 at 13:18 Comment(0)
H
4

I had the same problem upgrading from 3.8 to 3.11 on macOS until I realized I needed to end my terminal session and start a new one. Then the python3 --version command reported the new version.

Hexyl answered 13/7, 2023 at 20:10 Comment(0)
C
3

When you download latest version, it comes with a file named Update Shell Profile.command.

In mac, you can find it at /Applications/Python 3.11/Update Shell Profile.command.

Run it and it should upgrade to latest version.

Catercornered answered 4/6, 2023 at 2:44 Comment(0)
S
1

Python 3.10.10 is already installed along with Python 3.9.13. Your path is probably pointing to 3.9.13 and that's why you're getting that Python version.

Try modifying your path variable to point to brew's Python installation, or (better yet) make use of a virtual environment.

a) Telling what Python version your PATH variable is pointing to:

$ which python

Will tell you what's the actual executable's path. That way, you are going to see exactly where you main python resides.

b) If you want to create a virtual environment with brew's python try something like:

$ /usr/local/Cellar/[email protected]/3.10.1/bin/python3 -m venv py310
$ source venv/bin/activate
$ python
> # you should be inside a 3.10.1 envornamente
> CTRL+D
$ pip install requests
Siler answered 10/2, 2023 at 19:24 Comment(4)
What command do i need to run to change the path variable to point to brew's python installation? When i run "which python" it says "user/miniforge3/bin/python"Applied
It depends on what's the shell you're using. Is it bash? Is it zsh? What does the command $ echo $SHELL tells you?Siler
Iam using the zsh shell :)Applied
Then you can edit the ~/.zshrc file to set your PATH variable accordingly.Siler
A
0

Just delete the current python installation on your device and download the version you want from the offical website. That is the easiest way and the most suitable one for a beginner.

Allianora answered 10/2, 2023 at 19:48 Comment(2)
I did that however when i run the command "python3 --version" it still shows my old versionApplied
I believe you weren't able to delete python in a proper way. Try using this command sudo pkgutil --forget python3. If that doesn't work you can also try [user name] sudo rm -rf /Applications/Python\ [your_python_version]/.Allianora
G
0

Download the source code for the version from their website.

cd into the directory, and run the following in your terminal

./configure
make
sudo make install

exit the terminal and re-open it.

Running python3 --version should show the latest version that you downloaded

Genovese answered 14/4 at 17:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.