


Summary of common methods for installing third-party libraries in Python
This article brings you relevant knowledge about Python, which mainly introduces the common methods of installing third-party libraries. Let’s take a look at them together. I hope it will be helpful to everyone.
[Related recommendations: Python3 video tutorial ]
In the study of pyhton, I believe everyone will usually encounter third-party libraries The installation problem is a headache for many beginners. Here I will make some simple summaries on how to install third-party libraries correctly and efficiently without taking detours
Installation method
1 . Install through pychram
This is the simplest and most direct method in my opinion, but it is also the easiest to report errors.
Open File-Settings-Project-Python Interpreter
From here you can see the third-party libraries and versions you have installed, and then click the plus sign below to proceed Add to. Here I take numpy as an example. Search for the library you want at the top, and then select the version you want at the bottom right. If not checked, it will default to the latest version. Click Install Packages to install it.
2. pip installation method
If the installation in pycharm fails, or pycharm is not used, you can directly Install using pip method.
First open cmd and directly enter pip install the third-party library you want to install
(here I still use numpy as an example)
Here, I will also add some information about Some methods of updating and uninstalling pip:
(1) Upgrading pip itself
py -m pip install --upgrade pip
(2) pip installation/uninstallation/upgrade
pip install 包名 #安装pip uninstall 包名 #卸载pip install --upgrade 包名 #升级
(3) pip viewing installed Package
pip list
(4) pip checks which packages need to be updated:
pip list --outdated
(5) pip checks the details of a package:
pip show 包名
(6) pip installation specification Version of the package:
pip install 包名==版本号 例如: pip install numpy==1.20.3pip install 'matplotlib>3.4'pip install 'matplotlib>3.4.0,=, , <h2> <a id="3_whl_55"></a>3. Download the whl file to local offline installation</h2><p>If the first two methods fail, then my most recommended method is the third Although it is not as convenient as the first two, it is effective in personal testing and will not report errors! Enter the website <a href="https://www.php.cn/link/7d7c61cdf50443a0079ebb5011209dbf">https://www.php.cn/link/7d7c61cdf50443a0079ebb5011209dbf</a> and find the library you need to download. Here I take matplotlib as an example: <br> First of all, you must pay attention to <mark> before installing this Some libraries that it depends on before the package must be installed first before installing the one you want, otherwise an error </mark> will be reported. <br> At the same time, after updating a certain library, you must also pay attention to updating the libraries it depends on at the same time, otherwise errors will occur. <br><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/067/36cabce7a764653c64263a29550b7634-3.png" class="lazy" alt="Summary of common methods for installing third-party libraries in Python"><br> Then select and download based on your python version and number of bits. Here, because my python version is 3.7.9 and the number of bits is 64 bits, I chose matplotlib‑3.5.1 ‑cp37‑cp37m‑win_amd64.whl. <br> Save the downloaded whl file to the folder <code>Python37\Lib\site-packages</code>, open cmd under the file, enter <code>pip install whl file name</code> to install. <br><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/067/c522c75f56fd335401a3847b6e4f524c-4.png" class="lazy" alt="Summary of common methods for installing third-party libraries in Python"></p><p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/067/d5fdf37a9f18234fe0c302793ed1f48c-5.png" class="lazy" alt="Summary of common methods for installing third-party libraries in Python"></p><h3 id="a-id-Supplement-a"><a id="31__65">##3.1 Supplement</a></h3>During my installation process, most of the failed problems were due to no It is caused by installing the corresponding dependent package, so after reporting an error, be sure to check whether the corresponding package is installed and update it at the same time. <p> For example, I once encountered this problem: <br>AttributeError: module 'matplotlib' has no attribute 'get_data_path'<code>, which troubled me for an afternoon and did not solve it. Finally, I found that a package that matplotlib depends on did not Installed. </code><br><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/067/d5fdf37a9f18234fe0c302793ed1f48c-6.png" class="lazy" alt="Summary of common methods for installing third-party libraries in Python"></p><h2 id="a-id-Other-methods-a"><a id="4_71">4. Other methods</a></h2><h3 id="a-id-PythonPypi-Python-official-Pypi-menu-a"><a id="41_PythonPypi_72">4.1 Python official Pypi menu</a></h3> Directly search for third parties Library to install, address: <p>https://www.php.cn/link/4b6cf59a2a5b31fc68aa6f9524067ef8<a href="https://www.php.cn/link/4b6cf59a2a5b31fc68aa6f9524067ef8"></a></p><h3> <a id="42_pip_74"></a>4.2 Domestic mirror sources solve the problem of slow pip installation</h3><p>Under Windows systems, when installing third-party libraries, you often encounter timeouts or slow downloads. This is Because the Python server is abroad, sometimes the network speed is too slow when downloading with pip. In this case, it is recommended to use a domestic mirror source for installation. <br> Installation method: Open cmd and add the "-i" or "-index" parameter. Take numpy as an example: `pip install -i https://www.php.cn/link/a6455ffc4e47fd737db213366771ec0e numpy<br> Several commonly used domestic image sources: <br> Tsinghua: <a href="https://www.php.cn/link/a6455ffc4e47fd737db213366771ec0e">https://www.php .cn/link/a6455ffc4e47fd737db213366771ec0e</a><br> Alibaba Cloud: <a href="https://www.php.cn/link/4901e49e1e2d9c85659eef5b2ffbe12f">https://www.php.cn/link/4901e49e1e2d9c85659eef5b2ffbe12f</a><br> University of Science and Technology of China: <a href="https://www.php.cn/link/1cbbae823ca54abfb04302180fd84137">https://www. php.cn/link/1cbbae823ca54abfb04302180fd84137</a><br> Douban: <a href="https://www.php.cn/link/3c0093f155f7a0bf00afca91dc8fb9b8">https://www.php.cn/link/3c0093f155f7a0bf00afca91dc8fb9b8</a></p><h1> <a id="_83"></a>Summary</h1> <p>For most novices, the installation of Python third-party libraries is definitely a stumbling block on their way to learning. I have also had a headache with this problem. But as far as my personal installation is concerned, I have personally tested the first three methods. The first and second methods are the simplest and most direct, but they are error-prone because you are not familiar with the dependencies between various packages, so I strongly recommend that if the first two installations are unsuccessful, you must try the third one! ! <mark>Check clearly the packages that need to be installed before installing the third-party libraries you need, otherwise the installation will not be successful</mark>! ! I don’t use the fourth method often, because I think the first three methods are enough to install the libraries you need. Of course, if you need it, you can learn more about the fourth method in detail, but I won’t cover it here. Too many introductions! </p><p>【Related recommendations: <a href="http://www.php.cn/course/list/31.html" target="_blank">Python3 video tutorial</a>】</p>
The above is the detailed content of Summary of common methods for installing third-party libraries in Python. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

To run Python code in Sublime Text, you need to install the Python plug-in first, then create a .py file and write the code, and finally press Ctrl B to run the code, and the output will be displayed in the console.

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

Running Python code in Notepad requires the Python executable and NppExec plug-in to be installed. After installing Python and adding PATH to it, configure the command "python" and the parameter "{CURRENT_DIRECTORY}{FILE_NAME}" in the NppExec plug-in to run Python code in Notepad through the shortcut key "F6".
