在Cygwin 64位上,导入UUID Python库失败

7

我正在使用虚拟环境包来运行Python,并尝试导入UUID。以下是我收到的跟踪信息:

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

之后,Python就会没有任何警告而停止。我尝试从Cygwin重新安装库,但这并没有帮助。
有什么方法可以解决这个问题?
我应该指出,我正在使用Windows7 64位下的Python 2.7。
编辑: 下面的链接帮助我找到了可能的错误来源:Bug python 18784。但我看了一下指定修补程序中的代码,似乎Python甚至没有达到那个点。
解决方案: 由于我的声望太低,我无法“输入解决方案”,所以我在这里发布它作为编辑。 我通过以下补丁找到了解决方案: http://bugs.python.org/file20685/issue11063.patch

Python bug 18784中的补丁确实是正确的,已经停止了故障,并已被上游接受。我将尽快尝试将该补丁添加到Cygwin的pythonpython3软件包中。 - Yaakov
顺便说一下,如果您知道我们可以联系谁来讨论那个 cygwin 问题 的话……我会很感兴趣的。 - Tanzaho
@Yaakov - 这确实解决了导入失败的问题,但我不确定它是否修复了在Cygwin上的潜在DLL加载问题。当尝试执行uuid.uuid4()时,我会得到一个segfault。你们两个能否重现这个问题? - Aron Ahmadia
不要在修补uuid.py之后执行操作。 - Yaakov
@Yaakov - 抱歉,我误将修补程序来自于问题http://bugs.python.org/file20685/issue11063.patch。 这是错误的修补程序。 您链接到此问题:http://bugs.python.org/issue18784以及此修补程序:http://bugs.python.org/file31377/uuid.patch,它确实解决了我的问题。 - Aron Ahmadia
3个回答

6

1

0

正如Yaakov所指出的那样,你遇到的错误已被报告为CPython Issue 18784,并且已在Python 2.7、3.3的维护分支以及开发分支(3.4)中于2013年9月13日修复。

如果您需要对现有的Python系统进行热修复,可以使用以下来自Evgeny Sologubov的简单补丁,该补丁会在uuid例程被定位后从尝试加载进一步库的uuid模块中断。

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

ctypes 仍然存在更深层次的问题需要解决,但这应该解决了许多人在 Cygwin64 上安装 Python 包时遇到的主要问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接