Python installation of third party libraries and FAQ summary

  • 2020-05-10 18:28:03
  • OfStack

The source code to install

The Python third party library is almost always available on github or pypi. The source package formats are zip, tar.zip, tar.bz2. Unzip these packages, go into the unzipped folder, and you'll usually have a file called setup.py. Open the command line and enter the folder. Run the following command to install the third repository into the system:


python setup.py install

Or with pip, no decompression is required: pip install package.zip

Package manager installation

Many programming languages today have package managers, such as gem for Ruby and npm for nodejs.

In Python, the third side module is installed through the setuptools tool. Python has two package management tools that encapsulate setuptools: easy_install and pip. pip is currently officially recommended.

With easy_install and pip very convenient to install third party libraries their principle is actually from the official source Python pypi. python. org/pypi downloaded to a local, then unpack the installation.

The basic operation commands are as follows:


#  The installation package
pip install packagename
 
#  uninstall package
pip uninstall packagename
 
#  View what is installed package
pip list
 
#  Redirects the project dependent libraries to a file, cd To the project root directory 
pip projectname > requirements.txt
 
#  Someone else installed the project's dependency library 
pip install -r requirements.txt
# pip Common commands can be entered on the command line pip -h To view 
# pip command -h You can see how this 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.

Q&A

The official pypi is unstable, slow or even inaccessible

Solution 1:

Use the source installation method, download from github or other libraries, use python setup.py install installation method, see [source installation] above

Solution 2:

Manually specify the source, pip followed by -i, as follows:

pip install packagename -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

pipy domestic mirror currently has:

Douban http: / / pypi. douban. com/simple /
Ali cloud http: / / mirrors. aliyun. com/pypi/simple /
https: China university of science and technology. / / pypi mirrors. ustc. edu. cn/simple /
Tsinghua university https: / / pypi. tuna. tsinghua. edu. cn/simple /
Huazhong university of science and http: / / pypi. hustunique. com /
Shandong university of science and technology http: / / pypi sdutlinux. org /

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

See if setuptools and pip versions are 1 and upgrade to the latest version


pip install setuptools -U 
pip install pip -U

"error: Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall. bat)."

The reason is probably the lack of 1 C compiler on windows.

Solution 1: install VC or VS, which sometimes works and sometimes doesn't.

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

whl format download address: http: / / www lfd. uci. edu / ~ gohlke/pythonlibs /


#  The input whl The full path where the file resides 
pip install D:\python\numpy-1.9.2+mkl-cp33-none-win_amd64.whl


Related articles: