Python 3.4和2.7:无法为python 3.4安装numpy包

SmC*_*lar 32 python ubuntu numpy pip python-3.4

我正在使用Ubuntu 12.04并希望与python 2.7并排使用python 3.4.

python 3.4的安装工作正常.但是,我无法安装python 3的numpy包(因此我无法安装scipy,pandas等).

运用

 sudo pip3 install numpy
Run Code Online (Sandbox Code Playgroud)

吐出以下错误:

File "numpy/core/setup.py", line 289, in check_types

"Cannot compile 'Python.h'. Perhaps you need to "\

SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.
Run Code Online (Sandbox Code Playgroud)

顺便说一句,我已经安装了python-dev.

而且,安装numpy via

 sudo apt-get install python-numpy
Run Code Online (Sandbox Code Playgroud)

不起作用,因为我已经为python 2.7安装了numpy,安装程序响应numpy已经是最新的.

我能做什么?谢谢!

Mar*_*ers 70

您尚未安装Python 3 开发包.安装python3.4-dev:

apt-get install python3.4-dev
Run Code Online (Sandbox Code Playgroud)

主程序包从不包含开发标题; Debian(以及扩展的Ubuntu)包策略是将它们放入一个单独的-dev包中.numpy但是要安装,您需要这些文件才能编译扩展.

  • 对于那些在2015年以类似查询到达的人(如我所做),需要将上述命令更改为`apt-get install python3.5-dev`. (5认同)
  • 对于未来的任何人:调整命令以适合您当前的Python版本.是的,Ubuntu不会读你的想法或日历.:-P (2认同)
  • 或者您可以只使用“ apt-get install python3-dev”,而ubuntu会记住您的想法并为您的Ubuntu版本安装正确的发行版。 (2认同)
  • @DaveLeBlanc:这取决于 Ubuntu 版本,哪个版本是“当前”版本。在 12.04 上,这是 [Python 3.2](https://launchpad.net/ubuntu/precise/+package/python3-dev),而不是 3.4。 (2认同)