7

I'm using djangoflup+fastgic+ngix. It works good.

Now I planned to upgrade from python 2.6.6 to 2.7.2 and met a problem to import flup in python 2.7.

Python 2.7.2 (Red Hat 4.1.2-50)
>>> import sys
>>> sys.path
['', '......', 
'/usr/local/lib/python2.7.2/lib/python2.7/site-packages/flup-1.0.2-py2.7.egg', '......']
>>> import flup
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named flup

It works perfectly on the SAME host under python 2.6.

Python 2.6.6 (Red Hat 4.1.2-50)
>>> import sys
>>> sys.path
['', '......', '/usr/local/lib/python2.6/site-packages/flup-1.0.1-py2.6.egg', '......']
>>> import flup
>>>

Any idea about the reason?

zhangchao
  • 71
  • 1
  • 2

4 Answers4

11

Newer versions of flup dropped support for python2.7 (accidentally?)

You can install an older one that works with:

pip install flup==1.0.3.dev-20110405
dequis
  • 2,100
  • 19
  • 25
3

The problem is with a change in importing threading capability. The latest (as of this writing) version of flup is 1.0.3 and can be fixed with the following patch:

diff -puNr flup-1.0.3/lib/python2.7/site-packages/flup/server/fcgi_base.py flup-1.0.3.fixed/lib/python2.7/site-packages/flup/server/fcgi_base.py
--- flup-1.0.3/lib/python2.7/site-packages/flup/server/fcgi_base.py 2019-02-03 23:13:24.305329000 +0000
+++ flup-1.0.3.fixed/lib/python2.7/site-packages/flup/server/fcgi_base.py   2019-02-03 23:12:12.319327934 +0000
@@ -38,11 +38,14 @@ import errno
 import traceback

 try:
-    import _thread
+    try:
+        import _thread
+    except ImportError:
+        import thread as _thread
     import threading
     thread_available = True
 except ImportError:
-    import _dummy_thread as thread
+    import _dummy_thread as _thread
     import dummy_threading as threading
     thread_available = False

Above, I preserved the original behaviour (importing _thread first), then it will fallback to import thread as _thread. I also fixed the fallback option since whoever introduced the change forgot to fix the fallback.

Given that RHEL/CentOS 7 are still running Python 2.7 this fix would be needed for some time. Unfortunately, I failed to locate the current home for flup to be able to push this fix upstream.

galaxy
  • 424
  • 2
  • 7
0

Does /usr/local/lib/python2.7.2/lib/python2.7/site-packages/flup-1.0.2-py2.7.egg really exist on your drive? in fact, if the path points to nothing, then the flup module cannot be found; in this case, you should (re)install it.

Eric O. Lebigot
  • 91,433
  • 48
  • 218
  • 260
0

I've resolved this problem by link the python-config file into $PATH:

ln -s /usr/local/lib/python2.7.2/bin/python-config /usr/local/bin/python-config
Curtis
  • 101,612
  • 66
  • 270
  • 352
zhangchao
  • 71
  • 1
  • 2