how to run pip for python 3 and python 2 - python

I have two versions of python installed on my machine (Ubuntu 14.xx LTE) as well as two versions of pip (one for python 2 and one for python 3). When I run pip --version on the command line I get the following output: pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7). I looked into this directory and it has many other things in it. However I couldn't find pip.py in it. How do I run pip for python 3? Any help is appreciated.

To use another version of pip for python on ubuntu, you can use the python major version after pip. For Example:
pip --version
will return the default version of pip
pip2 --version
will use the Python 2 version of pip, and
pip3 --version
will use Python 3.
Hope this helped!

rename your python.exe for python 3 to python3. Don't forget to put it inside your PATH environment. Just use python for python 2, python3 for python 3.
Their pip are separated, pip for python 2. pip3 for python 3.

Related

Can I uninstall python2 from macos?

My mac has python3 and python2 installed by default.
Before now, only python3 and pip3 commands were working on the macOS terminal. But when I upgraded my pip pip3 install --upgrade pip, my pip command works as well, and when I type python --version it shows 2.7.16. Although I still have python3 installed, I don't like having python2. Can I uninstall python2 or is it just not possible?
Keep in mind that the python --version command showed an error before I upgraded pip
If Python 2 was installed onto your Mac by default, do NOT try to remove it as it is not possible, and could break your entire operating system.
As #GavinWong said, do not try to remove Python 2 from your Mac. Some of the scripts used by the operating system are written in Python 2 and hence Python 2 must be available for Mac to fubtion properly.

How do I deal with pip in different python versions?

I had python 3.8 installed and then I installed python 2.7. I am trying to run a python program with py -2 program.py in vs code using with python 2.7 as selected environment and I am getting an error, ImportError: No module named googlemaps even though I have already installed.
If I run the program using Python3 then it would run fine. Also when I open vs code using python 2.7 as selected runtime environment then I would get a warning Linter Pylint is not installed. If I click on install then I would get another warning There's no Pip installer available in the selected environment.
Also even though I have changed the python path from 3.7 to 2.7, default python version will still show up as 3.7 when I runPython in command line.
Things that I have tried to install the googlemaps module for python 2 after googling for solutions,
pip2 install googlemaps--upgrade
py -2 -m pip install googlemaps
If you have your python2 binary located, you can just call it directly:
/usr/bin/python2 -m pip install googlemaps
And if you're not sure where your python binary is, you can use
import sys
print(sys.executable)
to locate it.
And if you don't have pip, you should install it by downloading this file:
https://bootstrap.pypa.io/get-pip.py
then running:
/usr/bin/python2 get-pip.py
It is recommended to install Python 3.8 using Pyenv and also when you are using different versions of python, it is very useful
curl https://pyenv.run | bash
pyenv install 3.8.1
pyenv virtualenv 3.8.1 venv
pyenv local venv
with pyenv local you set your version for use.
If after this you run
pyenv version
It will output to 3.8.1
With regards to pip installation, run
whereis python
and if it outputs to
usr/bin/python2
then you can use pip for installing python2 packages and pip3 for packages compatible to python3.

numpy got installed in Python3.5 but not in Python3.6

I have both Python 3.5 and Python 3.6 on my laptop. I am using Ubuntu 16.04. I used pip3 to install numpy. It is working with Python3.5 but not with Python3.6. Please help.
To install via pip for specific python version use:
py -(python-version) -m pip install numpy
in your case
py -3.6 -m pip install numpy
Make sure that your Python is Python 3.6:
python --version
Python 3.6.4
Now install with:
python -m pip install numpy
This will run the pip for the current Python the option -m imports the module pip and runs it as it would be pip as command line app.
Cannot comment since I don't the rep.
If your default python is 3.5 when you check python --version, the way to go would be to find the location of the python executable for the desired version (here 3.6).
cd to that folder and then run the command given by Mike.

How to change Python version in which modules get installed?

I'm trying to install Python-Twitch for Python 3.4. I have both 3.4 and 3.5 installed on my computer, and in command prompt I do this:
python --version
Where it gives me Python 3.5.x. Then:
set PATH=C:\Python34\;%PATH%
And python --version will then read Python 3.4.x.
Once I do 'pip install python-twitch', it installs it to the Python 3.5 Lib/Site-Packages folder. How would I get this over to 3.4?
Thanks so much for any help.
I think this was already answered: pip: dealing with multiple Python versions?
Since version 0.8, Pip supports pip-{version}. You can use it the same as easy_install-{version}:
$ pip-2.5 install myfoopackage
$ pip-2.6 install otherpackage
$ pip-2.7 install mybarpackage
EDIT: pip changed its schema to use pipVERSION instead of pip-VERSION in version 1.5. You should use the following if you have pip >= 1.5:
$ pip2.6 install otherpackage
$ pip2.7 install mybarpackage
Check https://github.com/pypa/pip/pull/1053 for more details

How to pip install packages into different versions of Python

I have 2 Python versions
Python 3.4.3
Python 2.7.10
Env variable works with Python 3.4(in my system), so when I pip install*package_name it will only install the package into Python 3.4
I have a system variable for Python 2.7 -- %python27% -- also.
My question is; how can I pip install a package/module into Python 2.7 without changing the Env. Variable.
Note: %python27% pip install *package_name doesn't work.
Thank you.
You should have multiple executables of pip.
Use pip2 and pip3 interchangeably.
Anyway, you should consider using virtualenv package, initialize it like virtualenv -p /usr/bin/python2.7 env_name or virtualenv-3.4 -p /usr/bin/python3.4 env_name then each time you use your code, type source env_name/bin/activate and "python" should be aliased to virtualised version.
You can use pip for python2 and pip3 for python3.
Also you can try using virtualenv or pyenv
I had the same problem, but it was installing to Python 2.7 rather than Python 3.4. Using $ pip3 install *package_name solved the issue.

Categories

Resources