3

I am aware that this kind of question has been asked many times. I even found out this almost identical issue: How to use pip3 for python 3.6 instead of python 3.5? But I still yet get my problem solved. I am using os x.

I have three versions of pythons: 2.7, 3.6 and 3.7.

python --version
Python 2.7.10

python3 --version
Python 3.7.4

but if I do

pip3 --version
pip 9.0.1 from /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (python 3.6)

I do not know why pip3 is pointed to 3.6 not 3.7 (while python3 gives me 3.7)

if I do

python3 
import site; site.getsitepackages()

I have

['/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages']

PIP3 pointed to python 3.6 instead of 3.7. How do I make it point to python 3.7?

I try add python3 to the path but to no avail. I do not want to uninstall python 3.6.

Frostless
  • 818
  • 1
  • 11
  • 33

3 Answers3

6

Make a habit of using the following;

python -m pip install <package> # and you will be sure to have the package attached with the right version of python

Eg:-

$ python3 -m pip install requests
han solo
  • 6,390
  • 1
  • 15
  • 19
  • thanks for this. but what if I still want pip3 --version associated with pyhthon 3.7 not 3.6? – Frostless Aug 25 '19 at 11:31
  • There's no point in wanting that. But anything is possible. You could symlink it after installing the the latest `python3-pip`, if your distribution provide one. But using the `-m` option with `pip` module is exactly the why it exists. It make sure your packages are tied with the correct python :) – han solo Aug 25 '19 at 11:45
  • Follow han's advice, avoid the `pip` or `pip3` or whatever scripts as much as possible. Prefer using _pip_'s executable module instead: `path/to/pythonX.Y -m pip`. For some more background info: https://snarky.ca/why-you-should-use-python-m-pip/ – sinoroc Mar 18 '20 at 09:35
1
$ which pip3
/usr/bin/pip3 

$ nano /usr/bin/pip3

At first line of the file, you should see

#!/usr/bin/python3

Just change it to the python version you want.

#!/usr/bin/python3.7
or
#!/usr/bin/python3.8

Save it. Done!

Coco Golden
  • 21
  • 1
  • 1
  • This worked for me, with the difference being that the new shebang that worked for me was `#!/usr/local/bin/python3` as I had recently switched from Canonical's `python3` to the one built from the current source downloaded from python.org. – Lori Aug 08 '22 at 21:12
-1

I ended up using this in the bash_profile

alias pip3='/usr/local/bin/python3 -m pip'
Frostless
  • 818
  • 1
  • 11
  • 33