【问题标题】:Install HTML: AttributeError: 'str' object has no attribute 'decode'安装 HTML: AttributeError: 'str' object has no attribute 'decode'
【发布时间】:2017-05-10 05:43:30
【问题描述】:

我尝试安装一个 HTML 包

python -m pip install HTML

Collecting HTML
  Using cached html-1.16.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\836D~1\AppData\Local\Temp\pip-build-xorbgx2e\HTML\setup.py", line 12, in <module>
        long_description = __doc__.decode('utf8'),
    AttributeError: 'str' object has no attribute 'decode'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\836D~1\AppData\Local\Temp\pip-build-xorbgx2e\HTML\

这个话题有很多问题 AttributeError: 'str' object has no attribute 'decode' but all of them for codes 如何通过安装修复探针?

【问题讨论】:

  • 看起来是表明包与 Python 3 不兼容的错误类型。
  • 你是对的!我不得不更改文件 setup.py 和 HTML.py。它适用于 Python 2

标签: html python-3.x installation


【解决方案1】:

html 添加到我的诗歌依赖文件然后运行poetry install 时遇到同样的问题:

Installing html (1.16): Failed

  EnvCommandError

  Command ['/project/.venv/bin/pip', 'install', '--no-deps', 'file:///home/user/.cache/pypoetry/artifacts/61/22/77/84e447e3655751d6c09f6688ea66d472bc206ff8f78f1e2ab51a5d6f0d/html-1.16.tar.gz'] errored with the following return code 1, and output: 
  Processing /home/user/.cache/pypoetry/artifacts/61/22/77/84e447e3655751d6c09f6688ea66d472bc206ff8f78f1e2ab51a5d6f0d/html-1.16.tar.gz
      ERROR: Command errored out with exit status 1:
       command: /home/user/project/.venv/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-i3m5e2vo/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-i3m5e2vo/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-4j0cpo0e
           cwd: /tmp/pip-req-build-i3m5e2vo/
      Complete output (5 lines):
      Traceback (most recent call last):
        File "<string>", line 1, in <module>
        File "/tmp/pip-req-build-i3m5e2vo/setup.py", line 12, in <module>
          long_description = __doc__.decode('utf8'),
      AttributeError: 'str' object has no attribute 'decode'
      ----------------------------------------
  ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

同样,尝试使用 pip 安装 html 并得到 ModuleNotFoundError 错误:

ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-p5pkr50r/html/setup.py'"'"'; __file__='"'"'/tmp/pip-install-p5pkr50r/html/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-p5pkr50r/html/pip-egg-info
         cwd: /tmp/pip-install-p5pkr50r/html/
    Complete output (15 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/python3.8/site-packages/setuptools/__init__.py", line 20, in <module>
        from setuptools.depends import Require
      File "/usr/lib/python3.8/site-packages/setuptools/depends.py", line 6, in <module>
        from .py33compat import Bytecode
      File "/usr/lib/python3.8/site-packages/setuptools/py33compat.py", line 11, in <module>
        from six.moves import html_parser
      File "/usr/lib/python3.8/site-packages/six.py", line 92, in __get__
        result = self._resolve()
      File "/usr/lib/python3.8/site-packages/six.py", line 115, in _resolve
        return _import_module(self.mod)
      File "/usr/lib/python3.8/site-packages/six.py", line 82, in _import_module
        __import__(name)
    ModuleNotFoundError: No module named 'html.parser'; 'html' is not a package
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

那时我意识到,我不需要在 Python 3 中显式安装 html。它已包含在内。

此代码默认适用于我:

import html

print(html.unescape("Hello&lt"))  # prints 'Hello<'

【讨论】:

    猜你喜欢
    • 2021-06-05
    • 2020-04-26
    • 1970-01-01
    • 2020-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-01
    相关资源
    最近更新 更多