python-2.6

No module named _cffi_backend

戏子无情 提交于 2019-12-21 03:35:24
问题 I have python2.6 in my Linux rhel-5. I have installed pip and required CFFI packages. When i try to run a sample CFFI program it says : ffi = FFI() File "/usr/lib/python2.6/site-packages/cffi/api.py", line 56, in init import _cffi_backend as backend ImportError: No module named _cffi_backend what could be the posiible error. Did i miss something during install. i have installed pip, wheel, pycparser, pytest, cffi.... 回答1: For python2.x use following command: python -m pip install cffi for

How to check whether a jpeg image is color or gray scale using only Python stdlib

空扰寡人 提交于 2019-12-21 03:17:08
问题 I have to write a test case in python to check whether a jpg image is in color or grayscale. Can anyone please let me know if there is any way to do it with out installing extra libraries like opencv? 回答1: Expanding @gat answer: import Image def is_grey_scale(img_path): img = Image.open(img_path).convert('RGB') w,h = img.size for i in range(w): for j in range(h): r,g,b = img.getpixel((i,j)) if r != g != b: return False return True Basically, check every pixel to see if it is grayscale (R == G

Unable to install 32-bit Python with pyenv, despite appropriate flags set

僤鯓⒐⒋嵵緔 提交于 2019-12-20 07:35:13
问题 I'm looking to install the 2.6.6 Python as 32-bit with pyenv on OS X, but get: ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib? Despite having consulted Common Build Problems, and applying the flags suggested there, as well as installing Xcode developer tools, the problem persists. Here is the full command: CFLAGS="-I$(xcrun --show-sdk-path)/usr/include -arch i386 -I$(brew --prefix openssl)/include" LDFLAGS="-arch i386 -L$(brew --prefix openssl)/lib" CONFIGURE_OPTS="

Changing labels in matplotlib polar plot

这一生的挚爱 提交于 2019-12-19 19:43:58
问题 I am using matplotlib to create polar plots to represent Rose Diagrams. Right now the plot is getting created perfectly. I want to replace the angles being displayed on the axis with direction names: N for 0 degrees, W for 90 degrees, S for 180 degrees and E for 270 degrees. The current rose diagram looks like the following: Note: I have tried with windrose but this output is more appropriate for my purpose. Hence a good way of assigning custom labels to the axes will be very helpful. The

Parse custom URIs with urlparse (Python)

淺唱寂寞╮ 提交于 2019-12-18 11:51:33
问题 My application creates custom URIs (or URLs?) to identify objects and resolve them. The problem is that Python's urlparse module refuses to parse unknown URL schemes like it parses http. If I do not adjust urlparse's uses_* lists I get this: >>> urlparse.urlparse("qqqq://base/id#hint") ('qqqq', '', '//base/id#hint', '', '', '') >>> urlparse.urlparse("http://base/id#hint") ('http', 'base', '/id', '', '', 'hint') Here is what I do, and I wonder if there is a better way to do it: import urlparse

Most “pythonic” way of organising class attributes, constructor arguments and subclass constructor defaults?

泄露秘密 提交于 2019-12-18 11:23:51
问题 Being relatively new to Python 2, I'm uncertain how best to organise my class files in the most 'pythonic' way. I wouldn't be asking this but for the fact that Python seems to have quite a few ways of doing things that are very different to what I have come to expect from the languages I am used to. Initially, I was just treating classes how I'd usually treat them in C# or PHP, which of course made me trip up all over the place when I eventually discovered the mutable values gotcha: class

Python 2.6 on Windows: how to terminate subprocess.Popen with “shell=True” argument?

徘徊边缘 提交于 2019-12-18 06:08:31
问题 Is there a way to terminate a process started with the subprocess.Popen class with the "shell" argument set to "True"? In the working minimal example below (uses wxPython) you can open and terminate a Notepad process happily, however if you change the Popen "shell" argument to "True" then the Notepad process doesn't terminate. import wx import threading import subprocess class MainWindow(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title) self.main

Python 2.6 on Windows: how to terminate subprocess.Popen with “shell=True” argument?

為{幸葍}努か 提交于 2019-12-18 06:07:23
问题 Is there a way to terminate a process started with the subprocess.Popen class with the "shell" argument set to "True"? In the working minimal example below (uses wxPython) you can open and terminate a Notepad process happily, however if you change the Popen "shell" argument to "True" then the Notepad process doesn't terminate. import wx import threading import subprocess class MainWindow(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title) self.main

Python 2.6 TreeMap/SortedDictionary?

只愿长相守 提交于 2019-12-18 04:32:57
问题 Is there a built-in sorted dictionary implementation in Python 2.6, or are hashtables the only kind? Clarifications: I'm asking about sorted dictionarys, not ordered dictionaries! 回答1: I think the answer here is no. There is a Treemap but it isn't in the python standard library. http://pypi.python.org/pypi/treemap/ I think to those who don't like my answer, may think it's wrong due to a recent update. Please note this is for Python 2.6, not 2.7 or Python 3 Please add the correct answer if you

Setup.py: install lxml with Python2.6 on CentOS

妖精的绣舞 提交于 2019-12-17 22:56:46
问题 I have installed Python 2.6.6 on CentOS 5.4, [@SC-055 lxml-2.3beta1]$ python Python 2.6.6 (r266:84292, Jan 4 2011, 09:49:55) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> I want to use the lxml module, but build from sources failed: src/lxml/lxml.etree.c:157929: error: ‘xsltLibxsltVersion’ undeclared (first use in this function) src/lxml/lxml.etree.c:157941: error: ‘__pyx_v_4lxml_5etree_XSLT_DOC_DEFAULT_LOADER’