make python3.5 as default in AWS? - python

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

Related

How to set "python" as default

Hello can someone help me with this.
So the issue is that I started using linux and I need to make my "python3" line code into just "python". For example -- "python3 run.py" (this is now), but i want just
"python run.py". If someone can help me it would made my day
All these answers assume your system doesn't have Python 2 installed, otherwise you might cause other issues.
The recommended way if you are using BASH on Linux or UNIX, is to edit the .bashrc file in your home directory :
~/.bashrc
The '~' 'points to your home directory '/home/username'. Once you have this file open, add the following to the bottom :
alias python='python3'
Now typing 'python' will automatically run Python 3. I use this method because it doesn't require altering system files, but you can't run as sudo (which might be a good thing).
If you need to use 'sudo', create a symbolic link with the following command:
sudo ln -s /usr/bin/python3 /usr/local/bin/python
Alternatively install the 'python-is-python3' package, as mentioned by #chepner the following assumes you are using the apt package manager, and similarly does nothing more than create a symbolic link :
sudo apt install python-is-python3
1.Go to terminal type - python --version
2.Log in with root privileges sudo su
3.Execute this command update-alternatives --install /usr/bin/python python /usr/bin/python3
4. Check version again
You can install python-is-python3 package:
$ sudo apt install python-is-python3

change the default version of python in kali linux

tried to install sherlock
for installing sherlock python 3.6 or more required, i installed python 3.8.2.But the default version is not changed it remain as python 2.7.17.
Here is a link that may help. Check it out!
Basically:
Check your existing python version by running:
python -V
or
python --version
List all the available items by running:
ls /usr/bin/python
Now, set your version priorities by issuing the following commands:
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives --install /usr/bin/python python /usr/bin/python3.8 2
You can then list the python priorities by:
update-alternatives --config python
Finally, check your default python version to confirm by repeating the first step!
I have included a screenshot of the same. Check it out.
Change Default Python Version Priority.png
Just taking the needed part from #George Oyosa's answer
update-alternatives --install /usr/bin/python python /usr/bin/python3.8 2
Just execute it and the the command update-alternatives will handle the rest for you.
Simply open terminal and run "alias python=python3" (without the quotes) then run "python -V" to check
sudo apt install -y python-is-python3
As explain here : Everything you need to know about the switch to Python 3

How to uninstall python 2.17.13, and keep python 3.7.6 as the default version on debian 9?

I installed a Django package on GCP (Debian 9 OS), that comes with the following softwares:
Django (2.2.9)
Git (2.25.0)
Apache (2.4.41)
lego (3.3.0)
MySQL (5.7.29)
Node.js (10.18.1)
OpenSSL (1.1.1d)
PostgreSQL (11.6)
Python (3.7.6)
SQLite (3.31.0.)
Subversion (1.13.0)
When I type the command python -V
I get the following python version: 2.17.13
When I type python3 -V
I get the following version: 3.7.6
How can I uninstall the previous version permanently and keep the current one as the default?
Here's what I tried and I didn't work:
$ ls /usr/bin/python*
usr/bin/python /usr/bin/python2.7 /usr/bin/python3.5 /usr/bin/python3m
/usr/bin/python2 /usr/bin/python3 /usr/bin/python3.5m
# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
Returns nothing
# update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
Returns nothing
I would not recommend uninstalling python2. Install python3 and make sure the directory where you install it is included in your systems $PATH variable. You will need to do something like this. Note, depending on how you install python3, some installers will automatically update your $PATH variable.
Example installing python3 in "/Library/Frameworks/python3" directory.
Show current $PATH variable.
echo $PATH
update .bashrc in home directory (append to current $PATH)
PATH="/Library/Frameworks/python3:${PATH}"
reload .bashrc (or exit and start terminal back up)
. ~/.bashrc
Confirm correct python install will be run when typing python3 into terminal.
$which python3
/Library/Frameworks/python3

Set python 3 as default python version in CentOS

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.

How to fix "python version are always returned 2.7 instead of 3.7"

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

Categories