Questions tagged «python-2.7»

Python 2.7是2.x系列的最后一个主要版本,并且自2020年1月1日起不再维护。请勿仅使用此标记来传达您正在使用的Python版本,除非该问题涉及特定于Python的问题2.7。使用更通用的[python]标记。

11
(13:权限被拒绝)连接到上游时:[nginx]
我正在使用Nginx和Gunicorn配置Django项目。 当我访问gunicorn mysite.wsgi:application --bind=127.0.0.1:8001Nginx服务器中的端口时,我的错误日志文件中出现以下错误; 2014/05/30 11:59:42 [crit] 4075#0:* 6 connect()到127.0.0.1:8001在连接到上游时失败(13:权限被拒绝),客户端:127.0.0.1,服务器:localhost,请求:“ GET / HTTP / 1.1”,上游:"http://127.0.0.1:8001/",主机:“ localhost:8080” 以下是我nginx.conf文件的内容; server { listen 8080; server_name localhost; access_log /var/log/nginx/example.log; error_log /var/log/nginx/example.error.log; location / { proxy_pass http://127.0.0.1:8001; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $http_host; } } 在HTML页面中,我得到了502 Bad Gateway。 我在做什么错?

5
如何在Python 2.7中隐藏子进程的输出
我在Ubuntu上使用eSpeak,并且有一个Python 2.7脚本可以打印和显示一条消息: import subprocess text = 'Hello World.' print text subprocess.call(['espeak', text]) eSpeak产生所需的声音,但由于一些错误(ALSA lib ...,没有套接字连接)而使外壳混乱,因此我无法轻松读取之前打印的内容。退出代码为0。 不幸的是,没有记录的选项可以关闭其详细信息,因此我正在寻找一种方法,仅在视觉上使其静音并保持打开的外壳干净以进行进一步的交互。 我怎样才能做到这一点?

30
urllib和“ SSL:CERTIFICATE_VERIFY_FAILED”错误
我收到以下错误: Exception in thread Thread-3: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner self.run() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run self.__target(*self.__args, **self.__kwargs) File "/Users/Matthew/Desktop/Skypebot 2.0/bot.py", line 271, in process info = urllib2.urlopen(req).read() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in …

10
如何将输入读取为数字?
这个问题的答案是社区的努力。编辑现有答案以改善此职位。它目前不接受新的答案或互动。 为什么在下面的代码中使用x和y字符串而不是整数? (注意:在Python 2.x中使用raw_input()。在Python 3.x中使用input()。在Python 3.x中raw_input()被重命名为input()) play = True while play: x = input("Enter a number: ") y = input("Enter a number: ") print(x + y) print(x - y) print(x * y) print(x / y) print(x % y) if input("Play again? ") == "no": play = False

11
在IPython Notebook中同时使用Python 2.x和Python 3.x
我使用IPython笔记本,并且希望能够选择在IPython中创建2.x或3.x python笔记本。 我最初有Anaconda。使用Anaconda时,必须更改全局环境变量以选择所需的python版本,然后才能启动IPython。这不是我想要的,所以我卸载了Anaconda,现在使用MacPorts和PiP设置了自己的安装。看来我还是要用 port select --set python <python version> 在python 2.x和3.x之间切换。这并不比anaconda解决方案好。 启动IPython笔记本后,是否有一种方法可以选择要使用的python版本,最好使用当前的MacPorts构建?



