安装Python的Numba模块

24

我正在尝试为Python安装numba,但在按照首页的说明后,出现了“找不到extension_types页面”的错误。

如果有人知道我做错了什么,或者我错过了应该安装的东西,我将非常感激。

非常感谢您的帮助。

Python 2.7.2+ (default, Jul 20 2012, 22:15:08) 
Type "copyright", "credits" or "license" for more information.

IPython 0.10.2 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.

In [1]: import numba
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)

/home/mijc/Downloads/numba/<ipython console> in <module>()

/home/mijc/Downloads/numba/numba/__init__.py in <module>()
      2 # type inferer

      3 from numba.special import *
----> 4 from numba import module_type_inference
      5 
      6 import os

/home/mijc/Downloads/numba/numba/module_type_inference.py in <module>()
      6 from numba import *
      7 from numba.minivect import minitypes
----> 8 from numba import typesystem, symtab
      9 
     10 import numpy.random

/home/mijc/Downloads/numba/numba/typesystem/__init__.py in <module>()
      2 from exttypes import *
      3 from closuretypes import *
      4 from ssatypes import *
      5 from templatetypes import *
      6 from typemapper import *

/home/mijc/Downloads/numba/numba/typesystem/basetypes.py in <module>()
      6 
      7 import numba
----> 8 from numba import  extension_types, error
      9 from numba.minivect.minitypes import *
     10 from numba.minivect.minitypes import map_dtype

ImportError: cannot import name extension_types

编辑: 我通过以下方式安装了numba:

git clone https://github.com/numba/numba.git
cd numba
python setup.py install

当我尝试通过pip安装时,出现以下错误:

pip install numba --upgrade
Downloading/unpacking numba
  Downloading numba-0.5.0.tar.gz (333Kb): 333Kb downloaded
  Running setup.py egg_info for package numba
    Traceback (most recent call last):
      File "<string>", line 14, in <module>
      File "/home/mijc/Downloads/numba/build/numba/setup.py", line 90, in <module>
        cython_gdb=True),
      File "/usr/local/lib/python2.7/dist-packages/Cython/Distutils/extension.py", line 108, in __init__
        **kw)
    TypeError: unbound method __init__() must be called with Extension instance as first argument (got Extension instance instead)
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 14, in <module>

  File "/home/mijc/Downloads/numba/build/numba/setup.py", line 90, in <module>

    cython_gdb=True),

  File "/usr/local/lib/python2.7/dist-packages/Cython/Distutils/extension.py", line 108, in __init__

    **kw)

TypeError: unbound method __init__() must be called with Extension instance as first argument (got Extension instance instead)

----------------------------------------
Command python setup.py egg_info failed with error code 1

你是怎么安装numba的?我在这里使用pip没有遇到问题:https://dev59.com/zm3Xa4cB1Zd3GeqPhaxB#14527365 - BenDundee
我使用了pip。我安装了Cython、llvmpy、meta和numba。 编辑:不对,实际上我没有这样做。我获取了一个git仓库并安装了它。当我尝试通过pip安装时,出现了错误。 - mijc
看起來錯誤都來自同一個地方?安裝時您有運行測試嗎?我記得是 python setup.py test,對吧? - BenDundee
很遗憾,Numba的setup.py没有提供测试。 - mijc
我在安装Spacy时遇到了相同的错误。 - Glycerine
尝试运行 python -m pip install --user numba 进行安装。 - billa-code
8个回答

11

我希望你正在使用Linux,并且已经安装了pip。

在我的Debian Linux上,我可以通过以下命令轻松安装numba:

sudo apt-get install build-essential
sudo apt-get install llvm
pip install llvmpy
pip install cython
pip install numba

那么你完成了!


3
我从pip install llvmpy得到以下错误: 收集llvmpy 正在使用缓存的llvmpy-0.12.7.tar.gz 来自命令python setup.py egg_info的完整输出: 错误:无法调用['llvm-config','--version'] 尝试设置LLVM_CONFIG_PATH=/path/to/llvm-config 注意:我已经安装了llvm。 - Andrei Sura

6
在Windows上,我遇到了同样的问题, 我安装了Miniconda, 执行了相应的操作。
conda install numba 

这将安装一个带有所有Numba包的Python解释器。然后,我将这些包复制到了我的解释器环境中。

完成!


5

我遇到了同样的问题,对我来说解决方案是升级distribute到0.6.45。


3
我看到这个问题有点老,但我会把我的经验放在这里,以防帮助其他人搜索。对我而言,最简单的解决方案是安装Anaconda发行版:https://store.continuum.io/请注意,有一个“非常免费”的版本供一般使用,还有一个不错的学术版本供...嗯,学术使用。:)
Numba实际上得到了Continuum的支持,至少根据他们的教程之一。我已经安装了它,并且现在开始尝试使用它。到目前为止,我很喜欢它(尽管在让一些我之前创建的Cython模块与它良好协作方面遇到了一些小问题)。如果您选择Continuum路线,他们有一个有点隐藏的博客,我发现很有用(主页上的链接位于“公司”下,这不是我首先查找的地方)。查看标记为“Numba”的内容;那里有示例。
我使用Anaconda和Numba的另一个秘密原因是:他们似乎相对较新,我猜测他们可能会非常关注解决你在他们的发行版中使用Numba时遇到的问题或疑问,希望建立良好的声誉和产品等。当然,这只是我的猜测。
唯一的缺点是:Anaconda中没有包含Picloud。过去我经常使用它,所以这很令人失望。这意味着我需要多做一些工作,但无需任何工作也不错 :)
注意:我与Continuum没有任何关联。迄今为止,我只是对他们的产品感到惊喜。

2
以下代码解决了我的问题。
python -m pip install --user numba

这是针对Ubuntu操作系统的。


同样适用于MacOS。 - Lavi Avigdor

1

尝试:

pip install numba==0.48

看起来decorators模块在较新的numba版本中已被删除。


0
使用 virtualenv 创建一个新的虚拟环境,并按照安装说明中的顺序在此环境中安装所有所需组件。

-1

我曾经遇到同样的问题,但是我通过在代码中先导入pandas再导入quantecon来解决它:

import pandas as pd
import quantecon as qe

这对我有效。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接