【问题标题】:When use pip to install flask-bcrypt, one error is :UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 49: ordinal not in range(128)使用 pip 安装 flask-bcrypt 时,一个错误是:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 49: ordinal not in range(128)
【发布时间】:2016-08-31 12:04:10
【问题描述】:

今天我安装flask-bcrypt的时候用到了:

pip install flask-bcrypt

发生了这个错误:

Command /home/sf/python/venv/bin/python2 -c "import setuptools, 
tokenize;__file__='/tmp/pip-build-duYRO6/bcrypt/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-hlvpv8-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/sf/python/venv/include/site/python2.7 failed with error code 1 in /tmp/pip-build-duYRO6/bcrypt
Traceback (most recent call last):
  File "/home/sf/python/venv/bin/pip", line 11, in <module>
    sys.exit(main())
  File "/home/sf/python/venv/local/lib/python2.7/site-packages/pip/__init__.py", line 248, in main
    return command.main(cmd_args)
  File "/home/sf/python/venv/local/lib/python2.7/site-packages/pip/basecommand.py", line 161, in main
    text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 49: ordinal not in range(128)

【问题讨论】:

  • 你用的是什么版本的pip?
  • python2.7,对不起,我已经解决了这个问题,只是希望有同样问题的人可以看到我的答案。
  • 您的回答不是一个好方法,您不应该更改默认编码。 sys.getdefaultencoding() 对我来说是 ascii,我可以很好地安装包。 anonbadger.wordpress.com/2015/06/16/…
  • 我尝试了很多方法想解决这个问题(比如:ianbicking.org/illusive-setdefaultencoding.html),但都失败了。最后,我更改了默认编码,就解决了。可能是因为我的电脑用的是中文。

标签: python python-2.7 pip


【解决方案1】:

你可以尝试关注

export LANG=en_US.UTF-8
pip install flask-bcrypt

【讨论】:

    【解决方案2】:

    当你在命令下输入 python shell 时,

    >>> import sys
    >>> sys.getdefaultencoding()
    

    它会输出这个:

    'ascii'
    

    所以,我修改

    /etc/python2.7/sitecustomize.py
    

    添加:

    import sys
    sys.setdefaultencoding('utf-8')
    

    现在默认编码更改为:

    'utf-8'
    

    这个错误已解决,但还有另一个错误:

    Command /home/sf/python/venv/bin/python2 -c "import setuptools,  
    tokenize;__file__='/tmp/pip-build-6LgjpC/bcrypt/setup.py';
    exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', 
    '\n'), __file__, 'exec'))" install --record /tmp/pip-3qxBJi-record/install-
    record.txt --single-version-externally-managed --compile --install-headers 
    /home/sf/python/venv/include/site/python2.7 failed with error code 1 in 
    /tmp/pip-build-6LgjpC/bcrypt
    Storing debug log for failure in /home/sf/.pip/pip.log
    

    你可以看到这个:when I try to install Flask-bcrypt it throws me error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    我只是安装:

    apt-get install libffi-dev
    

    最后,我成功安装了flask-bcrypt。

    【讨论】:

      猜你喜欢
      • 2018-11-02
      • 2013-12-31
      • 1970-01-01
      • 1970-01-01
      • 2017-05-21
      • 1970-01-01
      • 1970-01-01
      • 2018-08-25
      • 1970-01-01
      相关资源
      最近更新 更多