I've installed Python 2.7 using macports and because of my $PATH variable, that's the one I get when I type $ python. However, virtualenv defaults to using Python 2.6 unless I remember to force it to do otherwise with the -p flag.
On a related note, globally running yolk -l shows the following:
Python - 2.6.1 - active development (/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload)
So my question is, should I do something to ensure the system is always using MacPorts' Python 2.7 or is it not worth worrying that Apple's Python 2.6.1 is apparently in the mix?
Use:
$ sudo port select --set python2 python27
In order to use the MacPorts version as your primary Python try:
$ sudo port select --set python python27
or
$ sudo port select --set python2 python27
To make this the default Python or Python 2 (i.e., the version run by
the 'python' or 'python2' commands), run one or both.
* Restart Terminal.app, or whichever console you're using then try:
$ which python
$ python -V
Related
I recently formatted my laptop and installed the Ubuntu operating system. I did not explicitly install Python. To check if it is pre-installed, I ran python --version in the terminal and got this:
$ python --version
Command 'python' not found, but can be installed with:
sudo apt install python3
sudo apt install python
sudo apt install python-minimal
You also have python3 installed, you can run 'python3' instead.
Then I checked python3 --version and got this: Python 3.6.9.
How is this possible? Should I install python as well? Or can I continue to use python3? Would this cause any problems?
Recent Ubuntu versions do not install python 2 by default, as python 2 is now "dead". However, the command python is not (yet) linked to python 3, to avoid some confusion; traditionally, python was for python 2 while python3 was for python 3.
In case you want to change this behavior and use python to run python 3, try installing a package named 'python-is-python3'. Then you can run python --version and see that it points to python 3.
In theory it might cause confusion for some legacy programs, but I haven't seen any issue so far for about a year.
In 20.04 LTS, the python included in the base system is Python 3.8. Python 2.7 has been moved to universe and is not included by default in any new installs.
Remaining packages in Ubuntu which require Python 2.7 have been updated to use /usr/bin/python2 as their interpreter, and /usr/bin/python is not present by default on any new installs. On systems upgraded from previous releases, /usr/bin/python will continue to point to python2 for compatibility. Users who require /usr/bin/python for compatibility on newly-installed systems are encouraged to install the python-is-python3 package, for a /usr/bin/python pointing to python3 instead.
— https://wiki.ubuntu.com/FocalFossa/ReleaseNotes
Just python on Linux traditionally refers to Python 2. python3 is the correct command if you want to use Python 3 (which you should, as Python 2 is EOL).
TL;DR: Just use python3
Python on Ubuntu refers to Python v2. If you were to run
python --version
you would see an output in the format of
Python 2.x.y
Python 2 has been sunset, which means it no longer will be updated and the recommendation is to move to Python3.
To run a program with Python 3, you just need to use python3 command instead.
python3 ./app.py
I have installed python 3.6 on my CentOS machine by following the guide at https://linuxize.com/post/how-to-install-python-3-on-centos-7/, which installs python 3 with the following:
sudo yum install rh-python36
The default python version, however, is still python 2. The guide mentions I can run python 3 by first running scl enable rh-python36 bash, and then python 3 will be used. However, this only works for that session - logging out and back in will revert back to python 2. According to How to set Python3.5.2 as default Python version on CentOS?, python 3 can be set as the default with the following:
sudo ln -fs /usr/bin/python3 /usr/bin/python
However, this doesn't work for me as for some reason I don't have any python3 file in /usr/bin/ - I only have python, python2, python2.7, python2.7-config, python2-config and python-config (despite installing python 3 with yum as above).
First, run
$ scl enable rh-python36 bash
to switch python version.
Second, run
$ which python
to find out the exact path of python3.6 binary.
Third, edit ~/.bashrc.
$ vim ~/.bashrc
and add below line.
alias python='/opt....(the path you found by "which python")'
and save the file.
I downloaded python 3.7.3 but python 2.7.10 already existed.
Now python --version returns 2.7.10
How to fix this?
If you are working on Linux, you can always type python3 --version to check if it is installed and be sure it is the version you want to use.
There are several ways to make python call Python 3 by default. For instance you can create an alias. Type whereis python3 so you get the installation path to python3 (normally it is located in /usr/bin/python3). If that's the case you can simply add to ~/.bashrc the following line:
alias python='/usr/bin/python3'
Then, source that file or reload the session. This assumes that /usr/bin/python3 is the location of Python 3. Please, note that other commands that depend on your Python installation (such as pip or coverage) are still pointing to the ones installed by Python 2, so you may want to do the same for them, or make sure that you call pip3 instead of pip if you want to install any extra package.
If you are using linux or macOS, the python command refers to the built-in Python2. You need to use the python3 command to use Python3.
So running:
python3 --version
should give you the expected output.
Also, when you want to run your scripts in Python3, you need to use:
python3 myscript.py
Both the python2x and python3x can exist on a system. On linux machines the default python version is python2x.
so if you want to work with python2x type python2.7 or python3 otherwise.
Installation
sudo apt update
sudo apt install python3.9
Checking the installation with the python3 --version command still returns the old version. To fix this :
Create a list of update alternatives. First, add the old version to the list with the command:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.[old-version] 1
Now add the new version:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
Type the following command to configure the priority status of the versions:
sudo update-alternatives --config python3
check the default version:
python3 --version
DONE
Is there a way to make python3.5 as the default python in AWS.
every time i try the next time i connect python2.7 is the default one and pip 6 is the last version, knowing that I did updated it some minutes before.
here is the method i followed : amazon_link
here is another link of amazon telling the versions, actually they are at 3.5 another_link
Thank you in advance, :)
best wishes
alternatives --set python /usr/bin/python3.5
and then back if you want to
alternatives --set python /usr/bin/python2.7
If you want to see what it currently points to
alternatives --display python
This is a system-wide setting not just for the current user. The system settings are stored in /etc/alternatives
A simple safe way would be to use an alias. Place this into ~/.bashrc or ~/.bash_aliases file:
alias python=python3
Example
$ python --version
Python 2.7.6
$ python3 --version
Python 3.4.3
$ alias python=python3
$ python --version
Python 3.4.3
By default, the awscli-bundle install script runs under the system default version of Python. To answer your question you will need to know the path of Python version to use.
Then run:
$ sudo /path/to/python/version awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
In my case I would run:
$ sudo /usr/local/bin/python3.7 awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
To change Python Version 3.x
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.x 1
*** Because sometimes priority is required use, you just add '1' at end of command line.**
To check update
sudo update-alternatives --list | grep python
Reset Python old version'
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
Just close terminal and restart.
Python -V
3.x
Good luck
do above: alias python=python36 in ~.bashrc file (Use emacs, vim, your favorite editor - emacs ~.bashrc) then save file.
then in command line terminal type: source ~/.bashrc (for changes to take effect)
Because AL2 is picky, unfortunately NONE of these answers is exactly correct. Here's what worked for me just now (as root)-
alternatives --install /usr/bin/python python /usr/bin/python2.7 1
alternatives --install /usr/bin/python python /usr/bin/python3.7 2
3.7 SHOULD be the default now, and you can test with python --version.
To change the default at any time:
update-alternatives --config python
The menu system will prompt you through the change.
I used alias and it works for me. (AMI2 AWS)
alias python=python3
Add this command in .bashrc file and then reboot the server
python --version
It will show python version 3
I have Python 3.4 installed on my Linux computer.
sudo apt-get install python3.4
However, when I run python -V, it shows that Python 2.7.6 is being used.
How do I tell the system to use the updated version of Python?
The answer to this question for a windows computer is at How to update version of Python?, but I couldn't find an answer for Linux.
On Linux, installations of python3 installed by the package manager (e.g. apt) can be called as python3. You might need to specify the version - e.g. python3.5 if the package manager has installed more than one, or you've compiled your own installations from source.
you can specify the version in the shebang.
write #!/usr/bin/env python3.
when run via ./my_script.py it will run in python3.
otherwise run it via python3 my_script.py.
if you just want to start an interactive python shell start it with python3
you also can be more specific with the version. just replace python3 with python3.4 (if installed)
In ubuntu various python executable are places under /usr/bin/ and might look like
/usr/bin/python
/usr/bin/python3.2
/usr/bin/python3.4
etc. so when you execute a command python -v it looks for a file with that name in that location. so to choose your version specify it like python3.4 -v
you can replace the simlink /usr/lib/python with /usr/bin/python3.4 to make that "default"