Setting default python version

Change Python Version Mac How to set Python3 as a default python version on MacOS?

By default MacOS ships with Python-2.-. But, I guess most of us have long back started to work with Python-3 and it is very irritating to run python3 every time instead of python in terminal. Here is how to do this. Open the terminal (bash or zsh) whatever shell you are using. Install python-3 using Homebrew (https://brew.sh).

lrwxr-xr-x 1 irfan admin 34 Nov 11 16:32 /usr/local/bin/python3 -> ../Cellar/python/3.7.5/bin/python3 lrwxr-xr-x 1 irfan admin 41 Nov 11 16:32 /usr/local/bin/python3-config -> ../Cellar/python/3.7.5/bin/python3-config lrwxr-xr-x 1 irfan admin 36 Nov 11 16:32 /usr/local/bin/python3.7 -> ../Cellar/python/3.7.5/bin/python3.7 lrwxr-xr-x 1 irfan admin 43 Nov 11 16:32 /usr/local/bin/python3.7-config -> ../Cellar/python/3.7.5/bin/python3.7-config lrwxr-xr-x 1 irfan admin 37 Nov 11 16:32 /usr/local/bin/python3.7m -> ../Cellar/python/3.7.5/bin/python3.7m lrwxr-xr-x 1 irfan admin 44 Nov 11 16:32 /usr/local/bin/python3.7m-config -> ../Cellar/python/3.7.5/bin/python3.7m-config 

Change the default python symlink to the version you want to use from above.
Note that, we only need to choose the one that end with python3.*. Please avoid using the ones’ that end with config or python3.*m or python3.*m-config. Below command shows how it should be done:

ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python 

Close the current terminal session or keep it that way and instead open a new terminal window (not tab). Run this:

Читайте также:  Map get or throw java

Top comments (85)

I’m not saying anyone would want to install Python 3 without brew, but if they did, pip3 gets installed:
$ pip3 —version
pip 19.2.3 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
$ pip3 install —upgrade pip
Collecting pip
Downloading files.pythonhosted.org/packages/54. (1.4MB)
|████████████████████████████████| 1.4MB 1.7MB/s
Installing collected packages: pip
Found existing installation: pip 19.2.3
Uninstalling pip-19.2.3:
Successfully uninstalled pip-19.2.3
Successfully installed pip-20.0.2

$ which pip
/Library/Frameworks/Python.framework/Versions/3.8/bin/pip

Now, Irfan’s handy command:
sudo ln -s -f /usr/local/bin/python3.8 /usr/local/bin/python

$ python —version
Python 3.8.2

7 likes Like Comment button

Hey! I tried following your above-mentioned method .. but I don’t know how the path is different . Although this method worked but will that path create any problem later on?
On my mac
which pip results in
/usr/local/bin/pip
instead of
/Library/Frameworks/Python.framework/Versions/3.8/bin/pip

apoorveesinha@Apoorvees-Air ~ % python —version
Python 2.7.16
apoorveesinha@Apoorvees-Air ~ % python3 —version
Python 3.8.2
apoorveesinha@Apoorvees-Air ~ % pip3 —version
pip 19.2.3 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
apoorveesinha@Apoorvees-Air ~ % pip3 install —upgrade pip
Collecting pip
Downloading files.pythonhosted.org/packages/54. (1.4MB)Installing collected packages: pip
Found existing installation: pip 19.2.3
Uninstalling pip-19.2.3:
Successfully uninstalled pip-19.2.3
Successfully installed pip-20.0.2
apoorveesinha@Apoorvees-Air ~ % which pip
/usr/local/bin/pip
apoorveesinha@Apoorvees-Air ~ % which pip
/usr/local/bin/pip
apoorveesinha@Apoorvees-Air ~ % sudo ln -s -f /usr/local/bin/python3.8 /usr/local/bin/python
Password:
apoorveesinha@Apoorvees-Air ~ %

apoorveesinha@Apoorvees-Air ~ % python —version
Python 3.8.2
apoorveesinha@Apoorvees-Air ~ % python3 —version
Python 3.8.2

2 likes Like Comment button

Источник

How can I change the default python on my Ubuntu 20.04 to Python3.8?

Complains it cannot find /usr/bin/python3.8, buuuuut: gt@gt-ThinkPad-X230:~$ ls /usr/bin/python* /usr/bin/python /usr/bin/python3.8 /usr/bin/python3-pasteurize /usr/bin/python2 /usr/bin/python3.8-config /usr/bin/python3-unidiff /usr/bin/python2.7 /usr/bin/python3-config /usr/bin/python3 /usr/bin/python3-futurize How do I get bash to find see /usr/bin/python3.8?

4 Answers 4

The correct way is sudo apt install python-is-python3 — it effectively does a symlink, but it also keeps pace with future updates; so if your ubuntu distribution moves to say Python 3.9, the manual symlink will no longer work, but the package makes sure it is still valid.

I did sudo apt install python-is-python3 , but nothing changed. What are the next steps? No man entry either

@Abdull inspect your environment. As I wrote, it does not do much more then install a symlink, so perhaps your PATH is messed up, or the binary that the symlink points to has been changed, there can be bunch of other problems. If you are at your wits end, I suggest you open a new question.

Firstly to answer your question, your approach should work, I think the path you’ve given in your alias needs the / preceding the path so the command should be alias python=’/usr/bin/python3.8′ , this would indeed need to go into your ~/.bashrc file assuming you are using bash.

Secondly, Ubuntu has a really nice method of setting default binaries globally rather than messing with dot config files as depicted here: update-alternatives

a better solution may be to simply run:

sudo update-alternatives --set python /usr/bin/python3.8 

This will ensure you have the version of python in use that you intend, everywhere.

I just tried this (in my case setting ‘python’ to ‘/usr/bin/python3’ on ubuntu20.04, but got the following error: ‘update-alternatives: error: no alternatives for python’. Any idea what I’m doing wrong?

@dagmarPrime update-alternatives is exactly what you need, as your aliases won’t get called in scripts. python can and should point to python 3 for most purposes these days and update-alternatives is the right way to do that.

@MaxPower You’re correct; this does not work on Ubuntu 20.04 LTS, for the reason you describe. But sudo apt install python-is-python3 does, per another answer, askubuntu.com/a/1272899/379076 .

After updating from 16 Xenial to 20.04.3 (via 18) alternatives seems to be a little wonky. alternatives says the symlink is pointing to python3.9 but it isn’t. update-alternatives —display python3 link currently points to /usr/bin/python3.9 link python3 is /usr/bin/python3 But. ls -l /usr/bin/python3 gives lrwxrwxrwx 1 root root 9 Mar 13 2020 /usr/bin/python3 -> python3.8 . ie pointing at 3.8. update-alternatives —set python3 /usr/bin/python3.9 shows update-alternatives: warning: forcing reinstallation . because link group python3 is broken .

Источник

Set Python 3 as your default “Python Version” on Windows 10/11

Python is a well-known programming language when it comes to solving Data Science related problems. It helps in easing down the work of Data Science with the help of its fast execution of codes because of its built Object-Oriented Programming but, there is a problem with this language as well.

Many Pythonists find it difficult to access the correct Python version because of too many Python versions present in their computer system. Due to this, they face problems in downloading the necessary packages in the correct Python version they want.

This leads to many problems in code executions as well as creates confusion for the computer to throw which version at what time.

Now, the question arises of how to resolve this issue and how to add the desired Python version say 3 as the default version on Windows 7/10/11.

The answer to this question is simple and given below. Just make sure that you have 2 or more 2 Python versions downloaded in the system to follow these steps of fixing the issue.

Steps to Change the Default Python Version on Windows 10/11 to Python 3

  • Open your command prompt and check the current Python version the system is using. This will help you get to know which version you are using right now and with which version you want to replace the same.
  • python —version

Check Default Python Version on Windows 10 using command prompt

  • After checking the Python version find the path of your Python versions that will be present most probably in C Drive under the Program Files folder.
  • Open the Program Files folder and locate your Python versions. After locating the same click on the versions and copy the path of the scripts folder of all the Python versions installed.

Find Installed Python folderSelect Pyhton 3 Scripts folder

  • Also, copy the path of the Program Files being present in C Drive.
  • Once the paths are copied the next step is to locate your Environment Variables for the computer. This can be done by right-clicking on the “This PC” option of your computer and clicking on the Properties option. After clicking on the same click on Advanced System Settings under the Properties option.
  • Once done, a pop will come on the screen displaying various options out of which you need to click on the Environment Variables option. The Environment Variables will open up for you and you can see all the system variables present there.

Environment Variables option to change the Windows 10 or 7 Python version

  • The Environment Variablsegregatedgintendednto two different parts that are User Variables and System Variables. Just locate the Path option under the System Variables and click on the same.
  • After clicking on the Path option make sure to put the Scripts and Program Files path of different Python versions that you currently want to use and work in, and where you want to store all your necessary packages should be put first followed by others. Simply, click on the Browse button and select the path of the Script folder and the Python3 itself.
  • Note:Remove any other Python Version available in the System variables, for example, Python2. Select its path and click on the Delete button.
  • Press the OK button to save the changes in the Windowgovernmentalentaltal Variables.

Add Python 3 directory path in Windows 10 or 7

  • Once this is done, restart your Command prompt and again type python —version . Now you will find the desired version there on the system and ready to be usable by the coder.

Conclusion

This is how a user can get his/her Python version when there are multiple versions on the computer. Try this out and start coding with your desired version.

Источник

Оцените статью