V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ligx
V2EX  ›  Python

命令行运行在 gvim 里的 python 代码报错,而在 Pycharm 中运行没有错?

  •  
  •   ligx · 2015-10-13 11:28:07 +08:00 · 2906 次点击
    这是一个创建于 3125 天前的主题,其中的信息可能已经有所发展或是发生改变。

    同样的代码,用命令行运行 gvim 中的 python 代码报错,但是在 Pycharm 中运行就没有错。
    错误信息是:
    Traceback (most recent call last):
    File "E:\Python\lib\threading.py", line 901, in _boots
    self.run()
    File "websocket_Demo.py", line 28, in run
    sha1 = hashlib.sha1()
    AttributeError: 'module' object has no attribute 'sha1'

    这是怎么回事?

    7 条回复    2015-10-13 15:27:29 +08:00
    henryon
        1
    henryon  
       2015-10-13 12:27:40 +08:00
    AttributeError: 'module' object has no attribute 'sha1'
    22too
        2
    22too  
       2015-10-13 13:08:21 +08:00
    代码问题吧,不是你的环境问题,
    ligx
        3
    ligx  
    OP
       2015-10-13 13:25:44 +08:00
    @22too

    import hashlib

    sha1 = hashlib.sha1()
    sha1.update((secKey+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11").encode())
    sha1_result = sha1.digest()

    这有问题吗?我没看出来
    likexian
        4
    likexian  
       2015-10-13 13:30:10 +08:00
    est
        5
    est  
       2015-10-13 13:33:00 +08:00
    你自己某个文件名字叫 hashlib 了。。
    ligx
        6
    ligx  
    OP
       2015-10-13 13:39:36 +08:00
    @est
    还真是!找到一个同名的 py 文件!
    谢了!
    firemiles
        7
    firemiles  
       2015-10-13 15:27:29 +08:00
    @est python package 和非 package 的包导入策略不同很蛋疼,导入本地包全部要求显示 from . 多好
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2428 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:34 · PVG 21:34 · LAX 06:34 · JFK 09:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.