Home  >  Article  >  Backend Development  >  How to install packages in python

How to install packages in python

藏色散人
藏色散人Original
2019-10-16 13:47:455095browse

How to install packages in python

How to install packages in python?

(1) Source code installation

You can manually download the third-party package and then install it manually.

Recommended: "Python Tutorial"

$ wget "https://files.pythonhosted.org/packages/96/66/43e6df87373557553be2b4343db27d008c6dcefa110ccff38cba1459ca07/ywdblogmath-0.1.tar.gz"
$ tar xvf ywdblogmath-0.1.tar.gz 
$ cd ywdblogmath-0.1/ 
$ python setup.py install

The installation or update files are as follows:

/usr/local/lib/python2.7/dist-packages/easy-install.pth
/usr/local/lib/python2.7/dist-packages/ywdblogmath-0.1-py2.7.egg

Some installed packages may contain C code, so Requires tools like gcc to compile.

(2) easy_install

If you want to use easy_install to install third-party packages, you need to install setuptools first. If it is not installed on your machine, you can install it using source code, such as :

# 去 https://pypi.org/project/setuptools/ 下载 .zip 包
$ python setup.py  install
easy_install 支持从 Pypi(tar.gz或egg包)、URL、本地目录安装软件包:
# 从 Pypi 安装最新的包,可能是 tar.gz 或 egg 包
$ easy_install  ywdblogmath 
# 安装 tar.gz 类型的包
$ easy_install "https://files.pythonhosted.org/packages/96/66/43e6df87373557553be2b4343db27d008c6dcefa110ccff38cba1459ca07/ywdblogmath-0.1.tar.gz" 
# 安装 egg 包
# easy_install "https://files.pythonhosted.org/packages/b0/fe/1fef363672c1e179de61ff1519aed6a3d68200b4cad0536b6d96b08cc5e9/ywdblogmath-0.3-py2.7.egg" 
# 本地目录包含 ywdblogmath 的源码 
$ easy_install /root/python

If you are installing a tar.gz or egg compressed package, relevant files will appear after installation, as follows:

/usr/local/lib/python2.7/dist-packages/easy-install.pth(文件更新)
/usr/local/lib/python2.7/dist-packages/ywdblogmath-0.1-py2.7.egg(文件新增)

Special instructions:

easy_install can only The package is installed and cannot be uninstalled.

easy_install cannot install wheel format packages (pip can, but pip cannot install egg format packages)

(3) pip

If this If pip is not installed on your machine, you can use the easy_install tool to install it.

pip Common commands:

$ pip list 
$ pip install ywdblogmath 
$ pip install ywdblogmath -U 
$ pip show ywdblogmath

Install tar.gz package:

$ pip install "https://files.pythonhosted.org/packages/96/66/43e6df87373557553be2b4343db27d008c6dcefa110ccff38cba1459ca07/ywdblogmath-0.1.tar.gz"

After installation, relevant files will appear, as follows:

/usr/local/lib/python2.7/dist-packages/ywdblogmath(新增目录)
/usr/local/lib/python2.7/dist-packages/ywdblogmath-0.1-py2.7.egg-info(新增文件)

Install wheel package:

$ pip install "https://files.pythonhosted.org/packages/5f/ca/6624a4b42be2df78f51043d2282944e78dc939066a3da07dfdb949cd6d3e/ywdblogmath-0.4-py2-none-any.whl"

After installation, relevant files will appear, as follows:

/usr/local/lib/python2.7/dist-packages/ywdblogmath (新增目录)
/usr/local/lib/python2.7/dist-packages/ywdblogmath-0.4.dist-info(新增文件)

The above is the detailed content of How to install packages in python. 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