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
Related
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
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
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 just started setting up a centos server today and noticed that the default version of python on centos is set to 2.6.6. I want to use python 2.7 instead. I googled around and found that 2.6.6 is used by system tools such as YUM so I should not tamper with it. Then I opened up a terminal on my mac and found that I had python 2.6.8 and 2.7.5 and 3.3.3 installed. Sorry for the long story. In short I just want to know how to lookup all the version of python installed on centos so I don't accidentally install it twice.
The more easy way its by executing the next command:
ls -ls /usr/bin/python*
Output look like this:
/usr/bin/python /usr/bin/python2.7 /usr/bin/pythonw
/usr/bin/python-config /usr/bin/python2.7-config /usr/bin/pythonw2.7
we can directly use this to see all the pythons installed both by current user and the root by the following:
whereis python
Find out which version of Python is installed by issuing the command
python --version:
$ python --version
Python 2.7.10
If you see something like this, Python 2.7 is your default version. You can also see if you have Python 3 installed:
$ python3 --version
Python 3.7.2
If you also want to know the path where it is installed, you can issue the command "which" with python and python3:
$ which python
/usr/bin/python
$ which python3
/usr/local/bin/python3
Here is a cleaner way to show them (technically without symbolic links). This includes python2 and python3 installs:
ls -1 /usr/bin/python* | grep '.*[2-3]\(.[0-9]\+\)\?$'
Where grep filters the output of ls that that has that numeric pattern at the end ($).
Or using find:
find /usr/bin/python* ! -type l
Which shows all the different (!) of symbolic link type (-type l).
Use, yum list installed command to find the packages you installed.
COMMAND: python --version && python3 --version
OUTPUT:
Python 2.7.10
Python 3.7.1
ALIAS COMMAND: pyver
OUTPUT:
Python 2.7.10
Python 3.7.1
You can make an alias like "pyver" in your .bashrc file or else using a text accelerator like AText maybe.
As someone mentioned in a comment, you can use which python if it is supported by CentOS. Another command that could work is whereis python. In the event neither of these work, you can start the Python interpreter, and it will show you the version, or you could look in /usr/bin for the Python files (python, python3 etc).
It depends on your default version of python setup. You can query by Python Version:
python3 --version //to check which version of python3 is installed on your computer
python2 --version // to check which version of python2 is installed on your computer
python --version // it shows your default Python installed version.
compgen -c python | grep -P '^python\d'
This lists some other python things too, But hey, You can identify all python versions among them.
Sift through the output of this script.
sudo find / -name 'python*' -type f -exec du -h {} + | sort -r -h ~/Documents/python_locations.txt
ls -l /usr/bin/python* & ls -l /usr/local/bin/python*
I would add to #nurealam siddiq answer,
python --version // it shows your default Python installed version.
python2 --version // to check which version of python2 is installed
python3 --version //to check which version of python3 is installed
python3.X --version // to further check which python3.X is installed
To check python versions installed in your OS you can run the below commands:-
python2 -version
python3 -version