程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Getting started with Python - using pip

編輯:Python

pip Use

  • One 、 Query function
    • 1.1 pip Query installed packages
  • Two 、 Upgrade package
    • Be careful
  • 3、 ... and 、 Change the mirror address
  • Four 、 How to input environment information
  • Four 、 problem

One 、 Query function

1.1 pip Query installed packages

Query all installation packages

pip show

Query the installation information of the specified package

pip show -f PackageName

List installed packages

pip list

Check out upgradeable packages

pip list -o

Two 、 Upgrade package

Upgrade package
Upgrade the specified package , By using ==, >=, <=, >, < To specify a version number .

pip install --upgrade PackageName

upgrade pip

pip install -U pip

Uninstall package

pip uninstall PackageName

Search package
2020 year 12 Monthly this function is disabled , Because someone wrote the wrong code ? Or on purpose , Cause the back end of this function to crash , I don't know whether it has been repaired or not .

pip search PackageName

Be careful

If two versions of Python, Use pip matters needing attention

python2 -m pip install XXX
python3 -m pip install XXX

Use the mirror site code

pip install -i http://pypi.douban.com/simple --trusted-host pypi.douban.com packagename
# packagename Is the name of the package to download 
pip install -i http://e.pypi.python.org --trusted-host e.pypi.python.org --upgrade pip
# upgrade pip

3、 ... and 、 Change the mirror address

Including temporary and permanent use
With the additional mirror command , You can set multiple images to use . See the code below for details :

# Temporary use 
pip install -i https://mirrors.aliyun.com/pypi/simple/ Package name
# Permanent change ( Take Alibaba cloud image as an example )
# Add a primary image as a common source 
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
# Add an additional image as an alternate image source , When the resource is not found in the primary image , Use an alternate mirror address 
pip config set global.extra-index-url https://pypi.tuna.tsinghua.edu.cn/simple
# Check the settings 
pip config list
# Cancel settings 
pip config unset global.index-url

Four 、 How to input environment information

# export file
pip freeze > requirements.txt
# Installation environment information
pip install -r requirements.txt

Four 、 problem

1. A warning message appears
The warning diagram as shown in the figure below appears :

terms of settlement :
Find the directory with the error in the warning message , And then delete ~ Folders at the beginning , Before that, the plug-in failed to install / Drop out , The plug-in installation is abnormal , Although the warning does not affect , But I have obsessive-compulsive disorder ha-ha . Just delete the folder :

The cause of the problem :
My previous updates pip When the package , Open... Without administrator privileges cmd, Cause installation to fail , So this is more .

2. to update pip problem
Use the administrator to use the above update pip On command , Note the following error .

Traceback (most recent call last):
File "d:\python\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "d:\python\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "D:\Python\Scripts\pip.exe\__main__.py", line 4, in <module>
ModuleNotFoundError: No module named 'pip'

terms of settlement :
Use the following commands in turn , Can solve .

python -m ensurepip
python -m pip install --upgrade pip

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved