“没有名为 _scproxy 的模块”在 OSX 上
我使用的是预装 python 2.6 的 OSX 10.6,并且想通过 easy_install 或 setup.py (在下载的包中)安装 python 包。就我而言,我正在尝试安装 MySQLdb。在这两种情况下,我都会得到一个堆栈跟踪,其结尾如下:
...
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/setuptools/command/easy_install.py", line 21, in <module>
from setuptools.package_index import PackageIndex, parse_bdist_wininst
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/setuptools/package_index.py", line 2, in <module>
import sys, os.path, re, urlparse, urllib2, shutil, random, socket, cStringIO
File "/System/Library/Frameworks/Python/framework/Versions/2.6/lib/python2.6/urllib2.py", line 111, in <module>
from urllib import (unwrap, unquote, splittype, splithost, quote,
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib.py", line 1335, in <module>
from _scproxy import _get_proxy_settings, _get_proxies
ImportError: No module named _scproxy
python 安装是未经修改的预安装版本 2.6.1,只不过我将源文件添加到了 lib 文件夹中。 “find /System/Library/Frameworks/Python.framework/ -name scproxy”不会产生任何结果。
如何安装缺少的模块?
I'm on OSX 10.6 with pre-installed python 2.6 and would like to install python packages via easy_install or setup.py (in a downloaded package). In my case I'm trying to install MySQLdb. In both cases I get a stack trace which ends like so:
...
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/setuptools/command/easy_install.py", line 21, in <module>
from setuptools.package_index import PackageIndex, parse_bdist_wininst
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/setuptools/package_index.py", line 2, in <module>
import sys, os.path, re, urlparse, urllib2, shutil, random, socket, cStringIO
File "/System/Library/Frameworks/Python/framework/Versions/2.6/lib/python2.6/urllib2.py", line 111, in <module>
from urllib import (unwrap, unquote, splittype, splithost, quote,
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib.py", line 1335, in <module>
from _scproxy import _get_proxy_settings, _get_proxies
ImportError: No module named _scproxy
The python installation is the unmodified pre-installed version 2.6.1 except that I added the source files to the lib folder. A "find /System/Library/Frameworks/Python.framework/ -name scproxy" does not yield any results.
How can I install the missing module?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
背景
_scproxy
是 Mac 特定的 urllib 帮助程序,与特定于操作系统的库交互以执行 HTTP 请求。我的系统上似乎也缺少它(10.6.7)。初步而言,我认为这看起来像是系统 Python 构建的问题(我在/System/Libraries
下找不到任何类似的内容)。Hack-o-rama 解决方案
可以(某种程度上)安装缺少的模块。但首先有一点建议:
你不应该TM对你的系统 Python 安装搞得太多。学习使用 virtualenv 帮自己一个忙,并对新的 virtualenv 应用潜在危险的操作。这样您的系统就不会受到安装有问题的软件包的影响。
无论如何:Snow Leopard 上的原生 Python 是 2.6.1。我用最新的 2.6、2.6.6 进行了实验,一种更安全的方法是下载它。然而,我的经验是,不同的点发布可以很好地协同工作。
无论如何,我在我的
~/src
目录中下载了 2.6.6,如下所示:控制台垃圾邮件疯狂
希望没有错误,更多控制台垃圾邮件
找到新建
_scproxy.so
:您现在可以将
_scproxy.so
复制到/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2 .6/lib-dynlo
(然后记住,你的 Python 系统中有一个自制的有点陌生的模块)。或者,更好的方法是将其添加到 virtualenv 的 lib/python2.6/ 子目录中。完成这些操作后,我可以按照回溯中指示的方式导入 _scproxy:ad
这是一个强烈的迹象,表明通过需要
urllib
请求使用_scproxy
的方法安装软件包将起作用。不过,从那时起,您就必须自己继续,因为我不想测试安装 MySQL 本身。Background
_scproxy
is a Mac-specific urllib helper interfacing with OS-specific libraries to do HTTP requests. It seems to be missing on my system too (10.6.7). Preliminary, I think it looks like a problem with the system Python build (I can't find anything that looks like it under/System/Libraries
).Hack-o-rama solution
It's (sort of) possible to install the missing module. But first a bit of advice:
You Shouldn'tTM mess too much with your system Python installation. Do yourself a favour by learning to use virtualenv, and apply potentially dangerous operations on new, fresh virtualenv's. That way you're system wont be affected by installation of problematic packages.
Anyway: stock Python on Snow Leopard is 2.6.1. I did my experiments with the most recent 2.6, 2.6.6, a marginably safer way would be to download that instead. My experience is however that varying dot releases work just fine together.
Anyway, I downloaded 2.6.6 in my
~/src
directory like this:console spams like crazy
hopefully no errors, more console spamming
Locate the newly built
_scproxy.so
:You can now copy your
_scproxy.so
to/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynlo
(and then remember that there's a home-built somewhat alien module in you system Python). Or, much better, add it to thead
lib/python2.6/
subdirectory of a virtualenv. After doing these things, I could import _scproxy in the manner indicated in your traceback:This is a strong indication that installing packages via a method requiring
urllib
requests utlizing_scproxy
will work. From there on you have continue on your own, though, since I don't want to test-install MySQL itself.