How to install Python 3 on AWS Linux RHEL Free Tier? - python

When I try to install, it says that 2.7 is already installed. I want Python 3. How to install that?
I tried using python3, cannot find package:

Python 3 is a different package:
sudo yum install python3

Check your RHEL release version using
$lsb_release -a
Then depending on your OS version follow answers in Installing Python 3 on RHEL for installation

Here is the one command to install python3 on Amazon linux 2:
$sudo yum install python3 -y
$python3 --version
Python 3.7.6

Related

download pip3 for python 3.9.0

when i run python3 -V on my amazon workdsace - it gives me Python 3.9.0
and when i run python -V - it gives me Python 2.7.18
and when i run pip --version - it gives me pip 20.2.4 from /home/myName/.local/lib/python2.7/site-packages/pip (python 2.7)
what i want is to download pip3 for python 3.9.0 to download modules also the script i made works with python3 not python2
any idea ?
It depends on your distribution here are the commands for CentOS and Debian/Ubuntu:
Centos: yum install python3-pip
Debian: apt install python3-pip
(you can found command for others Distributions here https://packaging.python.org/guides/installing-using-linux-tools/#installing-pip-setuptools-wheel-with-linux-package-managers)
Or you can install directly from the python script provided by pip developers (not recommended if you have installed your python from OS package manager):
https://pip.pypa.io/en/stable/installing/#installing-with-get-pip-py

How to upgrade Python 3 on Linux RHEL?

I have a Rhel version of a Linux and would like to upgrade from Python 3.6 to 3.7.2
What is the best and proven way to do it?
Tried with yum but seems that does not have latest versions of python..
Sharing what worked for me. Worked for me on Enterprise RHEL 7.
#-> python --version
Python 2.7.5
#-> yum install rh-python38
#-> scl enable rh-python38 bash
#-> python --version
Python 3.8.0
But you will have enter into the scl shell everytime as the default shell would still be Python 2.7. To make this permanent, I had to
Add this to my ~/.bash_profile
source /opt/rh/rh-python38/enable
Below command worked for me.
sudo dnf install python3.8 -y
I wanted to use python3.8 and removed old python3.6 and installed python3.8 using above command
command to remove python3.6
sudo dnf remove python3.6 -y

Install Python version 3 side by side with version 2 in Centos 7

I have a CentOS 7 machine which already has Python 2.7.5 installed. Now i want to install Python version 3 also side by side without disturbing the original Python version 2. If i install with pip i fear that it would install version 3 on top of the already existing version.
Can someone please guide me how to do the same ? Also i have created a virtualenvs directory inside my installation where i want to create the virualenvs.
At present whenever i create any virtualenvs using the virtualenv command it automatically copies the Python version 2 installable over there.
I want my virtualenvs to contain version 3 and anything outside my virtualenvs should run with version 2.
Is this even possible.
Thanks a lot for any answers.
For CentOS 7, we can use IUS Community repo
yum -y install https://centos7.iuscommunity.org/ius-release.rpm
yum -y install python36u
yum -y install python36u-pip
pip3.6 install numpy
So outside your virtualenv, default pip may install for python 2 not python 3.
For Python2 virtaulenv support python3, you can try:
virtualenv python2-bridge
source ./python2-bridge/bin/active
pip install --upgrade virtualenv
virtualenv -p python3 <folder>
source ./<folder>/bin/activate
python --version && pip --version
Python 3.4.3
pip 8.1.2 from /home/centos/<folder>/lib/python3.4/site-packages (python 3.4)
Refer(
https://opsech.io/posts/2016/Sep/06/creating-python-3-virtual-environments-on-centos-7.html)
The simplest method I know is to add the IUS Community repo for Centos 7 (only the most common x86_64 architecture is supported). Then simply install the required Python3 version directly with yum, e.g. yum install python36u
Link: https://ius.io/setup
Installing anything from an unknown source is a risk. The IUS has a good reputation - see e.g.
https://wiki.centos.org/AdditionalResources/Repositories - but you must decide yourself if you want to use it.
In case someone stumbles upon this old thread: note that as of CentOS 7.7, python3 is included in the official repos, so you can just do
yum install python3
See https://www.liquidweb.com/kb/how-to-install-python-3-on-centos-7/
You can simply apt-get install python3 and then use -p python3 while creating your virtual environment. Installing python3 will not disturb your system python (2.7).

How to install pip for a specific python version

I have my deployment system running CentOS 6.
It has by default python 2.6.6 installed. So, "which python" gives me /usr/bin/python (which is 2.6.6)
I later installed python3.5, which is invoked as python3 ("which python3" gives me /usr/local/bin/python3)
Using pip, I need to install a few packages that are specific to python3. So I did pip install using:-
"sudo yum install python-pip"
So "which pip" is /usr/bin/pip.
Now whenever I do any "pip install", it just installs it for 2.6.6. :-(
It is clear that pip installation got tied to python 2.6.6 and invoking pip later, only installs packages for 2.6.6.
How can I get around this issue?
If pip isn’t already installed, then first try to bootstrap it from the standard library:
$ python3.5 -m ensurepip --default-pip
If that still doesn’t allow you to run pip:
Securely Download get-pip.py.
Run sudo python3.5 get-pip.py.
Now you can use pip3 to install packages for python3.5. For example, try:
$ sudo pip3 install ipython # isntall IPython for python3.5
Alternatively, as long as the corresponding pip has been installed, you can use pip for a specific Python version like this:
$ python3.5 -m pip install SomePackage # specifically Python 3.5
References:
Ensure you can run pip from the command line
work with multiple versions of Python installed in parallel?
I have python 3.6 and 3.8 on my Ubuntu 18.04 WSL machine. Running
sudo apt-get install python3-pip
pip3 install my_package_name
kept installing packages into Python 3.6 dist directories. The only way that I could install packages for Python 3.8 was:
python3.8 -m pip install my_package_name
That installed appropriate package into the Python 3.8 dist package directory so that when I ran my code with python3.8, the required package was available.
Example of how to install pip for a specific python version
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
/opt/local/bin/python2.7 get-pip.py
Script is from official doc: https://pip.pypa.io/en/stable/installing/
On Ubuntu 18.04.1 LTS I wanted to install pip for my second python version (python3) and the following command did the trick for me:
$ sudo apt install python3-pip

How to change Python version in which modules get installed?

I'm trying to install Python-Twitch for Python 3.4. I have both 3.4 and 3.5 installed on my computer, and in command prompt I do this:
python --version
Where it gives me Python 3.5.x. Then:
set PATH=C:\Python34\;%PATH%
And python --version will then read Python 3.4.x.
Once I do 'pip install python-twitch', it installs it to the Python 3.5 Lib/Site-Packages folder. How would I get this over to 3.4?
Thanks so much for any help.
I think this was already answered: pip: dealing with multiple Python versions?
Since version 0.8, Pip supports pip-{version}. You can use it the same as easy_install-{version}:
$ pip-2.5 install myfoopackage
$ pip-2.6 install otherpackage
$ pip-2.7 install mybarpackage
EDIT: pip changed its schema to use pipVERSION instead of pip-VERSION in version 1.5. You should use the following if you have pip >= 1.5:
$ pip2.6 install otherpackage
$ pip2.7 install mybarpackage
Check https://github.com/pypa/pip/pull/1053 for more details

Categories

Resources