应该安装python-dev来安装pip [英] Should python-dev be required to install pip

查看:393
本文介绍了应该安装python-dev来安装pip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现许多人在用pip安装python软件包时遇到了麻烦,因为未安装python-dev.主要是错误:

I find that many people have troubles installing python packages with pip because python-dev is not installed. Mainly, the error:

fatal error: Python.h: No such file or directory

那么问题是:python-dev应该是pip的必需依赖项吗?还是这仅是针对通过pip安装的某些软件包的问题;如果是,是否采取某些步骤来确保用户在安装模块时不会遇到错误?

So the question: Should python-dev be a required dependency of pip? Or is this only an issue for certain packages being installed with pip, and if so, are there certain steps to take to ensure users do not encounter the error when installing your modules?

推荐答案

我不认为这实际上属于StackOverflow,但万一我错了……

I don't think this actually belongs on StackOverflow, but in case I'm wrong…

首先,python-dev不是Python,而是Ubuntu,Fedora或其他发行版.如果您下载,构建和安装Python,或者从python.org运行任何二进制安装程序,则会在适当的位置安装Python.h.许多linux发行版都喜欢将软件包拆分为子软件包,将只需要构建的内容移动到-dev或类似的软件包中,对Python这样做绝对没有错,但是发行版仍在这样做.

First, python-dev is not a Python thing, it's an Ubuntu or Fedora or some other distro thing. If you download, build, and install Python, or run any binary installer from python.org, you get Python.h installed in an appropriate place. Many linux distros like to split packages into subpackages, moving stuff you only need for building into a -dev or similar package, and there's absolutely nothing wrong with doing that to Python, but it's still something the distro is doing.

第二,不需要Python.h来构建所有软件包,只需要那些包含C扩展模块的软件包即可.由于许多软件包都是纯Python的,并且没有此类扩展模块,因此发行版的pip软件包不需要其python-dev软件包是有道理的. (就像发行版的pip包可能不需要C编译器一样.)

Second, Python.h is not needed for building all packages, only those that include C extension modules. Since many packages are pure-Python and have no such extension modules, it makes sense that a distro's pip package wouldn't require its python-dev package. (In the same way that a distro's pip package probably wouldn't require a C compiler.)

第三,大多数为您提供python-pip或类似软件包的发行版也为您提供了流行软件包的软件包.如果以这种方式安装它们,则由于它们是二进制软件包,则不需要python-dev(和C编译器),或者您将需要它们,但它们将作为依赖项(rpm,deb,等等.都有一种方法可以指定单独的"build"和"run"依赖项.

Third, most distros that give you a python-pip or similar package also give you packages for popular packages. If you install them that way, either you won't need python-dev (and a C compiler), because they're binary packages, or you will need them but they'll be pulled in as a dependency (rpm, deb, etc. all have a way to specify separate "build" and "run" dependencies).

但是,如果您落后于软件包管理器的后台并尝试使用pip安装软件包(这是很合理的做法),则软件包管理器将无法告诉您哪些软件包需要哪些依赖项,而pip可以只告诉您关于Python软件包的依赖关系,因此没有什么可强制执行的.

But if you go behind your package manager's back and try to install packages with pip (which is a reasonable thing to do), the package manager can't tell you which packages need what dependencies, while pip can only tell you about Python package dependencies, so there's nothing to enforce this.

这篇关于应该安装python-dev来安装pip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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