pip安装第三方包
1 Python pip指令簡述
Python中安裝第三方包需要使用pip命令,該命令在Python3中自帶,不必額外安裝。
打開Python安裝路徑,進入“Scripts”文件夾,即可看到pip.exe命令。
進入CMD命令窗口即可執行pip命令。
pip查看現在機器上所安裝的第三方包:
1 pip list #該語句現在準備廢棄,不建議使用 2 pip freeze #建議使用該語句
pip安裝第三方包(XX為包名):
1 pip install XX
如果安裝過程中下載速度太慢而導致出現“read timed out”錯誤,請使用下面語句:
1 pip --default-timeout=100 install XX
【特殊的】在安裝tensorflow時使用下面的語句:
1 pip install --upgrade --ignore-installed tensorflow
pip安裝第三方包所在路徑為:
Windows是python目錄下Libsite-packages
有時使用過程中會提示pip版本太低,需要升級,使用pip升級指令:
1 python -m pip install --upgrade pip
pip刪除第三方包(XX為包名):
1 pip uninstall XX
【重點】【可以更改pip源,盡量在安裝的時候使用這個,安裝速度比較快】(XX為包名):
1 # 可以在使用pip的時候在后面加上-i參數,指定pip源 2 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple XX 3 4 # 阿里云 http://mirrors.aliyun.com/pypi/simple/ 5 # 中國科技大學 https://pypi.mirrors.ustc.edu.cn/simple/ 6 # 豆瓣(douban) http://pypi.douban.com/simple/ 7 # 清華大學 https://pypi.tuna.tsinghua.edu.cn/simple/ 8 # 中國科學技術大學 http://pypi.mirrors.ustc.edu.cn/simple/
【可以永久更換pip源】
直接在user目錄中創建一個pip目錄,如:C:Usersxxpip,新建文件pip.ini,內容如下:
1 [global] 2 index-url = https://pypi.tuna.tsinghua.edu.cn/simple
2 pip安裝實例
接下來以安裝“numpy”和“Matplotlib”為例:
1 pip install numpy #這是一個數據處理包(13M) 2 # 等待安裝完畢,才能安裝下一個包 3 pip install Matplotlib #這是一個繪圖包(9M) 4 # 等待安裝完畢 5 # 可能在安裝過程中會出現“read timed out”錯誤,請使用上述方法解決 6 # Matplotlib在安裝過程中可能會安裝有其他需要的包,請忽視。 7 # Matplotlib捆綁的其他包:cycler/kiwisolver/pyparsing/python-dateutil/pytz/six
安裝完畢后,可以在 IDLE中運行“import numpy”和“import matplotlib”,若沒有出錯,則成功安裝。
以上兩個包的使用方法,見“https://zhuanlan.zhihu.com/p/24309547”。
3 常用第三方包
numpy、pandas、scipy、xlrd、xlwt(數據處理)
matplotlib(繪圖,包含cycler, kiwisolver, pyparsing, python-dateutil, pytz, six)
jieba、pyHanlp(NLP,分詞、詞性標注、命名實體識別等)
Pillow(圖像處理)
PyMySQL(數據庫)
PyGame(制作游戲)
beautifulsoup4(爬蟲)
requests(網絡請求,包含urllib3, idna, certifi, chardet, requests)
tensorflow(機器學習,包含setuptools, gast, six, absl-py, wheel, termcolor, numpy, protobuf, markdown, werkzeug, tensorboard, astor, grpcio, tensorflow)
ImageHash(圖像相似度,包含scipy、PyWavelets)
jupyter(編輯器,包含decorator, ipython-genutils, traitlets, simplegeneric, pygments, backcall, parso, jedi, wcwidth, prompt-toolkit, pickleshare, colorama, ipython, tornado, jupyter-core, pyzmq, jupyter-client, ipykernel, entrypoints, jsonschema, nbformat, defusedxml, pandocfilters, webencodings, html5lib, bleach, MarkupSafe, jinja2, mistune, testpath, nbconvert, prometheus-client, pywinpty, terminado, Send2Trash, notebook, jupyter-console, qtconsole, widgetsnbextension, ipywidgets, jupyter)
Flask(HTTP API接口)
Gensim(NLP,支持包括TF-IDF、LSA、LDA、Word2Vec在內多種主題模型算法,包含boto, bz2file, jmespath, docutils, botocore, s3transfer, boto3, smart-open)
總結
- 上一篇: CentOS7通过SpeedTest工具
- 下一篇: 【文本分类-05】BiLSTM+Atte