SoFunction
Updated on 2024-11-17

Summary of Python installing third-party libraries and how to deal with common problems

Source Code Installation

Almost all Python third-party libraries can be found on github or pypi. The source packages are in zip , , tar.bz2. Unzip these packages and go to the extracted folder, which will usually have a file in it. Open the command line and go to that folder. Run the following command to install this third library on your system:

python  install

Or with the help of pip, you don't need to unpack it.pip install

Package Manager Installation

Many programming languages, nowadays, come with package managers, such as Ruby's gem and nodejs' npm.

In Python, installing third-party modules is done through the setuptools tool. there are two package management tools that encapsulate setuptools: easy_install and pip. pip is the official recommendation.

It's easy to install third-party libraries with easy_install and pip. They actually work by downloading them locally from the official Python source/pypi and unpacking and installing them.

The basic operation commands are as follows:

# Install the package
pip install packagename
 
# Uninstall the package
pip uninstall packagename
 
# View installed packages
pip list
 
# Redirect the output of project-dependent libraries to a file, cd to the project root directory
pip projectname > 
 
# Dependency libraries for projects installed by others
pip install -r 
# pip common commands can be viewed by typing pip -h at the command line
# pip command -h to see how the command is used
 
Commands:
 install           Install packages.
 download          Download packages.
 uninstall          Uninstall packages.
 freeze           Output installed packages in requirements format.
 list            List installed packages.
 show            Show information about installed packages.
 search           Search PyPI for packages.
 wheel            Build wheels from your requirements.
 hash            Compute hashes of package archives.
 completion         A helper command used for command completion
 help            Show help for commands.

common problems

The official pypi is unstable, very slow or even inaccessible!

Solution 1:

Using source code installation, download from github or other repositories and install with python install, see [Source Code Installation] above.

Solution 2:

To specify the source manually, follow pip with -i, the command is as follows:

pip install packagename -i /simple --trusted-host

pipy domestic mirrors are currently available:

Douban, PRC social networking website/simple/
AliCloud (computing)/pypi/simple/
University of Science and Technology of China (USTC)/simple/
Tsing Hua or Qinghua University, Beijing/simple/
Central China University of Technology/
Shandong University of Technology/

Some packages can be installed on this computer, but not on another one.

Refer to setuptools, pip version is the same, upgrade to the latest version

pip install setuptools -U 
pip install pip -U

Errors when installing certain packages”error: Microsoft Visual C++ 10.0 is required (Unable to find ).”

The reason is probably the lack of some C compilers on windows.

Solution 1: Install VC or VS, this method sometimes works, sometimes does not work.

Solution 2: Simpler solution: download the package in whl format and install it with pip. Take numpy package as an example:

Download address in whl format:/~gohlke/pythonlibs/

# Enter the full path where the whl file is located
pip install D:\python\numpy-1.9.2+mkl-cp33-none-win_amd64.whl