-1

I installed many packages by pip and pip3, I am still confused which to use and what is the difference. (At first I was using python (2.x version), now mostly python3) In same question Should I use pip or pip3? there is answer to use python3 -m pip or python -m pip (I think I did not know about this, so never used it). How you can tell if you use the first one or the other? Is it the same as using pip3 or pip? Now I am mostly using python3 over python, does it mean that packages installed via pip are now useless? If there is advice for some package to install it by: pip install "some package" does it actually mean: use pip for the python version you use? I usually try both options - so I install some packages via pip and pip3 (trying what does not make error). Is it possible that single python program imports python(2) and python3 packages at the same time? (Im working on Ubuntu 16.04 and Kubuntu 18.04)

weatherman
  • 100
  • 1
  • 12
  • 4
    Does this answer your question? [pip or pip3 to install packages for Python 3?](https://stackoverflow.com/questions/40832533/pip-or-pip3-to-install-packages-for-python-3) – Czaporka Dec 20 '20 at 10:33
  • I am not sure... :-) At least commands ```ls -l `which pip` ``` and ```pip show pip``` are useful and showing me I am using the same thing. – weatherman Dec 20 '20 at 11:04

2 Answers2

2

You have asked a lot of questions... here are your answers:

Q. How you can tell if you use the first one or the other?

A. Use the command pip --version and pip3 --version.

Q. Is it the same as using pip3 or pip?

A. Yes, if both of the above commands gives the same result; no, if otherwise.

Q. Now I am mostly using python3 over python, does it mean that packages installed via pip are now useless?

A. Yes, python2 and python3 aren't backwards compatible, all the new code that you are writing doesn't work with python2; however, be careful while deleting stuff, you could break some code somewhere due to accident.

Q. If there is advice for some package to install it by: pip install "some package" does it actually mean: use pip for the python version you use?

A. Refer to answer 1.

Q. Is it possible that single python program imports python(2) and python3 packages at the same time?

A. No, it doesn't work that way. Check the links in the comments.

tripleee
  • 175,061
  • 34
  • 275
  • 318
tsamridh86
  • 1,480
  • 11
  • 23
2

does it actually mean: use pip for the python version you use?

Yes, absolutely. That is the important thing to remember. Also very important: projects (libraries, applications, dependencies, requirements, packages) are always installed for one specific Python interpreter version. They are not shared. So you could potentially have multiple Python 3.8 on the same machine for example. Some could be in virtual environments, some not. That is why it is extremely important to make sure to use pip for the correct Python interpreter you are targeting. I recommend going all the way and using:

/path/to/pythonX.Y -m pip install Something

Once you are perfectly confident that using a shorter form such as pythonX.Y -m pip, or python -m pip ... will work with the exact Python interpreter you have in mind, then and only then you can use the shorter versions (pipX.Y ..., or pip ..., those I do not recommend at all, unless you are absolutely sure, which is almost never, since the pip scripts can be overwritten to point to a different Python interpreter).

Note that you probably should use virtual environments, and this also of course works perfectly with virtual environments (even when they are not "activated"):

path/to/venv/bin/python -m pip install Something

For virtual environments, I would say it safe-ish to go directly for the pip script:

path/to/venv/bin/pip install Something

You should read this:

sinoroc
  • 18,409
  • 2
  • 39
  • 70