dlage
2020-12-02 17:31
采纳率: 100%
浏览 364

ModuleNotFoundError: No module named 'sgmllib'

pytorch的官方教程,执行到下面的代码就报错。
import transforms as T

def get_transform(train):
    transforms = []
    transforms.append(T.ToTensor())
    if train:
        transforms.append(T.RandomHorizontalFlip(0.5))
    return T.Compose(transforms)

报错:

Traceback (most recent call last):
  File "D:\software\software\Anaconda\envs\pyt_GPU\lib\site-packages\IPython\core\interactiveshell.py", line 3343, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-38-8f09a7ff1c98>", line 1, in <module>
    import transforms as T
  File "D:\software\software\Pycharm\PyCharm Community Edition 2020.2.4\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "D:\software\software\Anaconda\envs\pyt_GPU\lib\site-packages\transforms\__init__.py", line 1, in <module>
    from .safe_html import safe_html, bodyfinder
  File "D:\software\software\Pycharm\PyCharm Community Edition 2020.2.4\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "D:\software\software\Anaconda\envs\pyt_GPU\lib\site-packages\transforms\safe_html.py", line 1, in <module>
    from sgmllib import SGMLParser, SGMLParseError
  File "D:\software\software\Pycharm\PyCharm Community Edition 2020.2.4\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'sgmllib'


 

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • frootguo 2020-12-02 18:17
    已采纳

    经过查阅资料发现python3.6.1已经没有这个库了,坑人啊。。。。。

    sgmllib是2.6以后引入python,在3.0以后这个库被移除了。如果你的python版本<2.6或者>=3.0就找不到这个module。
    如果你要使用已有的、依赖sgmllib的代码,安装python2.7等合适的版本。如果要迁移到3.0环境,需要移植代码,可以使用html.parser.HTMLParser

    评论
    解决 无用
    打赏 举报
查看更多回答(3条)

相关推荐 更多相似问题