2

I have to use Python2 for the following command: python2 -m pip install SomePackage in the command line. I get the message that Python2is not found, but I have definitly installed Python 2.7.1.

When I run python --version I get the output Python 3.5.1.

Edit: I use Windows. And the commands whereis and env were also not found.

8
  • and what do you get when you run python2 --version? Commented May 24, 2016 at 11:02
  • ​​​​​​​​​​​​​​​What's the system you're using? Did you try pip2 install SomePackage? Also, try whereis python2 and env python2? Commented May 24, 2016 at 11:03
  • @M.T I already wrote: Python2 is not found. Commented May 24, 2016 at 11:04
  • 2
    @kame That means there is no python2 command in your path variable. Add the pyhton2 path to your Path variable in windows. This should fix the problem Commented May 24, 2016 at 11:06
  • 1
    @kame: ​​​​​​​​​​​​​​​Well, these are Linux commands...However, where did you install Python? Try run Python from there? And as ZeusNet said, check out this question. Commented May 24, 2016 at 11:10

3 Answers 3

2

Under windows you have to use:

py -2 yourfilename  // for python2.x
py -3 yourfilename  // for python3.x
Sign up to request clarification or add additional context in comments.

Comments

1

If you really have installed python2.x and it is on your path, you can ensure that you are installing for python2 by running

pip2 install somepackage

Equivalently you can run

pip3 install somepackage

to ensure that it is installed on python3.x.

This can become a bit messy/tedious in the long run, so it might be worth looking into using virtual environments, or something like miniconda which tend to handle this quite well.

2 Comments

I installed python2.7. I have it in my path but pip2 is still not running.
@kame I assume you have installed pip on python2? If not check out this
0

The canonical way to find out where a command is found on the path with with the Bourne shell built-in,

$ command -v python
/usr/local/anaconda/bin/python

(BTW, don't use which; let the shell tell you what it's doing.)

It could easily be that Python2 is on your path, but later in the list than the one that's being found. It could also be that the shell's cache of found executables needs updating:

$ help hash
hash: hash [-lr] [-p pathname] [-dt] [name ...]
Remember or display program locations.
...
  -d                forget the remembered location of each NAME

$ hash -d python; command -v python
/usr/local/anaconda/bin/python

To display the path in a more friendly way:

$ echo $PATH | tr :  \\n 
/usr/local/anaconda/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games

You may want to re-arrange your path. Another trick I sometimes use is to rename the system-provided executable, perhaps by capitalizing it, so it's still available but won't be found without special effort.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.