python如何安装包-Python教程

资源魔 25 0

python若何装置包?

(1)源码装置

能够手动下载第三方包,而后手动装置。

保举:《Python教程》

$ 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

装置或更新文件以下:

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

某些被装置的包可能蕴含 C 代码,以是需求 gcc 这样的对象编译。

(2)easy_install

假如想要应用 easy_install 装置第三方包,需求先装置 setuptools,假如本机不装置,能够采纳源码形式装置,比方:

# 去 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

假如装置的是一个 tar.gz 或 egg 的紧缩包,装置后会呈现相干文件,以下:

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

特地阐明:

easy_install 只能装置包,不克不及卸载包。

easy_install 不克不及装置 wheel 格局的包(pip 能够,但 pip 不克不及装置 egg 格局的包)

(3)pip

假如本机不装置 pip,能够应用 easy_install 对象装置。

pip 罕用饬令:

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

装置 tar.gz 包:

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

装置后会呈现相干文件,以下:

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

装置 wheel 包:

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

装置后会呈现相干文件,以下:

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

以上就是python若何装置包的具体内容,更多请存眷资源魔其它相干文章!

标签: Python python教程 python编程 python使用问题

抱歉,评论功能暂时关闭!