html - 安装 HTML : AttributeError: 'str' object has no attribute 'decode'

标签 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' object has no attribute 'decode' but all them for codes 如何通过安装修复问题?

最佳答案

我在将 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<'

关于html - 安装 HTML : AttributeError: 'str' object has no attribute 'decode' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41319726/

相关文章:

html - 如何使用混合混合模式和隔离的CSS组合?

python - 如何在Python中构造对称矩阵

python - 为什么我的 getpass.getpass() 不工作?

python-3.x - Pymongo update_one

php - 升级到 PHP 5.3 后,如何通过将 session_unregister 替换为 $SESSION[] 来避免弃用警告?

wix - MSI/WiX - 在多实例转换期间分配组件 GUID

css - 如何在响应式布局上添加页脚?

javascript - Twitter Bootstrap 轮播不会在悬停/鼠标悬停时暂停

git - 在 Atom 中为 Linter 包安装包模块

javascript - 选择html表的一些行,并在单击链接时将所选行的一列的值发送到另一个php页面