Python错误:能够从命令行运行程序,但不能从IDE运行

时间:2013-03-29 20:58:28

标签: python python-2.7 jython

我正在尝试使用Charm Cryptography库。我已经安装了库,我可以看到Python / Lib / site-packages中的egg。当我使用命令行运行下面的程序时,但是当我尝试使用带有PyDev插件的Eclipse时,它给了我这个错误。我使用的是Python 2.7,Windows 7.如果需要任何其他信息,请告诉我。

Traceback (most recent call last):
  File "C:\Users\raunak\Documents\workspace1\ABETest\src\test\ABETest.py", line 6, in <module>
    from charm.toolbox.pairinggroup import PairingGroup,GT
  File "C:\Python27\Lib\site-packages\Charm_Crypto-0.42-py2.7-win32.egg\charm\toolbox\pairinggroup.py", line 2, in <module>
    from charm.core.math.pairing import pairing,ZR,G1,G2,GT,init,pair,hashPair,H,random,serialize,deserialize,ismember,order
ImportError: DLL load failed: The specified module could not be found.


from charm.toolbox.pairinggroup import PairingGroup,GT
from charm.schemes.abenc.abenc_waters09 import CPabe09
group = PairingGroup('SS512')
cpabe = CPabe09(group)
msg = group.random(GT)
(master_secret_key, master_public_key) = cpabe.setup()
policy = '((ONE or THREE) and (TWO or FOUR))'
attr_list = ['THREE', 'ONE', 'TWO']
secret_key = cpabe.keygen(master_public_key, master_secret_key, attr_list)
cipher_text = cpabe.encrypt(master_public_key, msg, policy)
decrypted_msg = cpabe.decrypt(master_public_key, secret_key, cipher_text)
print decrypted_msg == msg

更新

Python Path from IDE:
['C:\\Users\\raunak\\Documents\\workspace1\\ABETest\\src\\test', 
'C:\\Users\\raunak\\Documents\\workspace1\\ABETest\\src', 
'C:\\Python27\\Lib\\site-packages\\distribute-0.6.35-py2.7.egg', 
'C:\\Python27\\Lib\\site-packages\\Charm_Crypto-0.42-py2.7-win32.egg', 
'C:\\Python27\\DLLs', 
'C:\\Python27\\lib', 
'C:\\Python27\\lib\\plat-win', 
'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 
'C:\\Python27\\lib\\site-packages', 
'C:\\eclipse\\plugins\\org.python.pydev_2.7.3.2013031601\\pysrc\\pydev_sitecustomize', 
'C:\\Windows\\system32\\python27.zip', 
'C:\\Python27\\lib\\plat-win']

Python From Command Line:
['C:\\', 
'C:\\Python27\\lib\\site-packages\\distribute-0.6.35-py2.7.egg', 
'C:\\%JYTHONPATH%', 
'C:\\Windows\\system32\\python27.zip', 
'C:\\Python27\\DLLs', 
'C:\\Python27\\lib', 
'C:\\Python27\\lib\\plat-win', 
'C:\\Python27\\lib\\lib-tk', 
'C:\\Python27', 
'C:\\Python27\\lib\\site-packages', 
'C:\\Python27\\lib\\site-packages\\Charm_Crypto-0.42-py2.7-win32.egg']

1 个答案:

答案 0 :(得分:0)

这可能是Python路径问题。比较跑步:

import sys
print sys.path

在你的命令行中通过PyDev。

一旦找到缺失的项目,就可以像任何其他列表一样添加到python路径,例如:

import os
sys.path.append(os.path.join("C:\\", "folder", "file"))