如果您“在资源管理器中显示”,Komodo Edit 会更改 Python sys.path

发布于 2024-07-26 12:29:25 字数 1033 浏览 4 评论 0原文

我正在使用代码编辑器 Komodo Edit

当我右键单击项目并单击“在资源管理器中显示”时,它会在我的项目所在目录中弹出一个类似于Windows资源管理器的框。 这非常方便。

然而,我注意到了一个潜在的副作用。 当你尝试使用这个看起来与 Windows 资源管理器一模一样的窗口运行 python 文件时,你会发现它完全搞乱了 Python 中的 sys.path 以使用自己的目录。

有什么办法可以避免这种情况吗?

import sys
sys.path

C:\Windows\system32\python26.zip
C:\Program Files\ActiveState Komodo Edit 5\lib\python\DLLs
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib\plat-win
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib\lib-tk
C:\Python26
C:\Program Files\ActiveState Komodo Edit 5\lib\python
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib\site-packages
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib\site-packages\win32
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib\site-packages\win32\lib
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib\site-packages\Pythonwin

I am using Komodo Edit, a code editor.

When I right click on projects and click "Show in Explorer", it will pop up a box just like Windows Explorer at the directory my project is. This is very convenient.

However, I noticed an insidious side effect. When you try to run a python file with this window that looks exactly like Windows Explorer, you will find out that it completely messes up sys.path in Python to use its own directory.

Is there any way to avoid this?

import sys
sys.path

C:\Windows\system32\python26.zip
C:\Program Files\ActiveState Komodo Edit 5\lib\python\DLLs
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib\plat-win
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib\lib-tk
C:\Python26
C:\Program Files\ActiveState Komodo Edit 5\lib\python
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib\site-packages
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib\site-packages\win32
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib\site-packages\win32\lib
C:\Program Files\ActiveState Komodo Edit 5\lib\python\lib\site-packages\Pythonwin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

漫雪独思 2024-08-02 12:29:25

这确实是Komodo的一个问题。 它实际上源于 Komodo 生成的资源管理器窗口,其中将 PYTHONHOME 环境变量设置为包含 Komodo 的路径,因为子进程继承了父进程的环境。 我通过 Komodo 生成的资源管理器打开命令提示符窗口注意到了这一点。 如果您查看 set 的输出,它包含(除其他外)以下内容:

PYTHONHOME=C:\Program Files\ActiveState Komodo Edit 5\lib\python
_KOMODO_HOSTUSERDATADIR=C:\Users\Dev\AppData\Roaming\ActiveState\KomodoEdit\5.1\host-host\
_KOMODO_VERUSERDATADIR=C:\Users\Dev\AppData\Roaming\ActiveState\KomodoEdit\5.1\
_XRE_USERAPPDATADIR=C:\Users\Dev\AppData\Roaming\ActiveState\KomodoEdit\5.1\host-host\XRE

我报告了此错误 此处位于 ActiveState 错误跟踪器

This is indeed a problem in Komodo. It actually stems from the Explorer window spawned by Komodo having the PYTHONHOME environment variable set to include Komodo's path, since the child process inherits the parent's environment. I noticed this by opening a Command Prompt window through an Explorer spawned by Komodo. If you look at the output from set, it contains (among other things) the following:

PYTHONHOME=C:\Program Files\ActiveState Komodo Edit 5\lib\python
_KOMODO_HOSTUSERDATADIR=C:\Users\Dev\AppData\Roaming\ActiveState\KomodoEdit\5.1\host-host\
_KOMODO_VERUSERDATADIR=C:\Users\Dev\AppData\Roaming\ActiveState\KomodoEdit\5.1\
_XRE_USERAPPDATADIR=C:\Users\Dev\AppData\Roaming\ActiveState\KomodoEdit\5.1\host-host\XRE

I reported this bug here at the ActiveState bug tracker.

坚持沉默 2024-08-02 12:29:25

哎呀! 我在 Vista 机器上也有同样的行为。 我没有看到该功能的任何设置,我认为这是一个科莫多错误。

我想了一个解决方法:在工具箱中创建一个新命令,并使用“explorer %D”作为命令行。 但它有同样的问题:-(

更新:如果您将 %D 用作 StartIn,则解决方法有效。请参阅捕获:

替代文本http://img10.imageshack.us/img10/2972/komodoshowinexplorer.jpg

Oups! I've the same behavior on my Vista machine. I didn't see any settings for that feature and I think that this is a Komodo bug.

I though about a workaround: create a new command in the toolbox with "explorer %D" as command line. But it has the same problem :-(

Update: The workaround works if you put %D for StartIn. See the capture:

alt text http://img10.imageshack.us/img10/2972/komodoshowinexplorer.jpg

凉宸 2024-08-02 12:29:25

您的 sys.path 应该是什么? 看起来 Python 已经在路上了,但也许你还需要其他库。

如果您缺少一些关键目录,请在您的 Python 模块之一中使用 sys.path.append 。 如果您需要移动 Python 解释器的目录(这可能是使相对路径名正常工作所必需的),也请使用 os.chdir。

编辑:令我震惊的是,您可能已经了解这些功能,而问题出在其他地方。

What should your sys.path be instead? It looks like Python is already on the path, but maybe you need other libraries there, too.

If you're missing some key directories, use sys.path.append in one of your Python modules. If you need to move the directory of the Python interpreter (which may be necessary in order to get relative pathnames to work), use os.chdir as well.

Edit: It strikes me that you probably already know about those functions and that the problem lies elsewhere.

我爱人 2024-08-02 12:29:25

我建议进入 Komodo Edit 的首选项 >> 环境,并将 PYTHONHOME 更改回原来的 python 安装(例如 c:\python27)

I'd recommend going into Komodo Edit's Preferences >> Environment, and changing PYTHONHOME back to the original python install (e.g. c:\python27)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文