声明:所有操作均是在mac OS 环境下
1. Python2的第三方库安装
Python2默认没有安装pip工具,但是安装的easy_install,我们可以用easy_install安装pip,在用pip安装其他的第三方库。
bogon:~ evan$ sudo easy_install pip
Searching for pip
Reading https://pypi.python.org/simple/pip/
Best match: pip 9.0.1
Downloading https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
Processing pip-9.0.1.tar.gz
Writing /tmp/easy_install-ilu_ZT/pip-9.0.1/setup.cfg
Running pip-9.0.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-ilu_ZT/pip-9.0.1/egg-dist-tmp-u5uG4o
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'
warnings.warn(msg)
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching '.mailmap'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files found matching '.landscape.yml'
warning: no previously-included files found matching 'pip/_vendor/Makefile'
warning: no previously-included files found matching 'tox.ini'
warning: no previously-included files found matching 'dev-requirements.txt'
warning: no previously-included files found matching 'appveyor.yml'
no previously-included directories found matching '.github'
no previously-included directories found matching '.travis'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'contrib'
no previously-included directories found matching 'tasks'
no previously-included directories found matching 'tests'
creating /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg
Extracting pip-9.0.1-py2.7.egg to /Library/Python/2.7/site-packages
Adding pip 9.0.1 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/bin
Installed /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip
或者也可以直接用easy_install下载第三方库。
bogon:~ evan$ sudo easy_install selenium
Password:
Searching for selenium
Reading https://pypi.python.org/simple/selenium/
Best match: selenium 3.5.0
Downloading https://pypi.python.org/packages/ac/d7/1928416439d066c60f26c87a8d1b78a8edd64c7d05a0aa917fa97a8ee02d/selenium-3.5.0.tar.gz#md5=986702fdd0e2aec6a4eda134678b8b3f
Processing selenium-3.5.0.tar.gz
Writing /tmp/easy_install-8JkREp/selenium-3.5.0/setup.cfg
Running selenium-3.5.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-8JkREp/selenium-3.5.0/egg-dist-tmp-TSB9ds
warning: no files found matching 'selenium/selenium.py'
warning: no files found matching 'LICENSE'
creating /Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg
Extracting selenium-3.5.0-py2.7.egg to /Library/Python/2.7/site-packages
Adding selenium 3.5.0 to easy-install.pth file
Installed /Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg
Processing dependencies for selenium
Finished processing dependencies for selenium
bogon:~ evan$
2. python3的第三方库安装:
bogon:~ evan$ which python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
bogon:~ evan$
bogon:~ evan$ which pip3
/usr/bin/which
/Library/Frameworks/Python.framework/Versions/3.6/bin/pip3
bogon:~ evan$ pip3 install pymysql
Collecting pymysql
Downloading PyMySQL-0.7.11-py2.py3-none-any.whl (78kB)
100% |████████████████████████████████| 81kB 42kB/s
Installing collected packages: pymysql
Successfully installed pymysql-0.7.11
bogon:~ evan$ pip3 -help
Usage:
pip <command> [options]
Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
check Verify installed packages have compatible dependencies.
search Search PyPI for packages.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion.
help Show help for commands.
General Options:
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring
environment variables and user configuration.
-v, --verbose Give more output. Option is additive, and can be
used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output. Option is additive, and can be
used up to 3 times (corresponding to WARNING,
ERROR, and CRITICAL logging levels).
--log <path> Path to a verbose appending log.
--proxy <proxy> Specify a proxy in the form
[user:passwd@]proxy.server:port.
--retries <retries> Maximum number of retries each connection should
attempt (default 5 times).
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists:
(s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
--trusted-host <hostname> Mark this host as trusted, even though it does
not have valid or any HTTPS.
--cert <path> Path to alternate CA bundle.
--client-cert <path> Path to SSL client certificate, a single file
containing the private key and the certificate
in PEM format.
--cache-dir <dir> Store the cache data in <dir>.
--no-cache-dir Disable the cache.
--disable-pip-version-check
Don't periodically check PyPI to determine
whether a new version of pip is available for
download. Implied with --no-index.
3. 卸载第三方库
pip uninstall pymysql
pip3 uninstall pymysql