python中pip命令主要用於安裝和下載包
安裝:pip install package_name
卸載:pip uninstall pakage_name
以numpy包為例進行測試。
1、查看python版本
C:\Users\75377>python --version Python 3.8.2
2、測試直接加載numpy包
C:\Users\75377>python ## 調用python Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import numpy ## 直接加載numpy,顯示沒有numpy模塊 Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'numpy'
3、退出python,使用pip命令進行安裝
>>> quit() ## 退出python C:\Users\75377>pip install numpy -y ## 直接安裝 Usage: pip install [options] <requirement specifier> [package-index-options] ... pip install [options] -r <requirements file> [package-index-options] ... pip install [options] [-e] <vcs project url> ... pip install [options] [-e] <local project path> ... pip install [options] <archive url/path> ... no such option: -y ## 不能使用 -y C:\Users\75377>pip install numpy ## 安裝 numpy Collecting numpy Using cached numpy-1.21.4-cp38-cp38-win_amd64.whl (14.0 MB) Installing collected packages: numpy Successfully installed numpy-1.21.4 ## 安裝成功 C:\Users\75377>
4、測試效果
C:\Users\75377>python Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import numpy ## 沒有問題,可以調用 >>>
5、使用pip卸載 numpy
>>> quit() C:\Users\75377>pip uninstall numpy ## 卸載numpy包 Found existing installation: numpy 1.21.4 Uninstalling numpy-1.21.4: Would remove: d:\programs\python\lib\site-packages\numpy-1.21.4.dist-info\* d:\programs\python\lib\site-packages\numpy\* d:\programs\python\scripts\f2py.exe Proceed (Y/n)? y Successfully uninstalled numpy-1.21.4 ## 卸載成功
6、測試卸載效果
C:\Users\75377>python Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import numpy ## 卸載成功 Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'numpy'