ImportError:无法导入名称<lib> python 2.7

时间:2020-07-14 04:02:44

标签: python python-2.7

我正在尝试为Python中的ecdsa库在tox -e coverage中运行python2.7

src/ecdsa/util.py文件如下:

import os
import math
import sys
import binascii
from hashlib import sha256
from . import der
from .curves import orderlen

但是,当我运行tox -e coverage时,出现以下错误:

________________________________ ERROR collecting src/ecdsa/test_numbertheory.py _________________________________
/usr/lib/python2.7/dist-packages/py/_path/local.py:650: in pyimport
    __import__(modname)
src/ecdsa/__init__.py:1: in <module>
    from .keys import (
src/ecdsa/keys.py:62: in <module>
    from . import ecdsa
src/ecdsa/ecdsa.py:59: in <module>
    from .util import bit_length
src/ecdsa/util.py:9: in <module>
    from . import der
E   ImportError: cannot import name der

python2.7中导入这些库的正确方法是什么?

更新:

因此,在src/ecdsa/ecdsa.py中,我具有以下定义:

# NIST Curve P-192:
_p = 6277101735386680763835789423207666416083908700390324961279
_r = 6277101735386680763835789423176059013767194773182842284081
# s = 0x3045ae6fc8422f64ed579528d38120eae12196d5L
# c = 0x3099d2bbbfcb2538542dcd5fb078b6ef5f3d6fe2c745de65L
_b = 0x64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1
_Gx = 0x188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012
_Gy = 0x07192B95FFC8DA78631011ED6B24CDD573F977A11E794811

curve_192 = ellipticcurve.CurveFp(_p, -3, _b)
generator_192 = ellipticcurve.Point(curve_192, _Gx, _Gy, _r)

src/ecdsa/curves.py里面,我有

import der
import ecdsa

运行tox -e coverage时出现以下错误:

____________________________________ ERROR collecting src/ecdsa/test_ecdsa.py ____________________________________
/usr/lib/python2.7/dist-packages/py/_path/local.py:650: in pyimport
    __import__(modname)
src/ecdsa/__init__.py:1: in <module>
    from keys import (
src/ecdsa/keys.py:62: in <module>
    import ecdsa
src/ecdsa/ecdsa.py:59: in <module>
    from util import bit_length
src/ecdsa/util.py:10: in <module>
    from curves import orderlen
src/ecdsa/curves.py:36: in <module>
    ecdsa.curve_192,
E   AttributeError: 'module' object has no attribute 'curve_192'

0 个答案:

没有答案