Home  >  Article  >  Backend Development  >  How to install python package

How to install python package

(*-*)浩
(*-*)浩Original
2019-06-27 14:30:1310301browse

We know that a very important reason why Python is very popular is because it has many packages for us to use, but many of these packages do not come with it and need to be installed manually. In this article, we will talk about installation. Several ways to package Python.

How to install python package

The packages we usually use are obtained from the website https://pypi.org/. Developers publish the packages to Pypi in accordance with certain development standards. , and then the user, that is, the user who uses the package, downloads and installs the package from the website in different ways. Python packages mainly come in two formats: .whl and .tar.gz.

Online installation(Recommended learning: Python video tutorial)

Online installation is a relatively simple way, just run the following code directly :

pip install xxx

xxx represents the name of a specific package, so where exactly does this line of code run? There are two main places to run this line of code.

If your Python has environment variables configured, then you can call the computer's own terminal (cmd) by combining the shortcut key Win R, then enter the above code and hit Enter to run.

Online installation is very simple. Just enter the pip command, hit Enter, and wait. No other operations are required. However, one disadvantage of online installation is that the download is relatively slow. For those relatively large packages, connection timeout errors may occur, causing the final installation to fail.

So in addition to online installation, we also need to learn manual installation.

whl file installation

As mentioned earlier, the .whl format file is one type of Python package. You can download it at https://www.lfd.uci .edu/~gohlke/pythonlibs/#jpype Find almost all .whl format files here.

You need to pay attention to the cp part after each file. This part is used to indicate the version of the package you want to download. The version of the package needs to be consistent with your Python version. cp36 means Python3.6 corresponding package. win32 means that the system is x32-bit, win_amd64 means that the system is x64-bit.

After downloading the file, open the command window. There are also two command windows here, which are the two windows used in online installation. You can choose according to your own situation. After opening the command window Use the cd command to switch to the path where the whl file is located.

Use the cd command to switch to the D drive, and then run pip install xxx.whl to complete the installation.

tar.gz file installation

tar.gz file needs to be downloaded by selecting the file in the corresponding format from https://pypi.org/. After downloading, it is A compressed package needs to be decompressed. After decompression, open the command window. You also need to switch to the path where the file is located, and then run the python setup.py install command to install it.

For more Python related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of How to install python package. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn