Python Basics | Installation of third-party libraries in the Anaconda environment

WeChat official account tweet: https://mp.weixin.qq.com/s/etFEXm6-ujK3Sg2B7gzqMg

Standard and third-party libraries

  • Python's standard library is the library that comes with Python by default when it is installed. (similar to the built-in camera of a smartphone)

  • The third-party library of Python needs to be installed by itself. (analogous to various apps on smartphones)

  • The Python community provides a large number of third-party libraries. They are omnipotent, covering scientific computing, Web development, database interface, graphics system and many fields, and most of them are mature and stable.

  • Anaconda automatically installs commonly used third-party libraries. (Just like buying a mobile phone, it has already installed common software such as WeChat and QQ for you)

View third-party libraries

We can use the Anaconda Prompt command line installation provided by Anaconda.

1. On the start menu, click ->Anacodna 3->Anaconda Prompt or search for Anaconda Prompt,

image-20221019170645740

2. Enter pip list on the command line in Anaconda Prompt, and the installed library will be displayed

image-20230107225906405

In addition, we can view the installed third-party libraries in the site-packages folder in the Lib folder under Anaconda's root directory (Anaconda's installation path).

image-20230107225802435

Install a third-party library: take the video download artifact you-get as an example

Next, take the installation of the video download artifact you-get library as an example to show the installation of third-party libraries.

Click on the start menu bar-Anaconda3-Anaconda Prompt.

image-20221019170645740

Install third-party libraries from Python's official sources

Anaconda Prompt command line input:

pip install <pakage name>

pip means Package Installer for Python (Python's package installation tool)

For example, if we want to install the you-get library, the Anaconda Prompt command line input:

pip install you-get

image-20230107224732489

Install a specific version of a third-party library

pip install <package name>==<version>

If you want to install pandas version 1.20, enter the following command

pip install pandas==1.2.0

Install third-party libraries through mirror sites

The principle of pip install is to download from Python's official source pypi.python.org/pypi to the local, and then unpack and install it.
However, access to the official pypi is unstable, and sometimes the speed is very slow or even impossible to access. At this point, we can use domestic mirroring.

Domestic mirrors currently include:

豆瓣 http://pypi.douban.com/simple/
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
华中理工大学 http://pypi.hustunique.com/
山东理工大学 http://pypi.sdutlinux.org/

Anaconda Prompt command line input:

pip install <pakage name> -i <mirror website>

For example, if we install the you-get library through a mirror website, enter in the command line:

pip install you-get -i https://pypi.tuna.tsinghua.edu.cn/simple/

image-20230107224833584

Use of you-get library

Download The Story of Capital Season 1 Episode 1

URL: https://www.bilibili.com/video/BV1mW411J7ED?p=1

image-20230107225058537

Anaconda Prompt command line input:

you-get https://www.bilibili.com/video/BV1mW411J7ED?p=1

image-20230107225325386

Download the "Capital Stories" video collection

Since there are 60 episodes in the capital story, what if we want to download 60 episodes? We can add --playlist directly after the URL of the single episode. That is, enter on the command line:

you-get https://www.bilibili.com/video/BV1mW411J7ED?p=1 --playlist

image-20230107225515545

Download the whl file and install third-party libraries

whl file usage scenario

When installing third-party modules through the pip install command, some third-party modules are not compatible with Python3, so you need to find a compatible package for installation.

For example, if we install the docx library, enter on the command line

pip install docx

img

We input import docx in the development environment to test whether the three-party library is successful, and an Error is displayed. The reason is that the docx installation package downloaded through the command line is only compatible with Python2 and not compatible with Python3.

img

At this point, we can manually download the third-party module package to the local through the download URL, and then install it manually. Many third-party module packages are whl files. The whl format is essentially a compressed package, which contains py files and compiled pyd files, so that you can choose your own python environment for installation without a compiling environment. .

whl file installation process

A. Download the required whl file. download link:

https://www.lfd.uci.edu/~gohlke/pythonlibs/

image-20220516201233095

For example, if we want to install the docx third-party library, click python_docx-0.8.10-py2.py3-none-any.whl to download

image-20220516201311263

B. Enter on the command line

pip install <whl file path+whl file name>

Taking this computer as an example, the downloaded whl file is stored in the C:\Users\mi\Downloads folder, so enter in the command line:

pip install C:\Users\mi\Downloads\python_docx-0.8.10-py2.py3-none-any.whl

img

It shows that the installation is successful, and we C:\Users\mi\Anaconda3\Lib\site-packagescan find the installed docx library

image-20220516201332744

Guess you like

Origin blog.csdn.net/mfsdmlove/article/details/129396045