从setuptools迁移到pip + virtualenv [英] Migrating to pip+virtualenv from setuptools

查看:57
本文介绍了从setuptools迁移到pip + virtualenv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,与setuptools相比,pipvirtualenv听起来很棒.能够卸载将是很棒的.但是我的项目已经在使用setuptools,那么如何迁移?到目前为止,我能找到的网站非常模糊和笼统.因此,在阅读了主要的网站并尝试了一些内容之后,这里是一些问题的选集:

So pip and virtualenv sound wonderful compared to setuptools. Being able to uninstall would be great. But my project is already using setuptools, so how do I migrate? The web sites I've been able to find so far are very vague and general. So here's an anthology of questions after reading the main web sites and trying stuff out:

  • 首先,现在应该virtualenvpip处于可用状态吗?如果没有,请不要理会其他人,就像疯子一样.
  • 应如何安装virtualenv?我还不太愿意相信它像 matplotlib 在虚拟环境中?由于某种原因,它总是想在这里编译而不是仅仅安装一个软件包,并且总是以失败告终(即使在脚本virtualenv之类的,就像在过去的日子不好吗?
  • #egg=Package URL语法是什么?这不是标准URL的一部分,那么为什么不将其作为单独的参数呢?
  • URL中的@rev包含在哪里?最后,我想,但是文档对此并不清楚(您还可以在URL中包含@rev").
  • 通过使用现有需求文件作为作为一种模板来理解新文件" ?这可能意味着任何事情.
  • First of all, are virtualenv and pip supposed to be in a usable state by now? If not, please disregard the rest as the ravings of a madman.
  • How should virtualenv be installed? I'm not quite ready to believe it's as convoluted as explained elsewhere.
  • Is there a set of tested instructions for how to install matplotlib in a virtual environment? For some reason it always wants to compile it here instead of just installing a package, and it always ends in failure (even after build-dep which took up 250 MB of disk space). After a whole bunch of warnings it prints src/mplutils.cpp:17: error: ‘vsprintf’ was not declared in this scope.
  • How does either tool interact with setup.py? pip is supposed to replace easy_install, but it's not clear whether it's a drop-in or more complicated relationship.
  • Is virtualenv only for development mode, or should the users also install it?
  • Will the resulting package be installed with the minimum requirements (like the current egg), or will it be installed with sources & binaries for all dependencies plus all the build tools, creating a gigabyte monster in the virtual environment?
  • Will the users have to modify their $PATH and $PYTHONPATH to run the resulting package if it's installed in a virtual environment?
  • Do I need to create a script from a text string for virtualenv like in the bad old days?
  • What is with the #egg=Package URL syntax? That's not part of the standard URL, so why isn't it a separate parameter?
  • Where is @rev included in the URL? At the end I suppose, but the documentation is not clear about this ("You can also include @rev in the URL").
  • What is supposed to be understood by using an existing requirements file as "as a sort of template for the new file"? This could mean any number of things.

推荐答案

哇,那是很多问题.他们中的许多人真的应该得到更多细节的自己的SO问题.我会尽力的:

Wow, that's quite a set of questions. Many of them would really deserve their own SO question with more details. I'll do my best:

首先是virtualenv和pip 应该处于可用状态 现在吗?

First of all, are virtualenv and pip supposed to be in a usable state by now?

是的,尽管它们不能满足所有人的需求. Pip和virtualenv(以及Python包管理中的所有其他功能)远非完美,但它们被广泛使用并依赖于此.

Yes, although they don't serve everyone's needs. Pip and virtualenv (along with everything else in Python package management) are far from perfect, but they are widely used and depended upon nonetheless.

应如何安装virtualenv? 我还没有准备好相信 就像其他地方所解释的那样令人费解.

How should virtualenv be installed? I'm not quite ready to believe it's as convoluted as explained elsewhere.

您链接的答案很复杂,因为它试图避免对全局Python安装进行任何更改,而是将所有内容安装在~/.local中.这具有一些优点,但是设置起来比较复杂.它还安装了 virtualenvwrapper ,这是一组用于处理virtualenv的便捷bash脚本,但是不需要使用virtualenv.

The answer you link is complex because it is trying to avoid making any changes at all to your global Python installation and install everything in ~/.local instead. This has some advantages, but is more complex to setup. It's also installing virtualenvwrapper, which is a set of convenience bash scripts for working with virtualenv, but is not necessary for using virtualenv.

如果您使用的是Ubuntu,则aptitude install python-setuptools后跟easy_install virtualenv应该可以为您提供有效的virtualenv安装,而不会对您的全局python环境造成任何损害(除非您还安装了Ubuntu virtualenv软件包,我不建议这样做)因为它可能是旧版本.

If you are on Ubuntu, aptitude install python-setuptools followed by easy_install virtualenv should get you a working virtualenv installation without doing any damage to your global python environment (unless you also had the Ubuntu virtualenv package installed, which I don't recommend as it will likely be an old version).

是否有一套经过测试的说明 有关如何在其中安装matplotlib 虚拟环境?因为某些原因 它总是想在这里编译 不仅仅是安装软件包, 并且总是以失败而告终(甚至 在build-dep之后占用了250 MB 磁盘空间).经过一堆 打印的警告 src/mplutils.cpp:17:错误:"vsprintf" 未在此范围内声明.

Is there a set of tested instructions for how to install matplotlib in a virtual environment? For some reason it always wants to compile it here instead of just installing a package, and it always ends in failure (even after build-dep which took up 250 MB of disk space). After a whole bunch of warnings it prints src/mplutils.cpp:17: error: ‘vsprintf’ was not declared in this scope.

它总是要编译",因为pip从设计上仅从源代码安装,而没有安装预编译的二进制文件.这是一个有争议的选择,可能是pip在Python Web开发人员中得到最广泛采用的主要原因,这些Web开发人员使用更多的纯Python程序包,并通常在标准的工作编译链的POSIX环境中进行开发和部署.

It "always wants to compile" because pip, by design, installs only from source, it doesn't install pre-compiled binaries. This is a controversial choice, and is probably the primary reason why pip has seen widest adoption among Python web developers, who use more pure-Python packages and commonly develop and deploy in POSIX environments where a working compilation chain is standard.

选择设计的原因是,提供预编译的二进制文件会在不同的平台和构建架构(包括python版本,UCS-2与UCS-4 python构建,32与64位...)之间出现组合爆炸问题. easy_install在大多数情况下都可以在PyPI上找到正确的二进制软件包的方式,但并不能解决所有这些因素,并且可能会破坏它.因此,pip完全避免了该问题(将其替换为您必须具有正常的编译环境).

The reason for the design choice is that providing precompiled binaries has a combinatorial explosion problem with different platforms and build architectures (including python version, UCS-2 vs UCS-4 python builds, 32 vs 64-bit...). The way easy_install finds the right binary package on PyPI sort of works, most of the time, but doesn't account for all these factors and can break. So pip just avoids that issue altogether (replacing it with a requirement that you have a working compilation environment).

在许多情况下,需要C编译的软件包的发布时间表也较慢,因此可以为它们简单地安装OS软件包是可以接受的.但是,这不允许在不同的virtualenv中使用它们的不同版本.

In many cases, packages that require C compilation also have a slower-moving release schedule and it's acceptable to simply install OS packages for them instead. This doesn't allow working with different versions of them in different virtualenvs, though.

我不知道是什么原因导致了您的编译错误,它通过以下一系列命令对我有用(在Ubuntu 10.10上):

I don't know what's causing your compilation error, it works for me (on Ubuntu 10.10) with this series of commands:

virtualenv --no-site-packages tmp
. tmp/bin/activate
pip install numpy
pip install -f http://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.0.1/matplotlib-1.0.1.tar.gz matplotlib

由于matplotlib的

The "-f" link is necessary to get the most recent version, due to matplotlib's unusual download URLs on PyPI.

这两种工具如何相互作用 setup.py?点子应该取代 easy_install,但不清楚 无论是嵌入式还是更多 复杂的关系.

How does either tool interact with setup.py? pip is supposed to replace easy_install, but it's not clear whether it's a drop-in or more complicated relationship.

setup.py文件是Python标准库的 distutils 的约定.包管理解决方案".仅distutils缺少一些关键功能,并且 setuptools 是广泛使用的第三方包容并扩展" distutils的软件包,以提供一些附加功能. setuptools也使用setup.py. easy_install是与setuptools捆绑在一起的安装程序. Setuptools的开发停滞了数年, distribute 是setuptools的一个分支,用于修复一些长期存在的错误.最终,通过将分发重新合并到setuptools中来解决了该派生问题,setuptools开发现在又重新激活(使用新的维护程序).

The setup.py file is a convention of distutils, the Python standard library's package management "solution." distutils alone is missing some key features, and setuptools is a widely-used third-party package that "embraces and extends" distutils to provide some additional features. setuptools also uses setup.py. easy_install is the installer bundled with setuptools. Setuptools development stalled for several years, and distribute was a fork of setuptools to fix some longstanding bugs. Eventually the fork was resolved with a merge of distribute back into setuptools, and setuptools development is now active again (with a new maintainer).

distutils2 是主要重写的distutils新版本,试图将来自setuptools/distribute的最佳创意,并且应该成为Python标准库的一部分.不幸的是,这项工作失败了,因此setuptools暂时仍然是Python打包的事实上的标准.

distutils2 was a mostly-rewritten new version of distutils that attempted to incorporate the best ideas from setuptools/distribute, and was supposed to become part of the Python standard library. Unfortunately this effort failed, so for the time being setuptools remains the de facto standard for Python packaging.

Pip替代easy_install,但不替代setuptools;它需要setuptools并在其之上构建.因此,它也使用setup.py.

Pip replaces easy_install, but it does not replace setuptools; it requires setuptools and builds on top of it. Thus it also uses setup.py.

virtualenv仅用于开发 模式,或者用户也应该安装 它吗?

Is virtualenv only for development mode, or should the users also install it?

对此没有唯一正确的答案;可以使用任何一种方式.最后,这实际上是用户的选择,理想情况下,您的软件应该可以在virtualenv内部或外部安装;尽管您可能选择记录并强调一种方法或另一种方法.这很大程度上取决于您的用户是谁,以及他们可能需要将您的软件安装到什么环境中.

There's no single right answer to that; it can be used either way. In the end it's really your user's choice, and your software ideally should be able to be installed inside or out of a virtualenv; though you might choose to document and emphasize one approach or the other. It depends very much on who your users are and what environments they are likely to need to install your software into.

生成的软件包将是 最小安装 要求(例如当前的鸡蛋), 或将与源&一起安装 所有依赖项的二进制文件加上所有 构建工具,创建一个千兆字节 虚拟环境中的怪物?

Will the resulting package be installed with the minimum requirements (like the current egg), or will it be installed with sources & binaries for all dependencies plus all the build tools, creating a gigabyte monster in the virtual environment?

如果需要编译的软件包是通过pip安装的,则需要从源代码进行编译.这也适用于任何需要编译的依赖项.

If a package that requires compilation is installed via pip, it will need to be compiled from source. That also applies to any dependencies that require compilation.

这与是否使用virtualenv问题无关. easy_install在virtualenv中是默认可用的,并且在这里可以正常工作.它可以安装预编译的二进制鸡蛋,就像在virtualenv外部一样.

This is unrelated to the question of whether you use a virtualenv. easy_install is available by default in a virtualenv and works just fine there. It can install pre-compiled binary eggs, just like it does outside of a virtualenv.

用户将不得不修改他们的 $ PATH和$ PYTHONPATH运行 生成的软件包(如果已安装在其中) 虚拟环境?

Will the users have to modify their $PATH and $PYTHONPATH to run the resulting package if it's installed in a virtual environment?

为了使用virtualenv中安装的任何内容,您需要使用virtualenv的bin/目录中的python二进制文件(或安装在virtualenv中的另一个引用此二进制文件的脚本).最常见的方法是使用virtualenv的activateactivate.bat脚本临时修改外壳程序PATH,因此,virtualenv的bin/目录是第一个.使用virtualenv修改PYTHONPATH通常不是有用或不必要的.

In order to use anything installed in a virtualenv, you need to use the python binary in the virtualenv's bin/ directory (or another script installed into the virtualenv that references this binary). The most common way to do this is to use the virtualenv's activate or activate.bat script to temporarily modify the shell PATH so the virtualenv's bin/ directory is first. Modifying PYTHONPATH is not generally useful or necessary with virtualenv.

我需要从一个脚本创建脚本吗? virtualenv的文本字符串,例如 过去的日子不好?

Do I need to create a script from a text string for virtualenv like in the bad old days?

否.

#egg =包装网址是什么 句法?那不属于 标准网址,为什么不这样 单独的参数?

What is with the #egg=Package URL syntax? That's not part of the standard URL, so why isn't it a separate parameter?

#egg = projectname-version" URL片段被黑客入侵首先是

The "#egg=projectname-version" URL fragment hack was first introduced by setuptools and easy_install. Since easy_install scrapes links from the web to find candidate distributions to install for a given package name and version, this hack allowed package authors to add links on PyPI that easy_install could understand, even if they didn't use easy_install's standard naming conventions for their files.

URL中的@rev在哪里?在 我猜到底,但是 文档尚不清楚 (您还可以在@ URL").

Where is @rev included in the URL? At the end I suppose, but the documentation is not clear about this ("You can also include @rev in the URL").

在引用的片段后面有几句话,其中有一个指向阅读需求文件格式的链接了解其他功能." @rev功能已被完整记录并在此处进行了演示.

A couple sentences after that quoted fragment there is a link to "read the requirements file format to learn about other features." The @rev feature is fully documented and demonstrated there.

应该理解什么 使用现有的需求文件作为 作为新模板的一种 文件"?这可能意味着任意数量的 事情.

What is supposed to be understood by using an existing requirements file as "as a sort of template for the new file"? This could mean any number of things.

第二句话说:它将按顺序保留devel-req.txt中列出的软件包,并保留注释."我不确定会有什么更好的简洁描述.

The very next sentence says "it will keep the packages listed in devel-req.txt in order and preserve comments." I'm not sure what would be a better concise description.

这篇关于从setuptools迁移到pip + virtualenv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