1

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.

kame
  • 16,824
  • 28
  • 95
  • 142
  • and what do you get when you run `python2 --version`? – M.T May 24 '16 at 11:02
  • ​​​​​​​​​​​​​​​What's the system you're using? Did you try `pip2 install SomePackage`? Also, try `whereis python2` and `env python2`? – Casimir Crystal May 24 '16 at 11:03
  • @M.T I already wrote: Python2 is not found. – kame May 24 '16 at 11:04
  • @Kevin I use Windows – kame May 24 '16 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 – ZeusNet May 24 '16 at 11:06
  • @Kevin whereis and env were also not found. :/ – kame May 24 '16 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](https://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-7). – Casimir Crystal May 24 '16 at 11:10
  • I added the missing C:\Python2.7 to my Path, but I still can't run pip2 or python2. pip3 is working, but I need pip2. – kame May 24 '16 at 11:20

3 Answers3

2

Under windows you have to use:

py -2 yourfilename  // for python2.x
py -3 yourfilename  // for python3.x
kame
  • 16,824
  • 28
  • 95
  • 142
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.

kame
  • 16,824
  • 28
  • 95
  • 142
M.T
  • 3,749
  • 4
  • 24
  • 46
  • I installed python2.7. I have it in my path but pip2 is still not running. – kame May 24 '16 at 11:21
  • @kame I assume you have installed pip on python2? If not check out [this](http://stackoverflow.com/a/12476379/5422525) – M.T May 24 '16 at 11:36
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.

James K. Lowden
  • 6,629
  • 1
  • 13
  • 28