【问题标题】:Python Error: Able to run the program from command line but not from IDEPython 错误:能够从命令行但不能从 IDE 运行程序
【发布时间】:2013-03-29 20:58:28
【问题描述】:

我正在尝试使用 Charm Cryptography 库。我已经安装了库,我可以看到 Python/Lib/site-packages 中的鸡蛋。当我使用命令行运行以下程序时,它确实如此,但是当我尝试将 Eclipse 与 PyDev 插件一起使用时,它给了我这个错误。我使用的是 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']

【问题讨论】:

  • 我也有同样的问题,请问您的问题解决了吗?

标签: python python-2.7 jython


【解决方案1】:

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

import sys
print sys.path

在命令行中与通过 PyDev。

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

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

【讨论】:

  • 我只能希望事情如此简单。我已经配置了 Python 路径。我可以从命令行和 Eclipse 运行它
  • 两条路径是否相同?可能是你在一个路径中有额外的东西,导致解释器在错误的地方寻找东西。
  • 我已经从命令行和IDE添加了Python路径的输出。
  • 你有没有尝试将eclipse中的python路径设置为命令行的路径?
  • 我不认为该错误与 Python 路径有关。它清楚地表明缺少某些 DLL。我会尝试使用 Dependency Walker 来追踪它。
猜你喜欢
  • 1970-01-01
  • 2018-11-11
  • 1970-01-01
  • 1970-01-01
  • 2017-11-21
  • 1970-01-01
  • 1970-01-01
  • 2019-01-08
  • 2011-04-16
相关资源
最近更新 更多