6
为什么我的Pandas的“应用”功能不能引用多个列?[关闭]
关闭。这个问题不能重现或由错别字引起。它当前不接受答案。 想改善这个问题吗?更新问题,使其成为Stack Overflow 的主题。 去年关闭。 改善这个问题 当将多个列与以下数据框一起使用时,Pandas Apply函数存在一些问题 df = DataFrame ({'a' : np.random.randn(6), 'b' : ['foo', 'bar'] * 3, 'c' : np.random.randn(6)}) 和以下功能 def my_test(a, b): return a % b 当我尝试使用以下功能时: df['Value'] = df.apply(lambda row: my_test(row[a], row[c]), axis=1) 我收到错误消息: NameError: ("global name 'a' is not defined", u'occurred at index …

8
在Python中,如何将“ datetime”对象转换为秒?
为这个简单的问题表示歉意...我是Python的新手...我四处搜寻,似乎没有任何反应。 我有一堆datetime对象,我想计算每个对象过去某个固定时间以来的秒数(例如,自1970年1月1日起)。 import datetime t = datetime.datetime(2009, 10, 21, 0, 0) 这似乎只能区分具有不同日期的日期: t.toordinal() 任何帮助深表感谢。
226 python  python-2.7 

12
bs4.FeatureNotFound:找不到具有您请求的功能的树构建器:lxml。您需要安装解析器库吗?
... soup = BeautifulSoup(html, "lxml") File "/Library/Python/2.7/site-packages/bs4/__init__.py", line 152, in __init__ % ",".join(features)) bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library? 以上输出在我的终端上。我在Mac OS 10.7.x上。我有Python 2.7.1,并按照本教程操作获得了Beautiful Soup和lxml,它们都已成功安装并与位于此处的单独测试文件一起使用。在导致此错误的Python脚本中,我包含以下行: from pageCrawler import comparePages 在pageCrawler文件中,我包含以下两行: from bs4 import BeautifulSoup from urllib2 import …

13
input()错误-NameError:名称“ ...”未定义
尝试运行此简单脚本时出现错误: input_variable = input ("Enter your name: ") print ("your name is" + input_variable) 假设我输入“花花公子”,我得到的错误是: line 1, in <module> input_variable = input ("Enter your name: ") File "<string>", line 1, in <module> NameError: name 'dude' is not defined 我正在使用python 2.7运行这些脚本。


3
使用Python编辑CSV文件时跳过标题
我正在使用以下引用的代码使用Python编辑CSV。代码中调用的函数构成了代码的上部。 问题:我希望下面引用的代码从第二行开始编辑csv,我希望它排除包含标题的第一行。现在,它仅在第一行上应用函数,并且我的标题行正在更改。 in_file = open("tmob_notcleaned.csv", "rb") reader = csv.reader(in_file) out_file = open("tmob_cleaned.csv", "wb") writer = csv.writer(out_file) row = 1 for row in reader: row[13] = handle_color(row[10])[1].replace(" - ","").strip() row[10] = handle_color(row[10])[0].replace("-","").replace("(","").replace(")","").strip() row[14] = handle_gb(row[10])[1].replace("-","").replace(" ","").replace("GB","").strip() row[10] = handle_gb(row[10])[0].strip() row[9] = handle_oem(row[10])[1].replace("Blackberry","RIM").replace("TMobile","T-Mobile").strip() row[15] = handle_addon(row[10])[1].strip() row[10] = handle_addon(row[10])[0].replace(" by","").replace("FREE","").strip() writer.writerow(row) in_file.close() …
209 python  python-2.7  csv 


18
在OSX 10.11(El Capitan)中安装Scrapy(系统完整性保护)时,出现“ OSError:[Errno 1] Operation not allow”
我正在尝试通过pip在OSX 10.11(El Capitan)中安装Scrapy Python框架。安装脚本下载所需的模块,并在某些时候返回以下错误: OSError: [Errno 1] Operation not permitted: '/tmp/pip-nIfswi-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info' 我尝试使用以下命令停用OSX 10.11中的无根功能: sudo nvram boot-args="rootless=0";sudo reboot 但是当机器重启时,我仍然收到相同的错误。 我的StackExchangers同事有什么线索或想法吗? 如果有帮助,则完整的脚本输出如下: sudo -s pip install scrapy Collecting scrapy Downloading Scrapy-1.0.2-py2-none-any.whl (290kB) 100% |████████████████████████████████| 290kB 345kB/s Requirement already satisfied (use --upgrade to upgrade): cssselect>=0.9 in /Library/Python/2.7/site-packages (from scrapy) Requirement already satisfied (use …

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.