OS X 安装了从 python 官网下的 3.5.2 的文件,然后准备安装 scrapy ,用的 Homebrew ,碰上了系统自带版本的梗,准备卸载系统自带 python ,网上搜了教程下小手颤抖,听说卸载系统自带 2.7 版本是作死行为,于是乖乖模仿各种网上的其它教程进行尝试。。。无数次失败之后。忽然发现自己的 pip 命令失效了(到现在还不知道为毛失效。有请大神解答。。。。)
jomato-MacBook-Pro:~ xxx$ sudo pip install Scrapy
sudo: pip: command not found
于是安静地重新 get 了一遍 pip
jomato-MacBook-Pro:~ xxx$ sudo python
get-pip.pyThe directory '/Users/xxx/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.
The directory '/Users/xxx/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already up-to-date: pip in /Library/Python/2.7/site-packages
就在这个地方我忽然想起了之前安装好 pip ,直接执行 scrapy 安装命令,是调用 2.7 的版本,我如果 get python3 里面的 pip ,然后直接安装 scrapy ,系统是不是会直接调用 python3 的版本对 scrapy 进行安装呢?于是尝试了一下。
jomato-MacBook-Pro:~ xxx$ sudo python3
get-pip.pyThe directory '/Users/xxx/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.
The directory '/Users/xxx/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
Downloading pip-8.1.2-py2.py3-none-any.whl (1.2MB)
100% |████████████████████████████████| 1.2MB 1.1MB/s
Collecting wheel
Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
100% |████████████████████████████████| 71kB 5.4MB/s
Installing collected packages: pip, wheel
Found existing installation: pip 8.1.1
Uninstalling pip-8.1.1:
Successfully uninstalled pip-8.1.1
Successfully installed pip-8.1.2 wheel-0.29.0
jomato-MacBook-Pro:~ xxx$ sudo pip install Scrapy
The directory '/Users/xxx/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.
The directory '/Users/xxx/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting Scrapy
Downloading Scrapy-1.1.2-py2.py3-none-any.whl (295kB)
100% |████████████████████████████████| 296kB 1.6MB/s
Collecting cssselect>=0.9 (from Scrapy)
Downloading cssselect-0.9.2-py2.py3-none-any.whl
Collecting six>=1.5.2 (from Scrapy)
Downloading six-1.10.0-py2.py3-none-any.whl
Collecting PyDispatcher>=2.0.5 (from Scrapy)
Downloading PyDispatcher-2.0.5.tar.gz
Collecting service-identity (from Scrapy)
Downloading service_identity-16.0.0-py2.py3-none-any.whl
Collecting parsel>=0.9.3 (from Scrapy)
Downloading parsel-1.0.3-py2.py3-none-any.whl
Collecting Twisted>=10.0.0 (from Scrapy)
Downloading Twisted-16.4.0.tar.bz2 (3.0MB)
100% |████████████████████████████████| 3.0MB 392kB/s
Collecting queuelib (from Scrapy)
Downloading queuelib-1.4.2-py2.py3-none-any.whl
Collecting w3lib>=1.14.2 (from Scrapy)
Downloading w3lib-1.15.0-py2.py3-none-any.whl
Collecting lxml (from Scrapy)
Downloading lxml-3.6.4.tar.gz (3.7MB)
100% |████████████████████████████████| 3.7MB 268kB/s
Collecting pyOpenSSL (from Scrapy)
Downloading pyOpenSSL-16.1.0-py2.py3-none-any.whl (43kB)
100% |████████████████████████████████| 51kB 5.6MB/s
Collecting attrs (from service-identity->Scrapy)
Downloading attrs-16.0.0-py2.py3-none-any.whl
Collecting pyasn1 (from service-identity->Scrapy)
Downloading pyasn1-0.1.9-py2.py3-none-any.whl
Collecting pyasn1-modules (from service-identity->Scrapy)
Downloading pyasn1_modules-0.0.8-py2.py3-none-any.whl
Collecting zope.interface>=4.0.2 (from Twisted>=10.0.0->Scrapy)
Downloading zope.interface-4.2.0-cp35-cp35m-macosx_10_9_x86_64.whl (130kB)
100% |████████████████████████████████| 133kB 838kB/s
Collecting cryptography>=1.3.4 (from pyOpenSSL->Scrapy)
Downloading cryptography-1.5-cp35-cp35m-macosx_10_10_x86_64.whl (1.4MB)
100% |████████████████████████████████| 1.4MB 539kB/s
Requirement already satisfied (use --upgrade to upgrade): setuptools in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (from zope.interface>=4.0.2->Twisted>=10.0.0->Scrapy)
Collecting idna>=2.0 (from cryptography>=1.3.4->pyOpenSSL->Scrapy)
Downloading idna-2.1-py2.py3-none-any.whl (54kB)
100% |████████████████████████████████| 61kB 5.6MB/s
Collecting cffi>=1.4.1 (from cryptography>=1.3.4->pyOpenSSL->Scrapy)
Downloading cffi-1.7.0-cp35-cp35m-macosx_10_10_x86_64.whl (154kB)
100% |████████████████████████████████| 163kB 1.2MB/s
Collecting pycparser (from cffi>=1.4.1->cryptography>=1.3.4->pyOpenSSL->Scrapy)
Downloading pycparser-2.14.tar.gz (223kB)
100% |████████████████████████████████| 225kB 1.2MB/s
Installing collected packages: cssselect, six, PyDispatcher, attrs, pyasn1, idna, pycparser, cffi, cryptography, pyOpenSSL, pyasn1-modules, service-identity, lxml, w3lib, parsel, zope.interface, Twisted, queuelib, Scrapy
Running
setup.py install for PyDispatcher ... done
Running
setup.py install for pycparser ... done
Running
setup.py install for lxml ... done
Running
setup.py install for Twisted ... done
Successfully installed PyDispatcher-2.0.5 Scrapy-1.1.2 Twisted-16.4.0 attrs-16.0.0 cffi-1.7.0 cryptography-1.5 cssselect-0.9.2 idna-2.1 lxml-3.6.4 parsel-1.0.3 pyOpenSSL-16.1.0 pyasn1-0.1.9 pyasn1-modules-0.0.8 pycparser-2.14 queuelib-1.4.2 service-identity-16.0.0 six-1.10.0 w3lib-1.15.0 zope.interface-4.2.0
除去前面 python3 的安装和 Homebrew 的安装以外,就用以下两条命令即可完成,亲测可用。
sudo python3
get-pip.pysudo pip install Scrapy
虽然还没回过神来,但确实看到了 successfull 的字样,逗比的 scrapy 之旅就此开启,系统版本 OS X EI Capitan.希望对入坑的朋友有所帮助。