-1

Currently i have python2.7 with pip v9.0.1 routed on this location c:\python27\lib\site-packages (python 2.7)

Now when i installed python3.6 using installation wizard, it messed up. running python on cmd always refers to python3.

$ python
Python 3.6
>>> 

To solve i need to do this:

$ set-alias py2 c:\python27\python.exe 
$ set-alias py3 c:\python36\python.exe

Now how can i do the same way for pip? python3 has its own pip installed from the wizard. when running pip and pip3 it always yield this result

$ pip
pip 9.0.1 from c:\python36\lib\site-packages (python 3.6)

$ pip3
pip 9.0.1 from c:\python36\lib\site-packages (python 3.6)
Shift 'n Tab
  • 8,808
  • 12
  • 73
  • 117
  • If this is a problem on Ubuntu, the proper way is a program called `alternatives`, which is a soft-link manager that keeps track of versioning options of a set of softwares. I use it all the time in `source activate XX` scripts. Not sure if there is similar tool for Windows. – Patrick the Cat Jan 18 '18 at 14:05
  • In the Unix world, this is often resolved by having the triple (`pip`, `pip2`, `pip3`) where `pipN` points to the package manager for `pythonN` and `pip` points to whatever Python `python` points. Check if you have `pip2` alias, if not, create one pointing to (I guess) `c:\python27\bin\pip.exe`. – hoefling Jan 18 '18 at 14:15
  • @hoefling mind to share the command to map specific pipN to pythonN? not in unix but windows – Shift 'n Tab Jan 18 '18 at 14:16
  • This is only a semantic mapping, not something you do with a command. You already have `pip3` pointing to pip for `python3` and `pip` pointing to `pip3`, all that is left is to set `pip2` alias for `python2`'s pip - find out the path to its executable and use `set-alias` the way you did in your question. – hoefling Jan 18 '18 at 14:26

1 Answers1

1

The easy solution on Windows is to use the -m option through the corresponding python executable. The only requirement then is that you have the python executables separate, which you seem to have already found a solution for.

py2 -m pip install somemodule
py3 -m pip install somemodule

If you need to make the separate executables work, my quick and dirty fix for that is to copy the corresponding executables, rename them to py2/py3 or python2/python3, then put them in the C:\Windows folder. They will work in a new cmd session after that.

To make separate executables in a more organized fashion, copy executables for python 2 and 3 into a folder in the C:\Users\eraw\AppData\Local\Programs\Python\executables folder, rename them in whatever way best suits you (py,python,python2,python3, etc.), then add that folder to the windows path variable by going to my computer(Windows 7) or this pc(Windows 10) -> Advanced settings -> Environment Variables -> Edit path variable. Be careful on Windows 7 and earlier to use a semicolon and NOT USE ANY SPACES.

Evan
  • 2,120
  • 1
  • 15
  • 20
  • i ran with this same answer and yes it is, i was able to find i can use pip2 and pip3 it solve the problems however set-alias is not persistent whenever i try to do py3 or py2 it wont work unless is set again – Shift 'n Tab Jan 18 '18 at 14:29
  • It seems i have to rename python27\python.exe to python2 and python36\python.exe to python3 and add their location to the path env. – Shift 'n Tab Jan 18 '18 at 14:32
  • Ok, my quick and dirty fix for the executables is to copy the corresponding executables, rename them to py2/py3 or python2/python3, then put them in the C:\Windows folder. Restart cmd then try them out. – Evan Jan 18 '18 at 14:32
  • yeah lot of thanks, i already did, you may add that as your answer – Shift 'n Tab Jan 18 '18 at 14:33
  • If you want it to be cleaner, I make a folder in C:\Users\username\AppData\Local\Programs\Python called executables, add all the executables there and add it to path. – Evan Jan 18 '18 at 14:34
  • Edited my original post to provide instructions on getting separate execuables working. – Evan Jan 18 '18 at 14:41