I have to work with a python program that is written in python 2 (my job is to upgrade it to python 3 later, but first I need to run some tests in the current version) and have a lot of outdated packages.
I need to install the packages on my machine to make the program run. Currently I have both python 2 and 3 installed on my machine. When I run "python3 -m pip install [packageName]" it runs as it should. But when I try to run the same command using python2 instead, it gives me the message: "C:\Python27\python2.exe: No module named pip"
What can I do to install the packages on the older version of python?
For New versions
Older versions of python may not have pip installed and get-pip will throw errors. Please update your python (2.7.15 as of Aug 12, 2018).
All current versions have an option to install pip and add it to the path.
Steps:
- Open
Powershellas admin. (win+xthena) - Type
python -m pip install <package>.
If python is not in PATH, it'll throw an error saying unrecognized cmd. To fix, simply add it to the path as mentioned below[1].
[OLD Answer]
Python 2.7 must be having pip pre-installed.
Try installing your package by:
- Open cmd as admin. (
win+xthena) - Go to scripts folder:
C:\Python27\Scripts - Type
pip install "package name".
Note: Else reinstall python: https://www.python.org/downloads/
[1] Also note: You must be in C:\Python27\Scripts in order to use pip command, Else add it to your path by typing:
[Environment]::SetEnvironmentVariable("Path","$env:Path;C:\Python27\;C:\Python27\Scripts\", "User")
Download pip script from https://bootstrap.pypa.io/get-pip.py and then run using python as:-
python get-pip.py
or you can use python to install modules directly
python -m pip install <module>
how to install pip for python 2.7? - Stack Overflow
How can one install pip for python 2.7.3 on windows 10? - Stack Overflow
How to install pip on Python 2.7 in 2021 - Stack Overflow
ubuntu - How to install pip for Python 2 - Stack Overflow
Videos
pip install --upgrade "pip < 21.0"
The latest pip has dropped support for Python 2 And you cannot install the latest pip via get-pip.py using Python 2.7.
Update: Found an answer here with the script for Python 2.7 https://stackoverflow.com/a/65866547/429476.
You should upgrade to Python 3. You can use your Linux package manager if you using a Linux distro which have only Python2.7. Note - it installs an older version of Pip that that comes from above script.
If you installed Python from a package manager on Linux, you should always install pip for that Python installation using the same source. https://pip.pypa.io/en/stable/installing/ --> https://packaging.python.org/guides/installing-using-linux-tools/
# curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1883k 100 1883k 0 0 6584k 0 --:--:-- --:--:-- --:--:-- 6584k
# python get-pip.py --user
Traceback (most recent call last):
File "get-pip.py", line 24226, in <module>
main()
File "get-pip.py", line 199, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
from pip._internal.cli.main import main as pip_entry_point
File "/tmp/tmpyG_UJ3/pip.zip/pip/_internal/cli/main.py", line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
# sudo apt-get install python-pip
# python -m pip --version
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
Try installing manually:
wget -P ~/.local/lib https://bootstrap.pypa.io/pip/2.7/get-pip.py
python2.7 ~/.local/lib/get-pip.py --user
#if using bash
printf "\nPATH=\$PATH:~/.local/bin/" >> ~/.bashrc
source ~/.bashrc
In newer versions of Ubuntu such as 20.04, python-pip is no longer a package. Therefore, the old:
sudo apt install python-pip
Will fail.
Here's how to work around this issue:
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
python get-pip.py
Link: https://www.how2shout.com/linux/how-to-install-python-2-7-on-ubuntu-20-04-lts-linux/
» pip install pip
As the message says, PyPi has discontinued support for Python <2.7.9 as of May 6th 2021. If you're running a version < 2.7.9 and you cannot upgrade to a newer version of Python then your only option is to manually download the wheels from PyPi.
These are the modification I needed to make to my build script to make it work:
I needed to install software-properties-common and gcc
apt-get install -y software-properties-common gcc
Then I downloaded (setuptools](https://pypi.org/project/setuptools/44.1.1/#files) and unzipped and installed it:
python ./setuptools-44.1.1/setup.py install
Next, I downloaded pip and added it to a folder called wheels. Then I could use the whl file to run pip to get pip
python ./wheels/pip-20.3.4-py2.py3-none-any.whl/pip install --no-index --find-links ./wheels/ pip --ignore-installed
It was suggested to build a Docker container using Ubuntu 16.04 with Python 2.7.17 and use that to download the packages.
pip download -r requirements.txt
But the versions of the packages were wrong, so I ended up going through the requirements.txt and downloading each package manually from PyPi and adding it to the wheels folder. A running instance is useful so you can run pip freeze or look at a requirements.txt file to grab the version numbers of all the packages you need.
Now that I could use pip, I can install my other packages:
python pip install --no-index --find-links ./wheels/ -r /root/requirements.txt
This uncovered some dependencies that I hadn't downloaded packages for yet so I had to go through and download those and added them to the wheels folder. There were a few other things I found needed different versions than I had originally downloaded and a few packages relied on pbr and many more wanted wheel:
pip install --no-index --find-links ./wheels/ pbr==5.5.1 wheel==0.36.2
I also needed to download cMake and add it to the wheels folder
After that I could install my requirements.txt:
pip install --no-index --find-links ./wheels/ -r /root/requirements.txt --ignore-installed
May be late to the party but something similar happened to me while trying to make an HTTPS request with Python 2.7.6 (lack of SNI support). This was causing a lot of issues on a remote web server I work on.
Looking for answers I tried installing urllib3[secure] and entered a loophole since pip was complaining about a lack of SNI support to install this and other packages as well.
I found out this StackOverflow answer which helped me install the required dependencies to make Python 2.7.6 and pip itself support SNI as well as install urllib[secure].
You need to create a folder containing the required wheels (download them from PyPi using wget for instance):
pip, asn1crypto, enum34, idna, six, ipaddress, pyOpenSSL, cffi, cryptography wheels; and also pycparser (a non-wheel, it will be a tar.gz)
Make sure the wheels you download support Python 2.7 and that you install pip before the rest of them.
In the original answer, its stated you can use python -m OpenSSL.debug to verify everything worked correctly (a ModuleNotFoundError would mean the pyOpenSSL package was not installed). You can also use pip -Vto check that the new pip version was installed correctly as well.
After updating pip and installing these dependencies I was able to install urllib3[secure] and get SNI support from python as well as pip.
Good luck!
Use virtual environments. They allow you to use isolated python instances with different set of packages. Python 3 comes with venv module that lets you create one using
python -m venv venv
venv\Scripts\activate.bat
When you do this your prompt changes from d:\my_project> to (venv) d:\my_project>, so you know you're inside a virtual environment and every package you install will be isolated to that environment.
I would suggest you use a Python distribution manager. This will allow you to run multiple versions of python in isolated environments. I have environments for python 2.7, 3.6 and 3.7 that each have their own dependencies. My manger of choice is anaconda but there are a few others available.
To install pip for Python2 on Ubuntu, this worked for me
sudo apt update
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
sudo python2 get-pip.py
It's based on DareDevil7's answer but notice the url is different.
run this
python2.7 -m ensurepip --upgrade
There should be a binary called "pip2.7" installed at some location included within your $PATH variable.
You can find that out by typing
which pip2.7
This should print something like '/usr/local/bin/pip2.7' to your stdout. If it does not print anything like this, it is not installed. In that case, install it by running
$ wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
$ sudo python2.7 get-pip.py
Now, you should be all set, and
which pip2.7
should return the correct output.
An alternative is to call the pip module by using python2.7, as below:
python2.7 -m pip <commands>
For example, you could run python2.7 -m pip install <package> to install your favorite python modules. Here is a reference: https://stackoverflow.com/a/50017310/4256346.
In case the pip module has not yet been installed for this version of python, you can run the following:
python2.7 -m ensurepip
Running this command will "bootstrap the pip installer". Note that running this may require administrative privileges (i.e. sudo). Here is a reference: https://docs.python.org/2.7/library/ensurepip.html and another reference https://stackoverflow.com/a/46631019/4256346.
I will not upgrade Python, it needs to be 2.7. I am on Windows.
I don't want to really learn python, all I need is to install 1, single package and I will never be touching it again.
I keep seeing the link: https://bootstrap.pypa.io/pip/2.7/get-pip.py
but I am to dumb. Can someone do a step by step tutorial like I had 50 IQ?
Edit: Here is a picture. Maybe the pip is there, but I just don't know how to use it lol. https://i.postimg.cc/jdsfRTCP/dsadassadsdawanie.png