Résoudre le problème de pip3 correspondant à python2 sous mac (problème de pointage pip)

Résoudre le problème de pip3 correspondant à python2 sous mac (problème de pointage pip)

La même chose peut résoudre le problème de pip correspondant à Python3.


Un, le problème

Vérifiez les versions de pip et pip3 sous mac, la version Python correspondant à pip3 est 2.7

image-20201221215802703

Dans des circonstances normales, cela devrait être: pip correspond à Python2 et pip3 correspond à Python3.

Deux, résolvez

Utilisez lequel pour afficher le chemin absolu de la commande pip.

~ » which pip                
/usr/local/bin/pip

L'utilisation d'easy_install pour installer pip dans mac fera à la fois pip et pip3 devenir pip

~ » sudo easy_install pip                 littlechieh6@bogon
Password:
Searching for pip
Best match: pip 20.2b1
Processing pip-20.2b1-py2.7.egg
pip 20.2b1 is already the active version in easy-install.pth
Installing pip script to /usr/local/bin
Installing pip3.8 script to /usr/local/bin
Installing pip3 script to /usr/local/bin

Using /Library/Python/2.7/site-packages/pip-20.2b1-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip
-------------------------------------------------------------
~ » pip3 --version                        littlechieh6@bogon
pip 20.2b1 from /Library/Python/2.7/site-packages/pip-20.2b1-py2.7.egg/pip (python 2.7)
-------------------------------------------------------------
~ » pip --version                         littlechieh6@bogon
pip 20.2b1 from /Library/Python/2.7/site-packages/pip-20.2b1-py2.7.egg/pip (python 2.7)

Ou utilisez le script get-pip.py sur le site Web bootstrap.pypa.io pour installer pip3, ce qui fera à la fois pip et pip3 devenir pip3

~/Desktop » curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:  1 1842k    1 20565    0     0  43294      0  0:00:43 --:--: 50 1842k   50  935k    0     0   626k      0  0:00:02  0:00:100 1842k  100 1842k    0     0   848k      0  0:00:02  0:00:02 --:--:--  848k
-------------------------------------------------------------
~/Desktop » sudo python3 get-pip.py
-------------------------------------------------------------
~/Desktop » pip --version                 littlechieh6@bogon
pip 20.3.3 from /Library/Python/3.8/site-packages/pip (python 3.8)
-------------------------------------------------------------
~/Desktop » pip3 --version                littlechieh6@bogon
pip 20.3.3 from /Library/Python/3.8/site-packages/pip (python 3.8)

Afficher l'emplacement d'exécution de Python2 et Python3

~ » which python3                         littlechieh6@bogon
/usr/bin/python3
-------------------------------------------------------------
~ » which python                          littlechieh6@bogon
/usr/bin/python
-------------------------------------------------------------
~ » ls -al /usr/bin/python3               littlechieh6@bogon
-rwxr-xr-x  1 root  wheel  31488 Sep 22 08:29 /usr/bin/python3
-------------------------------------------------------------
~ » ls -al /usr/bin/python                littlechieh6@bogon
lrwxr-xr-x  1 root  wheel  75 Jul  1 08:44 /usr/bin/python -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7

Afficher l'emplacement d'exécution de pip

~ » which pip                             littlechieh6@bogon
/usr/local/bin/pip
-------------------------------------------------------------
~ » which pip3                            littlechieh6@bogon
/usr/local/bin/pip3
-------------------------------------------------------------
~ » ls -al /usr/local/bin/pip             littlechieh6@bogon
-rwxr-xr-x  1 root  admin  263 Dec 21 22:56 /usr/local/bin/pip
-------------------------------------------------------------
~ » ls -al /usr/local/bin/pip3            littlechieh6@bogon
-rwxr-xr-x  1 root  admin  263 Dec 21 22:56 /usr/local/bin/pip3

Le point clé des scripts originaux pip et pip3 est de #!représenter le chemin pour exécuter le script. Puisque pip et pip3 sont exécutés par python3, utilisez pip -Vetpip3 -V

#!/Applications/Xcode.app/Contents/Developer/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

Utilisez vim /usr/local/bin/pippour pointer l'interpréteur vers Python2

#!/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

Trois, l'effet

~ » pip -V                                littlechieh6@bogon
pip 20.2b1 from /Library/Python/2.7/site-packages/pip-20.2b1-py2.7.egg/pip (python 2.7)
-------------------------------------------------------------
~ » pip3 -V                               littlechieh6@bogon
pip 20.3.3 from /Library/Python/3.8/site-packages/pip (python 3.8)

Tutoriel de référence:

  1. https://blog.csdn.net/u014259820/article/details/100580970

Je suppose que tu aimes

Origine blog.csdn.net/qq_43085611/article/details/111502620
conseillé
Classement