Python3 as default python version

set python3 as default mac
change default python version ubuntu
check default python version
change default python version linux
python 3
install python 3
switch between python 2 and 3 mac
ubuntu 18.04 default python version

I am creating a script that will call an API and return some results. I have the script working with pycharm on my computer but I am running into a few problems but I want to focus on this problem first.

1) I am unable to set Python3 as my default python.

I am using a Mac. When I go into terminal I enter $ python --version and it returns Python 2.7.10

I then enter $ alias python=python3, and when I run $python --version it returns Python 3.7.2

When I create a py.script with the os module, it does not work. See my code below.

import os
os.system('alias python=python3')
print(os.system('python --version')

It prints 2.7.10

I also tried to run the os.system('alias python="python3"')

On -nix machines (including OSX), one way to change the version of the interpreter that the script runs with is to add a shebang as the first line of your script.

Eg.

#! /usr/bin/env python3

import sys
print(sys.version)

Then to run your script do:

~/$ chmod u+x myscript.py
~/$ ./myscript.py 

You only need to run the chmod command the first time. It enables you to execute the file. Whenever you run your script directly (rather than as an argument to python) your script will be run using the version specified by the shebang.

The right and wrong way to set up Python 3 on MacOS, On another note, anyone coming here because they are trying to learn about making Python 3 their default, may instead find use in researching� Set your preferred default version by setting the PY_PYTHON environment variable (e.g. PY_PYTHON=3.7). You can see what version of python is your default by typing py. You can also set PY_PYTHON3 or PY_PYTHON2 to specify default python 3 and python 2 versions (if you have multiple).

welcome to SO! Pycharm needs you to specify which interpreter to use as default, as it wouldn't choose the system one by default.

So if you want python3, you can run which python3, and use the path as a settings for the current project. How to do that step by step is here:

https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html

Hope it help, post a comment if you need more details.

How to make 'python' program command execute Python 3?, 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� In our case we have set a priority 2 for /usr/bin/python3.4 and as a result the /usr/bin/python3.4 was set as default python version automatically by update-alternatives command. # python --version Python 3.4.2 Next, we can again list all python alternatives: # update-alternatives --list python /usr/bin/python2.7 /usr/bin/python3.4

This isn't surprising, because os.system opens its own shell, and running alias in that way only affects the currently running terminal. Each call to os.system would be in a separate shell.

I'm not sure what your ultimate goal is, but you almost certainly don't need to change what python means to a shell to do it. If you DO, you'll have to run both commands at once.

import subprocess

cp = subprocess.run("alias python=python3 && /path/to/script")

Change Python Version Mac: How to set Python3 as a default , 4 and as a result the /usr/bin/python3.4 was set as default python version automatically by update-alternatives command. # python --version� It is not recommended to change the symbolic link because of other package dependencies, but they "have ongoing project goals to make Python 3 the default, preferred Python version in the distros".

Interesting - apparently os.system ignores the alias? Just checked it in Linux and got the same results.

Try sys instead of os:

import sys
print(sys.version)

How to change from default to alternative Python version on Debian , From the comment: sudo update-alternatives --config python. Will show you an error: update-alternatives: error: no alternatives for python3. Let' check our python version [ec2-user@cloudvedas ~]$ python3.6 -V Python 3.6.4 [ec2-user@cloudvedas ~]$ Update default python But if you still run the normal command to check python version it will show the Python 2 version if it was installed by default. [ec2-user@cloudvedas ~]$ python --version Python 2.7.5 [ec2-user@cloudvedas ~]$

Change the Python3 default version in Ubuntu, Do not use update-alternatives to change your default python version, as this even if you have multiple versions of python 3 installed via apt . By default, MacOS come with a default version of Python, which is Python 2, but to install certain software such as Ansible and AWS Cli, you may need to have the Python 3+. But after you install the Python 3, it will not auto bind you the default Python, you may need to run Python3 everytime you want to use Python3, this is very irritating.

How to make python3.7 default, X onwards all have python 3.x interpreter bundled. H owever python 2.7.6 interpreter is still usually configured as the default interpreter. 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.

Configure Python 3 as default on Ubuntu, Giving python3.6 a higher priority means that it will be used as default. Let's check: # python --version. Python 3.6.8. If you would like to change� 20 Since python3 is the default python version in Ubuntu 18.04 and python2 won't be shipped by default on a fresh Ubuntu 18.04 installation, how can I make python3 default after an upgrade to Ubuntu 18.04 (from 16.04). Currently, after the upgrade to python2 it still defaulted (e.g. python command directs to python2 etc.).

Comments
  • You must not set Python 3 as your default (system) Python. Doing so could break your OS in all sorts of ways as it has many scripts that rely on using Python 2. Why not change your question to be about what you are trying to do, rather than how you are trying to achieve it. That is, why do you want Python 3 to be your default?
  • what I am trying to do is run an api call via the Requests module, but when I run the script the Request module is not found (unless I run it via Pycharm). However, if I open IDLE and import Requests manually it works, I just want to save it as a script. Here is the code import os import requests #perform actions. When I save it as a .py and attempt to run the script via Python Launcher I get an error message saying ImportError: No module named requests
  • I can get the script to run on pycharm exactly as I want, I just can't get the import requests module to work when I save it as a .py, I get the error ImportError: No module named requests when I attempt to run it via Python Launcher
  • Ultimately, I want to create a script that can be used by multiple users, it needs to run an API call to Postman via the requests module. So, I am still in the testing phase. I can get the script to run on my machine via PyCharm no problem, but when I save it as a .py and try to run it via the Python Launcher I receive the following error message: "ImportError: No module named requests"
  • That sounds like a whole different problem. You can over-engineer a solution using setuptools's entrypoints directive and building the application into a built package, then distributing that bdist or wheel file to each user. It's a lot more work, but it has the benefit of handling all your dependency management by itself.
  • @CaliforniaDataSurfer note that if you put #!/usr/bin/env python3 as the first line of your Python file, it should just work.
  • Do you mean to run something like this #!/usr/bin/env python3 import requests
  • No, put that line (called a shebang) as the first line of your python script. Then double-clicking it from the Finder should use python3 rather than python.
  • via terminal I get 2.7.10, via IDLE I get 3.7.2