Run these commands to ensure your repositories are up to date before installing
Copysudo apt update
sudo apt upgrade
sudo apt install python2.7
Then to install pip for python 2:
Copysudo apt install python-pip
Answer from Spiff on Stack OverflowRun these commands to ensure your repositories are up to date before installing
Copysudo apt update
sudo apt upgrade
sudo apt install python2.7
Then to install pip for python 2:
Copysudo apt install python-pip
As my comment has solved the issue, I will develop it a little more in this answer for further reference.
Try using aptitude, it better manage conflicting packages for you:
Copysudo aptitude install python-minimal
Reference: https://askubuntu.com/a/451078/1006720
python - How to install Python2.7.5 in Ubuntu docker image? - Stack Overflow
How do I install python 2.7
Python 2.7.18 is installed yet only Python 2.7.17 only shows up with Python2 -V
What is the safest way to work with Python 2 on Ubuntu 24.04?
Videos
First, install some dependencies:
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
Then download using the following command:
version=2.7.13
cd ~/Downloads/
wget https://www.python.org/ftp/python/$version/Python-$version.tgz
Extract and go to the directory:
tar -xvf Python-$version.tgz
cd Python-$version
Now, install using the command you just tried, using checkinstall instead to make it easier to uninstall if needed:
./configure
make
sudo checkinstall
Change version to whichever version you need (version=2.7.1 or version=3.6.0, for example).
Unless you really have a burning desire to compile it yourself, the preferred way is to use the DeadSnakes PPA to install versions of Python that aren't included by default:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python2.7
Other versions, such as python2.4 or python3.6, etc. are also available.
Python 2 is no longer installed by default in fresh installations of Ubuntu 18.04 and later. Don't remove python3 from Ubuntu 18.04 and later or else Ubuntu Software, the terminal and many other apps that are installed by default will stop working. If you removed Python 3 and now Ubuntu Software, terminal and other applications don't work follow the instructions in this answer to reinstall it and get all applications working again.
To install Python 2.7 in Ubuntu 18.04 and later open the terminal and type:
sudo apt install python2.7
To start the Python 2.7 interpreter run this command:
python2.7
To start the Python 3 interpreter run this command:
python3
Either way the Python interpreter will show a version message when it is started that shows what version of Python you are running.
1) To install Python 2 version on Ubuntu 18.04 open up terminal and enter:
sudo apt install python-minimal
or
sudo apt install python2.7
Check version:
python --version
2) If still python 3+ updated list of Python alternatives to perform a switch between any python version is to run:
update-alternatives --config python
Example:
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.5 2 auto mode
1 /usr/bin/python2.7 1 manual mode
2 /usr/bin/python3.5 2 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in manual mode
and select an appropriate version using selction integer as shown above.
3) If you see: update-alternatives: error: no alternatives for python. Run:
ls /usr/bin/python*
Example output:
/usr/bin/python /usr/bin/python2 /usr/bin/python2.7 /usr/bin/python3 /usr/bin/python3.5
Next, update the Python alternatives list for each version you whish to use with priority 1 and 2:
update-alternatives --install /usr/bin/python python /usr/bin/python3.5 1
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2
Then run again update-alternatives --config python and select an appropriate version..
This version is no longer available in canonical mirrors.
It has been released in 2013.
As a result, having both python and pip working together since then is challenging.
Python 2.7.5 + PIP on centos7
It may be the simplest way if ubuntu is not a requirement.
CopyARG CENTOS_VERSION=7
FROM centos:$CENTOS_VERSION
# Python 2.7.5 is installed with centos7 image
# Add repository for PIP
RUN yum install -y epel-release
# Install pip
RUN yum install -y python-pip
RUN python --version
ENTRYPOINT [ "python" ]
Python 2.7.5 on ubuntu
I've been able to install it from source
It has not been a success to install pip :
https://bootstrap.pypa.io/pip/2.7/get-pip.py
CopyARG UBUNTU_VERSION=18.04
FROM ubuntu:$UBUNTU_VERSION
ARG PYTHON_VERSION=2.7.5
# Install dependencies
# PIP - openssl version > 1.1 may be an issue (try older ubuntu images)
RUN apt-get update \
&& apt-get install -y wget gcc make openssl libffi-dev libgdbm-dev libsqlite3-dev libssl-dev zlib1g-dev \
&& apt-get clean
WORKDIR /tmp/
# Build Python from source
RUN wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz \
&& tar --extract -f Python-$PYTHON_VERSION.tgz \
&& cd ./Python-$PYTHON_VERSION/ \
&& ./configure --enable-optimizations --prefix=/usr/local \
&& make && make install \
&& cd ../ \
&& rm -r ./Python-$PYTHON_VERSION*
RUN python --version
ENTRYPOINT [ "python" ]
Python 2.7.6 + pip on ubuntu
Ubuntu 14.04 still has mirrors working (how long ???).
Python packages are really close to your expectations.
You may try to run your scripts with that one.
CopyARG UBUNTU_VERSION=14.04
FROM ubuntu:$UBUNTU_VERSION
RUN apt-get update \
&& apt-get install -y python python-pip \
&& apt-get clean
RUN python --version
ENTRYPOINT [ "python" ]
Python 2.7.5 + pip, not working but could on ubuntu
Here is what I've tried with no success.
CopyARG UBUNTU_VERSION=16.04
FROM ubuntu:$UBUNTU_VERSION
# Install dependencies
RUN apt-get update \
&& apt-get install -y wget gcc make openssl libffi-dev libgdbm-dev libsqlite3-dev libssl-dev zlib1g-dev \
&& apt-get clean
WORKDIR /tmp/
# Build python from source
RUN wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz \
&& tar --extract -f Python-$PYTHON_VERSION.tgz \
&& cd ./Python-$PYTHON_VERSION/ \
&& ./configure --enable-optimizations --prefix=/usr/local \
&& make && make install \
&& cd ../ \
&& rm -r ./Python-$PYTHON_VERSION*
# Build pip from source
RUN wget https://bootstrap.pypa.io/pip/2.7/get-pip.py \
&& python get-pip.py
RUN python --version
ENTRYPOINT [ "python" ]
Python 2.7.9 with pip - as requested in comment
You can use this dockerfile, building python includes pip.
CopyARG UBUNTU_VERSION=16.04
FROM ubuntu:$UBUNTU_VERSION
ARG PYTHON_VERSION=2.7.9
# Install dependencies
RUN apt-get update \
&& apt-get install -y wget gcc make openssl libffi-dev libgdbm-dev libsqlite3-dev libssl-dev zlib1g-dev \
&& apt-get clean
WORKDIR /tmp/
# Build Python from source
RUN wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz \
&& tar --extract -f Python-$PYTHON_VERSION.tgz \
&& cd ./Python-$PYTHON_VERSION/ \
&& ./configure --with-ensurepip=install --enable-optimizations --prefix=/usr/local \
&& make && make install \
&& cd ../ \
&& rm -r ./Python-$PYTHON_VERSION*
RUN python --version \
&& pip --version
ENTRYPOINT [ "python" ]
The simplest possible solution:
Copysudo apt-get install libssl-dev openssl
wget https://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz
tar xzvf Python-2.7.5.tgz
cd Python-2.7.5
./configure
make
sudo make install
After installation completed set installed python as default one.
Hi everyone,
I'm using a laptop with Ubuntu and I have just installed Python 2.7.18 using this tutorial https://tecadmin.net/install-python-2-7-on-ubuntu-and-linuxmint/ . When I execute Python2 -V, it shows me Python 2.7.17 as the version of Python installed. However, if I execute Python2.7 -V, it shows me Python 2.7.18 as the Python version (see screenshot drive link to see the issue). What does this mean? In my (other) Windows laptop, when I execute Python2 -V, it shows me Python 2.7.18 so why doesn't it happen here in my Ubuntu laptop? Thanks in advance.
Screenshot link: https://drive.google.com/file/d/18xlyZU8eEjBb4U90RwLq8g_oKUxCO_ud/view?usp=sharing
Hi all! I just started a new job that is having me analyze/write code in Python 2. The reason it is Python 2 and not Python 3 is because we are supporting older systems that require it, and our code must be backwards compatible with these systems.
With that said, the workstation they've supplied me is running Ubuntu 24.04, and I'm at wits end as to how I can SAFELY run Python 2 code on it. From what I've gathered, recent versions of Ubuntu depend on Python 3 packages so it isn't as simple as adding a legacy apt repo and installing Python 2 - it would break my OS.
So, the question remains: How can I safely work with Python 2 without bricking my OS? Do I need to containerize or use virtualization? Thank you!
Although I have cursory experience with Ubuntu, from what I can understand from the error, you may need to reinstall the original packages as they may have not been installed correctly to begin with. Inputting the following commands may help fix the problem by reinstalling the dependencies it asks for:
sudo apt install python-minimum
sudo apt install python2.7
Also, as it says python3 is installed (not python), the first command you put in to find the version should be:
python3 --version
When you say to Ubuntu "install python", because Python 2.x and Python 3.x coexist now, "python" can be Python 2.x or 3.x. You need to explicitly designate Python 2 or 3.
Python 2 and 3 have a few incompatible differences. Error you are seeing a result of Ubuntu's apt tree is set up to not install python unless you tell it to install 2.x or 3.x Your problem should go away by "sudo apt install python2.7" or python2.7-minimal.
EDIT: BTW, if you install Ubuntu 18.04LTS Mate, python2 and python3 are both installed by default. Updating your Ubuntu to 18.04 may solve your problem as well.