有谁知道在运行之前在哪里或如何设置默认路径/目录以保存 python 脚本?
在 Mac 上,它想将它们保存在顶层~/Documents directory
。我想指定一个真实的位置。有任何想法吗?
有谁知道在运行之前在哪里或如何设置默认路径/目录以保存 python 脚本?
在 Mac 上,它想将它们保存在顶层~/Documents directory
。我想指定一个真实的位置。有任何想法吗?
在 OS X 上,如果您启动IDLE.app
(例如通过双击或使用open(1)
),默认目录将硬连线到~/Documents
. 如果您想永久更改默认设置,您需要编辑idlemain.py
IDLE.app 应用程序包中的文件;根据您安装的 Python,它可能位于以下之一:
/Applications/MacPython 2.x/IDLE.app/Contents/Resources
/Applications/MacPython 2.x/IDLE.app/Contents/Resources
/Applications/MacPorts/Python 2.x/IDLE.app/Contents/Resources
/Applications/Python 2.x/IDLE.app/Contents/Resources
/Applications/Python 3.x/IDLE.app/Contents/Resources
编辑该行:
os.chdir(os.path.expanduser('~/Documents'))
另一方面,如果您从命令行启动 IDLE,例如,使用:
$ cd /some/directory
$ /usr/local/bin/idle
IDLE 将使用该当前目录作为默认目录。
I actually just discovered the easiest answer, if you use the shortcut link labeled "IDLE (Python GUI)". This is in Windows Vista, so I don't know if it'll work in other OS's.
1) Right-click "Properties".
2) Select "Shortcut" tab.
3) In "Start In", write file path (e.g. "C:\Users...").
Let me know if this works!
如果您从该目录运行任何模块,您似乎可以进入您想要的目录。
我之前曾尝试通过路径浏览器打开 idlemain.py。我能够打开和编辑文件,但似乎我无法保存我的修改。
I'm just glad to hear other people are having this problem. I just thought I was being stupid.
如果您打开一个模块,则会设置默认工作目录。
启动空闲。
文件 -> 打开以打开您的文件。并设置当前工作目录。
在 Windows 上(至少是 Vista,这是我在这里看到的),桌面上的快捷方式图标有一个“开始于”字段,您可以在其中设置程序启动时用作当前工作目录的目录。改变这对我有用。Mac上有类似的东西吗?(也可以从命令行从所需目录开始。)
For OS X:
Open a new finder window,then head over to applications. Locate your Python application. (For my mac,it's Python 3.5)
Double click on it. Right click on the IDLE icon,show package contents. Then go into the contents folder,then resources.
Now,this is the important part:
(Note: You must be the administrator or have the administrator's password for the below to work)
Right click on the idlemain.py,Get Info.
Scroll all the way down. Make sure under the Sharing & Permissions tab,your "name"(Me) is on it with the privilege as Read & Write. If not click on the lock symbol and unlock it. Then add/edit yourself to have the Read & Write privilege.
Lastly,as per Ned Deily's instructions,edit the line:
os.chdir(os.path.expanduser('~/Documents'))
with your desired path and then save the changes.
Upon restarting the Python IDLE,you should find that your default Save as path to be the path you've indicated.
I am using windows 7 and by going to Start-> IDLE(Python 3.6 32-bit)
The click on properties and then in the shortcut tab go to Start in and entering the desired path worked for me kindly note if IDLE is open and running while you do this you'll have to shut it down and restart it for this to work
In Windows 10+, click the Windows Start button, then type idle, and then right-click on the IDLE desktop app and open the file location. This should bring you to the Start Menu shortcuts for Python, and you'll find a shortcut to IDLE there. Right-click on the IDLE shortcut and select properties. Set the "Start in" directory to be where you want default save path to be.
如果您在 Python 安装中找到 idlelib 目录,它将有一些带有 .def 扩展名的文件。config-main.def 有关于放置自定义配置文件的说明。但是,通过这些我没有找到任何可配置的路径(您的安装可能会有所不同)。看起来您可能需要打开编辑器代码才能更改它。
在我的例子中,默认目录设置为我启动 IDLE 的目录。例如,如果我从主目录中名为“tmp”的目录启动 IDLE,则默认保存路径设置为~/tmp
. 所以像这样开始你的空闲:
~/tmp $ idle
[...]
If you are using linux, you can create simple .sh file as presented below::
#!/bin/sh
cd /fullPath/PythonScripts/
idle
Run the file :)