设置Pydev交互式控制台的默认目录? [英] Set default directory of Pydev interactive console?
问题描述
使用 Control + Alt + Enter
的交互式控制台(又名PyDev控制台)加载 C:\Program文件(x86)\eclipse
作为默认目录。我如何将其加载到脚本或项目所在的默认工作目录?
The interactive console (aka PyDev console) which I use to run scripts with Control + Alt + Enter
loads with C:\Program Files (x86)\eclipse
as the default directory. How can I make it load to the default working directory that the script or project is located in?
我一直在研究这一切,似乎没有任何效果。看来,其他人也遇到了同样的问题,没有答案:
I've been researching this all over now and nothing seems to work. It looks like others have been having the same issues with no answers too:
https://superuser.com/questions/486759/how-can-i-select-a-default- interactive-console-in-pydev
我还尝试实现自定义启动脚本在这里找到无效。我还将我的工作目录添加到PYTHONPATH,作为在此建议。
I also tried implementing a custom startup script found here to no avail. I've also added my working directory to the PYTHONPATH as suggested here.
推荐答案
上述链接中由 https://stackoverflow.com/users/5717589/ptrj 是正确的,我相信也适用于此。它类似于 https://stackoverflow.com/users/5618245/daniel 发布,但我想提供更详细的信息。我会再次粘贴在这里方便。 ptrj应该得到信用。另外,上述链接的ptrj答案应该已被upvoted的IMO。
The answer given in the above link by https://stackoverflow.com/users/5717589/ptrj is correct and I believe also applies here. It is similar to what https://stackoverflow.com/users/5618245/daniel posted but I think gives more detailed information. I will paste again here for convenience. ptrj should get credit. Also, ptrj answer for the above link should have been upvoted IMO.
从ptrj:
我有同样的问题,并有刚找到另一个解决方案它类似于已经提到但在eclipse / pydev中完全可配置的(不需要修改脚本)。
from ptrj: I had the same problem and have just found another solution. It's similar to the ones already mentioned but fully configurable within eclipse/pydev (no need to modify your scripts).
在窗口 - >首选项 - > PyDev - >口译 - > Python解释器选择选项卡环境并添加名为PROJECT_PATH(或任何您选择的)和Value $ {project_loc}(这是项目文件夹的绝对路径)的新变量。
然后在Window - > Preferences - > PyDev - > Interactive Console - > Initial Command add line import os; os.chdir(os.environ [ PROJECT_PATH])。
(如果您启动当前工作编辑器的控制台,则可以使用。)
In Window -> Preferences -> PyDev -> Interpreters -> Python Interpreter choose tab Environment and add a new variable with Name PROJECT_PATH (or anything of your choice) and Value ${project_loc} (this is an absolute path to the project folder). Then in Window -> Preferences -> PyDev -> Interactive Console -> Initial Command add line import os; os.chdir(os.environ['PROJECT_PATH']). (It works if you start a "Console for currently working editor".)
我使用这种方法,对我来说是有用的。
I use this method and it works for me.
这篇关于设置Pydev交互式控制台的默认目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!