I have python2 and python3 both. When I run

pip --version 

pip 21.0.1 from /home/istiak/.local/lib/python3.9/site-packages/pip (python 3.9)

└─$ python2 --version     
    Python 2.7.18

I have some code of Python2. Which written in weird way ~ I think bash. Here's the git repo. So, I want to run the project by python2 while I run the program by python3 I get the following error

SyntaxError: Missing parentheses in call to 'print'. Did you mean print("""


I could fix them. While they are written in weird way. So, how can I edit them..? That's why I want to run that program by python2. When I run the program by python2 I get an error ImportError: No module named mechanize. I have mechanize installed in Python3. When I try to install by pip2. I get following error

Command 'pip2' not found, did you mean: command 'pip' from deb python3-pip command 'nip2' from deb nip2 command 'pip3' from deb python3-pip Try: sudo apt install

I tried to install pip2 also. sudo apt-get install python2. sudo apt-get install python2-pip. Although I am not getting pip2. How can I install mechanize in python2?

2 Answers 2


Answer for Ubuntu.

Command 'pip2' not found

You need to install pip2 (packaged for Ubuntu Xenial and Bionic):

sudo apt install python-pip

Or use the following command (Other than Xenial and Bionic):

sudo apt install python2   # already done
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
sudo python2 get-pip.py

To install mechanize:

pip2 install mechanize


python2 -m pip install mechanize
  • It worked.. But, Could you please explain the curl command..? I know that it copy and paste/download and save the file... But, I don't know how curl works(I think something like git clone).. Apr 12, 2021 at 7:56
  • @GameStakes curl will download file from the specified URL then using the --output option, it will save the downloaded file to get-pip.py.
    – GAD3R
    Apr 12, 2021 at 7:59

pip2 is not included in the package repository of certain distros (including Ubuntu 20.04) already. To install, run this script as sudo.

Also, the script seems not in bash, but rather just the old Python 2, which uses the print statement instead of its function counterpart in Python 3. If this is the only problem, you can just use a regex to replace the lines.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .