7

I am running python within a virtual environment wrapper and I try to import UUID. Here is the trace of what I receive :

python -v
>>> import uuid


# /home/tanzaho/.virtualenvs/django_wordiz/lib/python2.7/site-packages/uuid.pyc matches /home/tanzaho/.virtualenvs/django_wordiz/lib/python2.7/site-packages/uuid.py
import uuid # precompiled from /home/tanzaho/.virtualenvs/django_wordiz/lib/python2.7/site-packages/uuid.pyc
import ctypes # directory /usr/lib/python2.7/ctypes
# /usr/lib/python2.7/ctypes/__init__.pyc matches /usr/lib/python2.7/ctypes/__init__.py
import ctypes # precompiled from /usr/lib/python2.7/ctypes/__init__.pyc
dlopen("/home/tanzaho/.virtualenvs/django_wordiz/lib/python2.7/lib-dynload/_ctypes.dll", 2);
import _ctypes # dynamically loaded from /home/tanzaho/.virtualenvs/django_wordiz/lib/python2.7/lib-dynload/_ctypes.dll
# /usr/lib/python2.7/struct.pyc matches /usr/lib/python2.7/struct.py
import struct # precompiled from /usr/lib/python2.7/struct.pyc
dlopen("/home/tanzaho/.virtualenvs/django_wordiz/lib/python2.7/lib-dynload/_struct.dll", 2);
import _struct # dynamically loaded from /home/tanzaho/.virtualenvs/django_wordiz/lib/python2.7/lib-dynload/_struct.dll
# /usr/lib/python2.7/ctypes/_endian.pyc matches /usr/lib/python2.7/ctypes/_endian.py
import ctypes._endian # precompiled from /usr/lib/python2.7/ctypes/_endian.pyc
# /usr/lib/python2.7/ctypes/util.pyc matches /usr/lib/python2.7/ctypes/util.py
import ctypes.util # precompiled from /usr/lib/python2.7/ctypes/util.pyc

After that, python just stops without any other warning. I tried to reinstall the library from Cygwin, but that did not help.

Is there a way I can fix this?

I should specify that I am using python 2.7 under Windows7 64bits.

Edit The following link helped me to find a possible eerror soure : Bug python 18784 . But I looked at the code specified in the patch and it seems that python does not even reach that point.

Solution As I cannot 'enter the solution' because my reputation is too low, I post it as an edit here. I found the solution via the following patch : http://bugs.python.org/file20685/issue11063.patch

Tanzaho
  • 1,362
  • 12
  • 20
  • The patch in [Python bug 18784](http://bugs.python.org/issue18784) is indeed correct, stop the failure, and have now been accepted upstream. I will attempt to add that patch to Cygwin's `python` and `python3` packages ASAP. – Yaakov Sep 23 '13 at 04:13
  • By the way, if you know who we can contact to talk about that [cygwin problem](https://github.com/kennethreitz/requests/issues/1547) too .... I would be interested. – Tanzaho Sep 24 '13 at 08:55
  • @Yaakov - This indeed fixes the import failure, but I'm not sure it fixes the underlying DLL load problem on Cygwin. I get a segfault when trying to execute uuid.uuid4(). Can either of you reproduce? – Aron Ahmadia Sep 30 '13 at 17:35
  • Not after patching `uuid.py`. – Yaakov Oct 02 '13 at 03:03
  • @Yaakov - Apologies, I was applying the patch from the question, http://bugs.python.org/file20685/issue11063.patch. This is the incorrect patch. You linked to this issue: http://bugs.python.org/issue18784 and this patch: http://bugs.python.org/file31377/uuid.patch, which indeed fixes my problems. – Aron Ahmadia Oct 02 '13 at 14:34

3 Answers3

6

I had the same symptoms on 64-bit Cygwin. Installing the "libuuid-devel" and "binutils" Cygwin packages resolved the import crash for me.

There's more discussion about solutions at: https://github.com/kennethreitz/requests/issues/1547.

Jeff S
  • 63
  • 1
  • 4
1

install libuuid-devel

the solution is here https://github.com/kennethreitz/requests/issues/1547#issuecomment-29301616

apt-cyg install libuuid-devel

after this the installation works

easy_install requests

printf "help('modules')" | python | grep requests
array               hotshot             requests            xmlrpclib
John Peterson
  • 83
  • 1
  • 5
0

As Yaakov notes, the bug you are experiencing has been reported as CPython Issue 18784, and has been fixed as of 13 Sep 2013 in maintenance branches for Python 2.7, 3.3, and the development branch (3.4).

If you need to hotfix an existing Python system, you can do with the following simple patch from Evgeny Sologubov which short-circuits the uuid module from attempting to load further libraries after the uuid routines have been located:

diff -r 4a318a45c4c3 Lib/uuid.py
--- a/Lib/uuid.py   Mon Aug 19 13:07:18 2013 -0400
+++ b/Lib/uuid.py   Mon Aug 19 21:41:08 2013 +0400
@@ -429,6 +429,8 @@
             _uuid_generate_random = lib.uuid_generate_random
         if hasattr(lib, 'uuid_generate_time'):
             _uuid_generate_time = lib.uuid_generate_time
+            if _uuid_generate_random is not None:
+                break  # found everything we were looking for

     # The uuid_generate_* functions are broken on MacOS X 10.5, as noted
     # in issue #8621 the function generates the same sequence of values

There are still deeper issues with ctypes that need to be addressed, but this should fix a lot of major problems people are seeing with installing Python packages on Cygwin64.

Aron Ahmadia
  • 2,267
  • 2
  • 19
  • 22