Cygwin和Windows路径冲突;同时使用 Windows 和 cygwin Python
我在 Windows XP 上安装了 cygwin。我在 Windows 上安装了一些软件后,cygwin 上的 Mercurial 停止工作。症状可以简化为 python 无法在其库中找到模块:
>>> import os
Traceback (most recent call last):
file "<stdin>", line 1, in <module>
ImportError: No module named os
我在 Windows 中安装的软件之一(subversion)使用 python,所以现在 Windows 有自己的 Python 安装。不要问为什么我想在cygwin下使用mercurial,在Windows下使用subversion;我只想说我愿意,但这不是重点。似乎 cygwin 试图使用 Windows python 而不是它自己的,或者至少我认为正在发生这种情况。如果这不是原因,请赐教。无论如何...
$ find /cygdrive/c -name os.py /cygdrive/c/csvn/Python25/Lib/os.py /cygdrive/c/cygwin/lib/python2.6/os.py
echo $PATH 确认 /cygdrive/c/csvn/Python25 在 /usr/lib/python2.6 之前。我不是 cygwin 专家,但据我所知, /etc/profile 将 Windows 路径添加到 cygwin 的 $PATH 中,并且我不知道如何阻止它这样做。作为解决方法,我修改了 .profile 以显式设置 PATH,从 Windows 中排除这些路径。但是,问题仍然存在:
$ echo $PATH
/usr/local/bin:/usr/bin:/usr/lib/python2.6
$ hg
'import site' failed; use -v for traceback
Traceback (most recent call last):
File "/usr/bin/hg", line 10, in <module>
import os
ImportError: No module named os
$ ls /usr/lib/python2.6/os.py
/usr/lib/python2.6/os.py
看起来路径冲突实际上尚未解决,因为当我再次发出上述“find”命令时,我得到了相同的结果, /cygdrive/c/csvn/Python25/Lib/os.py首先出现。理论上,可能还有其他原因导致 python 无法在 cygwin 上运行,但无法控制我的 PATH 仍然是一个问题。有什么想法吗?
I've installed cygwin on Windows XP. Mercurial on cygwin stopped working after I installed some software on Windows. The symptom can be simplified to python not being able to locate modules in its library:
>>> import os
Traceback (most recent call last):
file "<stdin>", line 1, in <module>
ImportError: No module named os
One of the pieces of software I installed in Windows (subversion) uses python so now Windows has its own Python installation. Don't ask why I wish to use mercurial under cygwin and subversion under Windows; suffice to say I do, but that's beside the point. It seems cygwin tries to use the Windows python instead of its own, or at least that's what I think is happening. If that's not the cause, please enlighten me. Anyway...
$ find /cygdrive/c -name os.py
/cygdrive/c/csvn/Python25/Lib/os.py
/cygdrive/c/cygwin/lib/python2.6/os.py
echo $PATH confirms that /cygdrive/c/csvn/Python25 is before /usr/lib/python2.6. I'm no cygwin wiz, but from what I can tell /etc/profile adds the Windows path to cygwin's $PATH, and I don't know how to keep it from doing so. As a workaround I modified .profile to explicitly set PATH, excluding those paths from Windows. But, the problem remains:
$ echo $PATH
/usr/local/bin:/usr/bin:/usr/lib/python2.6
$ hg
'import site' failed; use -v for traceback
Traceback (most recent call last):
File "/usr/bin/hg", line 10, in <module>
import os
ImportError: No module named os
$ ls /usr/lib/python2.6/os.py
/usr/lib/python2.6/os.py
It looks like the path conflict has not actually been resolved, because when I issue the above "find" command again I get the same results, with /cygdrive/c/csvn/Python25/Lib/os.py showing up first. In theory there may be some other reason python isn't working on cygwin, but not being able to control my PATH would still be a problem. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,我的同事也遇到了这个问题,已经卸载了 csvn 东西,所以我无法检查。但是阅读 doc 表明应受谴责的变量可能是 <代码>$PYTHONHOME。检查是否已设置并尝试取消设置!
Unfortunately my colleague who also had the problem already uninstalled the csvn thing, so I can't check. But reading the doc suggests the culpable variable might be
$PYTHONHOME
. Check whether it's set and try unsetting it!您是否尝试过 此中找到的解决方案其他SO帖子?似乎有类似的问题。
Have you tried the solutions found in this other SO post? Seems like a similar problem.