V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Oct 13, 2015 · 3771 views
    This topic created in 3855 days ago, the information mentioned may be changed or developed.

    同样的代码,用命令行运行 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 replies    2015-10-13 15:27:29 +08:00
    henryon
        1
    henryon  
       Oct 13, 2015
    AttributeError: 'module' object has no attribute 'sha1'
    22too
        2
    22too  
       Oct 13, 2015
    代码问题吧,不是你的环境问题,
    ligx
        3
    ligx  
    OP
       Oct 13, 2015
    @22too

    import hashlib

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

    这有问题吗?我没看出来
    likexian
        4
    likexian  
       Oct 13, 2015
    est
        5
    est  
       Oct 13, 2015
    你自己某个文件名字叫 hashlib 了。。
    ligx
        6
    ligx  
    OP
       Oct 13, 2015
    @est
    还真是!找到一个同名的 py 文件!
    谢了!
    firemiles
        7
    firemiles  
       Oct 13, 2015
    @est python package 和非 package 的包导入策略不同很蛋疼,导入本地包全部要求显示 from . 多好
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2440 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 04:51 · PVG 12:51 · LAX 21:51 · JFK 00:51
    ♥ Do have faith in what you're doing.