为什么在python中执行此操作时会出现以下错误:
>>> import locale
>>> print str( locale.getlocale() )
(None, None)
>>> locale.setlocale(locale.LC_ALL, 'de_DE')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/locale.py", line 531, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
Run Code Online (Sandbox Code Playgroud)
这适用于其他语言环境,如fr或nl.我正在使用Ubuntu 11.04.
更新:执行以下操作不会产生任何结果:
dpkg-reconfigure locales
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = "UTF-8",
LANG = (unset)
are supported and installed on your system.
perl: warning: Falling back to …Run Code Online (Sandbox Code Playgroud) 安装mechanize之后,我似乎无法导入它.
我尝试从pip,easy_install和via python setup.py install这个repo安装:https://github.com/abielr/mechanize.所有这一切都无济于事,因为每次我输入我的Python互动时,我得到:
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mechanize
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mechanize
>>>
Run Code Online (Sandbox Code Playgroud)
我之前运行的安装报告说它们已经成功完成,所以我希望导入能够正常工作.可能导致此错误的原因是什么?
我正在尝试创建一个脚本来从我的网站下载验证码。我认为代码可以正常工作,但不会出现该错误,当我在cmd中运行它时(我使用的是Windows,而不是Linux),我收到以下信息:
from bs4 import BeautifulSoup
ImportError: No module named bs4
Run Code Online (Sandbox Code Playgroud)
我尝试使用,pip install BeautifulSoup4
但是在安装时收到语法错误。
这是脚本:
from bs4 import BeautifulSoup
import urllib2
import urllib
url = "https://example.com"
content = urllib2.urlopen(url)
soup = BeautifulSoup(content)
img = soup.find('img',id ='imgCaptcha')
print img
urllib.urlretrieve(urlparse.urljoin(url, img['src']), 'captcha.bmp')
Run Code Online (Sandbox Code Playgroud)
根据此答案的问题一定是由于我尚未激活virtualenv,然后安装BeautifulSoup4。
另外,我认为这些信息不会有任何帮助,但是我将python文本保存在notepad.py中,并使用cmd运行它。