安装HTML:AttributeError:'str'对象没有属性'decode'

时间:2016-12-25 08:28:46

标签: html python-3.x installation

我尝试安装包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'对象没有属性'decode',但是所有这些都是代码 如何通过安装来修复探针?

1 个答案:

答案 0 :(得分: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<'