The Python Package Index (PyPI) is a repository of software for the Python programming language.
https://pypi.org/
pypi
Everyone on the Python Planet is probably already familiar with Peter Fein’s recent article about PyPI.
Python Planet上的每个人都可能已经熟悉Peter Fein最近关于PyPI的文章。
Everyone on the Python Planet is probably already familiar with Peter Fein’s recent article about PyPI use (or lack thereof). But in case not, particularly striking was the number of folks who joined the “PyPI bashing” in the comments. In fact, it has inspired me to write this post “in defense of PyPI”. I would like to offer the Python community a summary of what I think are the general criticisms, along with my responses as a “sysadmin / developer type”.
Python Planet上的每个人都可能已经熟悉Peter Fein最近关于PyPI使用(或缺乏PyPI)的文章。 但是如果不是这样的话,在评论中加入“ PyPI扑朔迷离”的人数尤其惊人。 实际上,这启发了我写这篇文章“捍卫PyPI”。 我想向Python社区提供我认为是普遍批评的摘要,以及我对“系统管理员/开发人员类型”的回答。
First let me say this: I love PyPI! And I agree with Peter, if your package isn’t on PyPI it “doesn’t exist”. I wouldn’t put it quite like that; but I would say it’s fairly important if you are publishing open source Python code, to consider uploading it to the Python Package Index.
首先让我这样说:我爱PyPI! 我同意Peter的观点,如果您的软件包不在PyPI上,则“不存在”。 我不会这么说。 但是我要说的是,如果您要发布开源Python代码,则考虑将其上传到Python包索引中是非常重要的。
Why?
为什么?
因为每个人都赢 (Because Everybody Wins)
Believe it or not, the general Python community is interested in seeing your code. Whether to use it for an example, or to avoid reinventing the wheel, or whatever the reason; we’d like a chance to see your code. But if you don’t publish it to PyPI, we may never get that chance!
信不信由你,一般的Python社区都对查看您的代码感兴趣。 是将其用作示例,还是避免重新发明轮子,或出于任何原因; 我们希望有机会看到您的代码。 但是,如果您不将其发布到PyPI,我们可能永远也不会获得机会!
For better or worse, PyPI is the canonical place on Earth for Python packages. It’s the CPAN of Python. I understand that not everyone is 100% comfortable with this, but that doesn’t make it any less true. If you accept that “open source is good”, and that “Python rules”, then you simply must take this next leap of faith: “PyPI is the place for Python packages”.
不管是好是坏,PyPI是Python软件包在地球上的规范位置。 这是Python的CPAN。 我了解并非所有人都对此感到百分百满意,但这并没有使它不那么正确。 如果您接受“开源是好的”和“ Python规则”,那么您必须简单地迈出下一步的信念:“ PyPI是Python软件包的地方”。
[waves hand]
[挥手]
Moving on, why else should you consider uploading your packages to PyPI?
接下来,为什么还要考虑将软件包上传到PyPI?
因为这是要做的“正确”事情 (Because It Is The “Right” Thing To Do)
Another thing that struck me is the number of folks who (appear to) confuse “version control” with “distribution”. If I’m not mistaken, Launchpad, Github, and Bitbucket are primarily designed for Bazaar, Git, and Mercurial hosting respectively. These sites can host your distribution tarballs, but they certainly weren’t designed and built to do so. Rather, they were designed and built to host your source code.
使我震惊的另一件事是(似乎)使“版本控制”与“发行”相混淆的人们的数量。 如果我没记错的话,Launchpad,Github和Bitbucket主要是分别为Bazaar,Git和Mercurial托管设计的。 这些站点可以托管您的发行包,但是它们并不是经过精心设计和构建的。 相反,它们是为托管您的源代码而设计和构建的。
In some cases, a project may wish to host it’s own distribution server. Whether it be for redundancy (although PyPI has begun to tackle this) or “branding” or other reasons, I would argue this is the preferred way of handling it: in addition to uploading to PyPI, not in place of it.
在某些情况下,项目可能希望托管其自己的分发服务器 。 无论是出于冗余(尽管PyPI已开始解决此问题)还是出于“品牌效应”或其他原因,我都认为这是处理冗余的首选方式:除了上传到PyPI之外,还不能代替它。
Why?
为什么?
因为那并不难 (Because It Is Not That Hard)
Ahem… we get it. The situation with easy_install is “less than ideal”. But this is something to be fixed, not avoided. If you are receiving too many support requests, may I suggest simply telling people not to use easy_install. Or, if the problem is proper packaging, learn how to test your packages before uploading them. Due to the large number of screwed up releases I’ve made, I’ve come to rely on alocal PyPI and a virtualenv to test installations. Others use even simpler methods. And with tools like mkrelease, it’s easy to upload your package to multiple PyPI locations with just a single command (although leaping-tall-buildings-in-a single-bound is not yet supported.)
天哪...我们明白了。 easy_install的情况“不理想”。 但这是必须解决的,不能避免。 如果您收到太多的支持请求,我是否建议您简单地告诉人们不要使用easy_install 。 或者,如果问题是包装正确, 请在上传之前了解如何测试您的包装 。 由于我制作了很多乱七八糟的发行版,因此我不得不依靠本地PyPI和virtualenv来测试安装。 其他人甚至使用更简单的方法 。 借助mkrelease之类的工具,只需一个命令即可将软件包轻松上传到多个PyPI位置(尽管尚不支持将Jumping -Tall-Buildings 整合为一个绑定)。
The point is, please consider helping the community fix the problem rather than simply avoiding it. There are folks actively trying to improve the situation right now.
关键是,请考虑帮助社区解决问题,而不是简单地避免它。 现在有些人正在积极尝试改善这种状况 。
Let’s see, what else?
让我们看看,还有什么?
因为它不一定是完美的 (Because It Does Not Have To Be Perfect)
Over the years I’ve seen various and sundry criticisms of the PyPI user interface. Fine. I have not looked into the current development process, but I assume the author/maintainers would be open to some constructive criticism and/or development assistance.
多年来,我看到了对PyPI用户界面的各种批评。 精细。 我没有研究当前的开发过程,但是我认为作者/维护者会接受一些建设性的批评和/或发展援助。
It doesn’t have to be Github-sexy to be useful. If you would like to report a bug or feature request, do it here (at least, I think that is the right place.)
不一定需要Github-sexy才有用。 如果您想报告错误或功能请求,请在此处进行 (至少,我认为这是正确的位置。)
结论 (Conclusion)
I hope this convinces at least some folks to consider uploading their packages to PyPI. If it doesn’t, please let me know why in the comments.
我希望这能说服至少一些人考虑将其软件包上传到PyPI。 如果没有,请在评论中让我知道原因。
Did you enjoy reading this article? If so, please consider `helping me help Plone`_.
您喜欢阅读本文吗? 如果是这样,请考虑“帮助我帮助Plone” _。
pypi
The Python Package Index (PyPI) is a repository of software for the Python programming language.
https://pypi.org/
转载于:https://www.cnblogs.com/longchang/p/11384689.html
可能有很多刚入行不久的朋友们,每天都在用pip 命令install 一些python软件包,却对pypi 不甚了解,那这个pip和pypi之间有什么练习和区别呢?下面就带大家简单有个了解吧!希望能够帮助到大家!
pip 是一个现代的,通用的 Python 包管理工具,是easy_install的替代品,英文python install packages !
Python包索引(PyPI)是Python编程语言的软件存储库。
PyPI(Python Package Index)是python官方的第三方库的仓库,所有人都可以下载第三方库或上传自己开发的库到PyPI。PyPI推荐使用pip包管理器来下载第三方库。
pip可正常工作在Windows、Mac OS、Unix/Linux等操作系统上,但是需要至少2.6+和3.2+的CPython或PyPy的支持。python 2.7.9 和3.4以后的版本已经内置累pip程序,所以不需要安装。PyPI可帮助您查找和安装Python社区开发和共享的软件。
包作者使用PyPI来分发他们的软件 。
这里有pypi官方社区详细介绍,大家可以进去看看 https://pypi.org/,写得很详细!
1,安装包 https://packaging.python.org/tutorials/installing-packages/#installing-packages
内容
本节介绍在安装其他Python包之前要遵循的步骤。
在继续之前,请确保您拥有Python,并且可以从命令行获得预期版本。您可以通过运行来检查:
python --version
你应该得到一些输出。如果您没有Python,请从python.org安装最新的3.x版本,或参考Hitchhiker的Python指南的安装Python部分。Python 3.6.3
注意
如果您是新手并且遇到如下错误:
>>>
>>> python --version
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'python' is not defined
这是因为本教程中的此命令和其他建议命令旨在在shell(也称为终端或 控制台)中运行。有关使用操作系统的shell和与Python交互的介绍,请参阅Python入门指南入门教程。
注意
如果您正在使用像IPython或Jupyter笔记本这样的增强型shell,则可以通过使用!
字符为它们添加前缀来运行本教程中的系统命令:
In [1]: import sys
!{sys.executable} --version
Python 3.6.3
建议编写{sys.executable}
而不是简单python
,以确保命令在与当前运行的笔记本匹配的Python安装中运行(可能与python
命令引用的Python安装不同)。
注意
由于大多数Linux发行版处理Python 3迁移的方式,使用系统Python而不首先创建虚拟环境的Linux用户应该python
使用python3
和使用pip
命令替换本教程中的命令。千万不能 在本教程与运行任何命令:如果你得到一个权限错误,回来的部分上创建虚拟环境中,设置一个,然后用教程继续写。pip3 --user
sudo
此外,您需要确保您有可用的点数。您可以通过运行来检查:
pip --version
如果您从源代码安装Python,使用python.org的安装程序,或者通过Homebrew安装Python,那么您应该已经拥有了pip。如果您在Linux上并使用操作系统软件包管理器进行安装,则可能需要单独安装pip,请参阅 使用Linux软件包管理器安装pip / setuptools / wheel。
如果pip
尚未安装,则首先尝试从标准库引导它:
python -m ensurepip --default-pip
如果仍然不允许你运行pip
:
安全下载get-pip.py [1]
跑。[2] 这将安装或升级pip。此外,如果它们尚未安装,它将安装setuptools和wheel。
pythonget-pip.py
警告
如果您使用的是由您的操作系统或其他软件包管理器管理的Python安装,请务必小心。get-pip.py不与这些工具协调,可能会使系统处于不一致状态。您可以使用 安装在其中设计用于本地安装的软件。
python get-pip.py --prefix=/usr/local/
/usr/local
虽然pip
单独就足以从预先构建的二进制存档进行安装,但最新的setuptools
和wheel
项目副本对于确保您也可以从源存档进行安装非常有用:
python -m pip install --upgrade pip setuptools wheel
有关详细信息,请参阅下面的部分,但这是在典型Linux系统上使用的基本venv [3]命令:
python3 -m venv tutorial_env
source tutorial_env/bin/activate
这将在tutorial_env
子目录中创建新的虚拟环境,并配置当前shell以将其用作默认python
环境。
Python“虚拟环境”允许将Python 包安装在特定应用程序的隔离位置,而不是全局安装。
想象一下,你有一个需要LibFoo版本1的应用程序,但另一个应用程序需要版本2.你如何使用这两个应用程序?如果将所有内容安装到/usr/lib/python3.6/site-packages(或任何平台的标准位置),则很容易在无意中升级不应升级的应用程序的情况下结束。
或者更一般地说,如果你想安装一个应用程序并保留它,该怎么办?如果应用程序有效,则其库中的任何更改或这些库的版本都可能会破坏应用程序。
另外,如果您无法将软件包安装到全局site-packages目录中,该怎么办?例如,在共享主机上。
在所有这些情况下,虚拟环境可以帮助您。它们有自己的安装目录,并且不与其他虚拟环境共享库。
目前,有两种常用的工具可用于创建Python虚拟环境:
基本用法如下:
使用virtualenv:
virtualenv <DIR>
source <DIR>/bin/activate
使用venv:
python3 -m venv <DIR>
source <DIR>/bin/activate
有关更多信息,请参阅virtualenv文档或venv文档。
在上述两种情况下,Windows用户都应该_not_使用 source命令,而应该直接从命令shell 运行activate脚本。在Unix shell下使用source可确保虚拟环境的变量在当前shell中设置,而不是在子进程中设置(然后消失,没有任何有用的效果)。
直接管理多个虚拟环境可能会变得乏味,因此 依赖关系管理教程引入了一个更高级别的工具Pipenv,它可以为您处理的每个项目和应用程序自动管理单独的虚拟环境。
pip是推荐的安装程序。下面,我们将介绍最常见的使用方案。有关更多详细信息,请参阅 pip文档,其中包含完整的参考指南。
pip最常见的用法是使用需求说明符从Python包索引进行安装。一般来说,需求说明符由项目名称后跟可选的版本说明符组成。 PEP 440包含a 当前支持的说明符的完整规范。以下是一些例子。
要安装最新版本的“SomeProject”:
pip install 'SomeProject'
要安装特定版本:
pip install 'SomeProject==1.4'
要安装大于或等于一个版本而不是另一个版本:
pip install 'SomeProject>=1,<2'
pip install 'SomeProject~=1.4.2'
在这种情况下,这意味着安装任何版本“== 1.4。*”版本也是“> = 1.4.2”。
pip可以从 Source Distributions(sdist)或 Wheels安装,但如果两者都存在于PyPI上,则pip将更喜欢兼容的wheel。
轮子是预先构建的分发格式,与源分发(sdist)相比,提供更快的安装,特别是当项目包含编译的扩展时。
如果pip没有找到要安装的轮子,它将在本地构建一个轮子并将其缓存以供将来安装,而不是在将来重建源分发。
将已安装的SomeProject从PyPI 升级到最新版本。
pip install --upgrade SomeProject
要安装与当前用户隔离的软件包,请使用以下--user
标志:
pip install --user SomeProject
有关更多信息,请参阅pip文档中的“ 用户安装”部分。
请注意,在--user
虚拟环境中,该标志无效 - 所有安装命令都将影响虚拟环境。
pip install -r requirements.txt
以“可编辑”模式从VCS安装项目。有关语法的完整细分,请参阅有关VCS支持的 pip部分。
pip install -e git+https://git.repo/some_pkg.git#egg=SomeProject # from git
pip install -e hg+https://hg.repo/some_pkg#egg=SomeProject # from mercurial
pip install -e svn+svn://svn.repo/some_pkg/trunk/#egg=SomeProject # from svn
pip install -e git+https://git.repo/some_pkg.git@feature#egg=SomeProject # from a branch
从备用索引安装
pip install --index-url http://my.package.repo/simple/ SomeProject
除了PyPI之外,在安装期间搜索其他索引
pip install --extra-index-url http://my.package.repo/simple SomeProject
在开发模式下从本地src安装,即以项目似乎已安装的方式安装,但仍可从src树中编辑。
pip install -e <path>
您也可以从src正常安装
pip install <path>
安装特定的源归档文件。
pip install ./downloads/SomeProject-1.0.4.tar.gz
从包含存档的本地目录安装(并且不检查PyPI)
pip install --no-index --find-links=file:///local/dir/ SomeProject
pip install --no-index --find-links=/local/dir/ SomeProject
pip install --no-index --find-links=relative/dir/ SomeProject
要从其他数据源(例如Amazon S3存储)进行安装,您可以创建一个帮助应用程序,以便在数据中显示数据 PEP 503兼容索引格式,并使用该--extra-index-url
标志指示pip使用该索引。
./s3helper --port=7777
pip install --extra-index-url http://localhost:7777 SomeProject
除稳定版本外,还可以查找预发布和开发版本。默认情况下,pip只能找到稳定的版本。
pip install --pre SomeProject
$ pip install SomePackage[PDF]
$ pip install SomePackage[PDF]==3.0
$ pip install -e .[PDF]==3.0 # editable project in current directory
[1] | 在此上下文中,“安全”是指使用现代浏览器或curl等工具从https URL下载时验证SSL证书。 |
[2] | 根据您的平台,这可能需要root或Administrator访问权限。pip目前正在考虑通过让用户安装默认行为来改变这种情况。 |
[3] | 从Python 3.4开始,venv (virtualenv的stdlib替代品 )将创建pip 预安装的virtualenv环境,从而使其成为virtualenv的平等替代品 。 |
[4] | 兼容版本说明符已被接受 PEP 440 和支持在 setuptools v8.0和 pip v6.0中发布 |