Skip to main content
 首页 » 编程设计

python之没有名为请求 PythonAnywhere 错误的模块

2025年05月04日17Free-Thinker

我需要在我的代码中使用 urllib 模块,我这样导入它:

import urllib.request 
import urllib.error 

但 PythonAnywhere 返回以下错误:

> 没有名为 request 的模块

当我尝试时,看起来 urllib 库已成功导入:

python3 myscript.py

代替:

python myscript.py

但在这种情况下我得到另一个错误:

> 没有名为“pyvirtualdisplay”的模块

Pyvirtualdisplay 在我的代码中也需要,所以我不知道该怎么做。有人可以帮忙吗?

请您参考如下方法:

The urllib2 module has been split across several modules in Python 3 named urllib.request and urllib.error ~ urllib2 - python docs

当你运行你的脚本时使用

python myscript.py

您的系统使用的是 python2,它没有 urllib.request 和 urllib.error 模块。使用 urllib2 库。