I need to use urllib module in my code and I import it like this:
import urllib.request
import urllib.error
but PythonAnywhere returns the following error:
> No module named request
It looks like the urllib library is imported successfully when I try:
python3 myscript.py
instead of:
python myscript.py
But in this case I get another error:
> No module named 'pyvirtualdisplay'
Pyvirtualdisplay is also needed in my code, so I dont know what to do. Can someone help ?
The urllib2 module has been split across several modules in Python 3 named urllib.request and urllib.error ~ urllib2 - python docs
When you run your script using
python myscript.py
Your system is using python2 which doesn't have the urllib.request
and urllib.error
modules. Use the urllib2
library.
You need to install Python extensions into each copy of Python that you use. For example, python
and python3
use different set of extensions. You may have a script called pip3
that installs extensions into your copy of Python 3.
Installation instructions on the PyVirtualDisplay project page state that first you'll need to install pip and Pillow for Python 3. If you were using a Debian or Ubuntu VPS, these might work in a terminal:
sudo apt-get update
sudo apt-get install python3-pip python3-imaging
sudo pip3 install pyvirtualdisplay
But a Google search tells me PythonAnywhere is a web application hosting service. The list of supported extensions includes pyvirtualdisplay in Python 2 but not in Python 3. Just a guess, but the administrators may not be aware that pyvirtualdisplay has been ported. I'd recommend contacting PythonAnywhere support and requesting the extension's installation into Python 3.
您可以为python 3自己安装pyvirtualdisplay。可以使用virtualenv(帮助页面上有详细信息),也可以使用--user
参数对pip进行设置,并确保使用正确版本的pip( pip3.3
或pip3.4
具体取决于您要使用的版本)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.