推荐学习书目
› 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 · 4260 views
    This topic created in 4039 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
    henryon
    Oct 13, 2015
    1
    AttributeError: 'module' object has no attribute 'sha1'
    22too
    22too
    Oct 13, 2015
    2
    代码问题吧,不是你的环境问题,
    ligx
    ligx
    OP
    Oct 13, 2015
    3
    @22too

    import hashlib

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

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