Skip to content Skip to sidebar Skip to footer

Using Pip On Windows Installed With Both Python 2.7 And 3.5

I am using Windows 10. Currently, I have Python 2.7 installed. I would like to install Python 3.5 as well. However, if I have both 2.7 and 3.5 installed, when I run pip, how do I g

Solution 1:

You will have to use the absolute path of pip.

E.g: if I installed python 3 to C:\python35, I would use: C:\> python35\Scripts\pip.exe install packagename

Or if you're on linux, use pip3 install packagename

If you don't specify a full path, it will use whichever pip is in your path.

Solution 2:

Because usually i change my intepreter to run something(i got 2 diff projects with both 2 and 3), i use these solution:

  1. Add path to the environment as usual (of course)
  2. Rename ur python.exe , in my case i want to run python 3 using command python3 on my cmd. So i renamed my python.exe in python3.x directory with python3. Itll works with python 2 ofc.
  3. Then to use pip in both python, i use this command.

python3 -m pip install 'somepackage'

and to run pip on python2

python -m pip install 'somepackage'

This is may not the best solution out there, but i like this one

** WINDOWS **

ref : https://datascience.com.co/how-to-install-python-2-7-and-3-6-in-windows-10-add-python-path-281e7eae62a

Solution 3:

In my case, I have Python 2.7 and Python 3.4, with the Python Launcher for Windows.

This is the output when running this commands:

PS C:\> pip -V
pip 9.0.1from c:\python27\lib\site-packages (python 2.7)  

PS C:\> pip3 -V
pip 9.0.1from C:\Python34\lib\site-packages (python 3.4)  

I'll note that in my Python27\Scripts\ directory, I have pip.exe, pip2.exe and pip2.7.exe. And in my Python34\Scripts\ directory, I have pip.exe, pip3.exe and pip3.4.exe. So all of these .exe files help you when you have different versions of Python installed at the same time.

Of course, for this to work, you have to have the respective Scriptsdirectries in your Path system enviroment variable.

Solution 4:

The answer from Farhan.K will work. However, I think a more convenient way would be to rename python35\Scripts\pip.exe to python35\Scripts\pip3.exe assuming python 3 is installed in C:\python35.

After renaming, you can use pip3 when installing packages to python v3 and pip when installing packages to python v2. Without the renaming, your computer will use whichever pip is in your path.

Solution 5:

I would advise against ever calling any pip script directly (nor pip3, pip2.7.exe, anything like that).

Instead, a surefire way is to always prefer the explicit variant of calling pip's executable module for a specific Python interpreter:

  • path/to/pythonX.Y -m pip somecommand
  • path/to/venv/bin/python -m pip somecommand
  • C:\path\to\venv\Scripts\python.exe -m pip somecommand

There are many advantages to this, for example:

  • It is explicit for which Python interpreter the projects will be pip-installed (Python 2 or 3, inside the virtual environment or not, etc.)
  • For a virtual environment, one can pip-install (or do other things) without activating it: path/to/venv/bin/python -m pip install SomeProject
  • Under Windows this is the only way to safely upgrade pip itself path\to\venv\Scripts\python.exe -m pip install --upgrade pip

But yes, if all is perfectly setup, then python3 -m pip install SomeProject and pip3 install SomeProject should do the exact same thing, but there are way too many cases where there is an issue with the setup and things don't work as expected and users get confused (as shown by the many questions about this topic on this platform).

References

Post a Comment for "Using Pip On Windows Installed With Both Python 2.7 And 3.5"