Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of installing dependent modules in Python

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

The main content of this article is to explain "what is the method of Python installation dependency module", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the method of installing dependency modules in Python"?

The Python module is simply a .py file that can contain any Python code we need. So far, all the programs we have written are contained in separate .py files, so they are both programs and modules. The key difference is that the design goal of the program is to run, while the design goal of the module is to be imported and used by other programs.

Not all programs have associated .py files-for example, sys modules are built into Python, and some modules are implemented in other languages (most commonly C). However, most of Python's library files are implemented using Python, so, for example, we use the statement import collections, and then we can create named tuples by calling collections.namedtuple (), while our access is implemented in the collections.py module file. For programs, it doesn't matter which language the modules are implemented in, because all modules are imported and used in the same way.

Python also provides tools for creating packages. Packages are actually formed by multiple modules gathered together, usually because these modules provide related functions, or have certain dependencies on each other.

1. prerequisite

1)。 Make sure you have installed the required version of Python

2)。 Make sure that the directory of Python has been added to the environment variable

2. Several common ways to install packages in Python

1)。 Pip installation mode (normal online installation)

2)。 Whl installation (offline installation), usually a package in .whl format

3)。 Source code installation method (offline installation), tar.gz/egg format

4)。 Easy_install installation method (less used)

3. Different installation methods specific installation step 1). Pip is a general-purpose Python package management tool; it provides the functions of finding, downloading, installing, and uninstalling Python packages. Using the pip installation package will automatically install other packages on which the package depends, without the need for manual installation.

> pip install-- upgrade pip (first upgrade pip to the latest version)

Pip install xxx (install python package format)

2)。 The wheel file is essentially zip or rar, but it is more convenient for python installation and use. How do I install a package in .whl format? First of all, make it clear why you want to use whl, because sometimes when the python official does not provide the right solution package, you have no choice but to use whl to install it. First, take a look at how to use whl to install the required package.

(1)。 Determine the Python version

(2)。 Find the package in .whl format corresponding to the Python version from the domestic mirror source repository and download it to the local

> pip install xxx.whl (download the package in .whl format and go to the directory of the currently downloaded package; that is, xxx.whl refers to the path where the .whl package is located)

3)。 Source code installation is in the above case, only the source code, you can install it manually, the necessary skills, general python third-party package, will provide manual installation mode, generally there will be a setup.py file for the ability to install from the source code, download the source code to install, go to the directory of the current downloaded source code package

Python setup.py install (installation format)

Several image repositories commonly used in 4.python

Python official source: pypi.python.org/pypi/

Douban: http://pypi.douban.com/simple/

Https://pypi.douban.com/simple/ Tsinghua: https://pypi.tuna.tsinghua.edu.cn/simple

University of California: https://www.lfd.uci.edu/~gohlke/pythonlibs/

University of Science and Technology of China: https://mirrors.ustc.edu.cn/pypi/web/simple

Ali: https://mirrors.aliyun.com/pypi/simple/

[supplement]:

Download address for each version of Python:

Official address: https://www.python.org/downloads/

Download address for each version of Anaconda:

Official address: https://repo.anaconda.com/archive/

Image of Tsinghua University: https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

The method of installing all dependent packages with one click in 5.Python

Pros: it can be done with a simple pip command (you don't have to download and install one by one manually when installing more python packages)

1)。 Python generates dependency packages with one click: (requirements.txt is used to record all dependent packages and version numbers of the project)

> pip freeze > requirements.txt

2). Python install dependency packages with one click: (install all dependency packages in requirements.txt at once)

Pip install-r requirements.txt

At this point, I believe that everyone on the "Python installation dependency module method is what" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report