另一方面,pip2的安装Mac附带了python 2.7的环境,可以直接在which python上看到其安装目录:
如果在~ $ which python/system/library/frameworks/python.framework/versions/2.7/sx DDT/python中查看python2.7没有问题,请单击
~ $ sudo easy _ installpippassword : searchingforpipbestmatch 3360 pip 19.1.1 pip 19.1.1 isalreadytheactiversionineasy pion sxddtinstallingpip 3.7脚本to/usr/local/sxddtinstallingpip 3脚本to/usr/local/sxddtusiing site-packagesprocessingdependenciesforpipfinishedprocessingdependenciesforpip安装完成后,请将pip -V或pip2 -V
~ $ pip-vpip 19.2.3 from/library/python/2.7/site-packages/pip-19.2.3-py 2.7.egg/pip python 2.7 ) )
~ $ which pip/usr/local/sx DDT/pip~$ which pip2/usr/local/sx DDT/pip 2之后,只需运行pip2 install xxx,python2中的软件包就会进入
二.安装pip3的第一步:在终端上输入curl https://bootstrap.pypa.io/get-pip.py-oget-pip.py
~ $ curl https://bootstrap.pypa.io/get-pip.py-oget-pip.py % total % received % xferdaveragespeedtimetimecurrentdloaduploadtotalspentleftspeed 10017333 k 00 执行步骤3360—:—231 k sudo python3get-pip.py来安装pip3
~ $ sudo python3get-pip.py warning : thedirectory ‘/users/Xu Linzhou/library/caches/pip/http ‘ oritsparentdirectoryisnotownedbythecurrentuserandthecachehasbeendisabled.pleasecheckthepermissionsandownerofthatdirecthattdirechecthechondored sudo, youmaywantsudo ‘ s-h flag.warning : thedirectory ‘/users/Xu Linzhou/library/caches/pip ‘ oritsparentdirectoryisnotownedbythecurrentuserandcachingwheelshasbeendisabled.checkthepermissionsandownerofthatdirectod o, youmaywantsudo ‘ s-h flag.collectingpipdownloading https://files.python hosted.org/packages/30/db/9e 38760 b 32 e 3e 7f 40 CCE 46 DD D5 FB 107 b8c 73840 df 38 f 0046 D8 e 6514 e 675 a1/pip-19.2.3-py2.py3-none-any.whl 1.4 MB )
thon get-pip.py,则安装的是pip2。
第三步:执行pip -V或pip3 -V验证pip3的安装
~ $ pip -Vpip 19.2.3 from /usr/local/lib/python3.7/site-packages/pip python 3.7)~ $ pip3 -Vpip 19.2.3 from /usr/local/lib/python3.7/site-packages/pip python 3.7)
至此,pip3安装完成。这时候我们惊奇的发现,在安装pip2时,pip等同于pip2,但是在安装完pip3后,pip变成了等同于pip3。所以,以后要安装python2的包时,需要用pip2 install xxx而不是pip install xxx了。
~ $ pip -Vpip 19.2.3 from /usr/local/lib/python3.7/site-packages/pip python 3.7)~ $ pip2 -Vpip 19.2.3 from /Library/Python/2.7/site-packages/pip python 2.7)~ $ pip3 -Vpip 19.2.3 from /usr/local/lib/python3.7/site-packages/pip python 3.7) 三、如何卸载pip2和pip3
如果只安装了pip2,这时候pip等同于pip2,所以卸载时可以执行sudo pip uninstall pip或sudo pip2 uninstall pip
~ $ sudo pip2 uninstall pipPassword:WARNING: The directory ‘/Users/xulinzhou/Library/Caches/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.Uninstalling pip-19.2.3: Would remove: /usr/local/sxddt/pip /usr/local/sxddt/pip3 /usr/local/sxddt/pip3.7 /usr/local/lib/python3.7/site-packages/pip-19.2.3.dist-info/* /usr/local/lib/python3.7/site-packages/pip/*Proceed y/n)? y Successfully uninstalled pip-19.2.3
卸载pip3的方式和卸载pip2的类似,执行sudo pip3 uninstall pip即可。实际上sudo pip uninstall pip命令则取决于这时候的pip等效于pip2还是pip3,可以通过pip -V查看。题主这里安装完pip3后的pip此时等效的是pip3,未安装pip3之前,pip等效于pip2。
四、如何升级pip2和pip3
执行pip2 install –upgrade pip可升级pip2,如下:
~ $ pip2 install –upgrade pipDEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-supportRequirement already up-to-date: pip in /Library/Python/2.7/site-packages 19.2.3)
执行pip3 install –upgrade pip可升级pip3,如下:
~ $ pip3 install –upgrade pipRequirement already up-to-date: pip in /usr/local/lib/python3.7/site-packages 19.2.3)
同理卸载,升级执行pip install –upgrade pip时,取决于这时候pip等效于pip2还是pip3。
五、切换pip等效成pip2或pip3
如果需要将pip改成等效成pip2,执行sudo vim /usr/local/sxddt/pip,把第一行的改成:#!/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python即可。如下:
#!/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python# -*- coding: utf-8 -*-import reimport sysfrom pip._internal import mainif __name__ == ‘__main__’: sys.argv[0] = re.subr’-script\.pyw?|\.exe)?$’, ”, sys.argv[0]) sys.exitmain))
如果需要将pip改成等效成pip3,执行sudo vim /usr/local/sxddt/pip,把第一行的改成:#!/usr/local/opt/python/sxddt/python3.7即可。如下:
#!/usr/local/opt/python/sxddt/python3.7# -*- coding: utf-8 -*-import reimport sysfrom pip._internal import mainif __name__ == ‘__main__’: sys.argv[0] = re.subr’-script\.pyw?|\.exe)?$’, ”, sys.argv[0]) sys.exitmain))
这样,可以自由切换pip等效成pip2或pip3。