简体   繁体   English

如何使用 Spyder 启动所有 .py 文件?

[英]How do I make all .py files launch with Spyder?

I installed Spyder using Anaconda, and I am able to launch the IDE using the Spyder icon in my start menu (Win10).我使用 Anaconda 安装了 Spyder,并且能够使用开始菜单 (Win10) 中的 Spyder 图标启动 IDE。 I wanted to set my preferences to open all .py files with Spyder, so I followed the Spyder start menu button to an executable, pythonw.exe .我想设置我的首选项以使用 Spyder 打开所有.py文件,所以我按照 Spyder 开始菜单按钮找到一个可执行文件pythonw.exe The problem is that I cannot launch pythonw.exe by clicking it.问题是我无法通过单击启动pythonw.exe

How does the start menu icon for Spyder, which points to pythonw.exe , launch Spyder, but clicking the executable does not yield the same results?指向pythonw.exe Spyder 的开始菜单图标如何启动 Spyder,但单击可执行文件不会产生相同的结果? Also, when I double click spyder.exe in Anaconda\\Scripts a command prompt opens along with the IDE, which does not happen when I click the start menu icon.此外,当我在Anaconda\\Scripts双击spyder.exe ,命令提示符会与 IDE 一起打开,而当我单击开始菜单图标时不会发生这种情况。

Why does this application behave so much differently than any other application I've used before (if this is just how things are in python, I apologize as I'm new!) and is it possible to set Spyder as the default application to open .py files in the same way I can open source files with IDEs in other languages?为什么这个应用程序的行为与我之前使用的任何其他应用程序的行为如此不同(如果这就是 Python 中的情况,我很抱歉,因为我是新手!)并且是否可以将 Spyder 设置为要打开的默认应用程序.py文件的方式与我可以使用其他语言的 IDE 打开源文件的方式相同吗?

Cheers干杯

I found the answer in this question, answer by xyzjayne .我在这个问题中找到了答案,由xyzjayne回答。

You create a bat file with the following contents:您创建一个包含以下内容的bat文件:

start YOURPATH\\Anaconda2\\pythonw.exe YOURPATH\\Anaconda2\\cwp.py YOURPATH\\Anaconda2 "YOURPATH/Anaconda2/pythonw.exe" "YOURPATH/Anaconda2/Scripts/spyder-script.py" %1启动 YOURPATH\\Anaconda2\\pythonw.exe YOURPATH\\Anaconda2\\cwp.py YOURPATH\\Anaconda2 "YOURPATH/Anaconda2/pythonw.exe" "YOURPATH/Anaconda2/Scripts/spyder-script.py" %1

YOURPATH will be the path leading to the folder just above the Anaconda folder. YOURPATH 将是通向 Anaconda 文件夹正上方的文件夹的路径。 For me it was:对我来说是:

C:\\ProgramData C:\\程序数据

And you select the Choose default program to open this file... - and you choose that bat file.并且您选择选择默认程序以打开此文件... - 然后您选择该 bat 文件。

When you go to Spyder shortcut's properties, the target includes a few files.当您转到 Spyder 快捷方式的属性时,目标包含一些文件。 So my guess is that for Spyder to run, all of these files must be run, and that's why when you just point .py files to one exe it doesn't work.所以我的猜测是,要运行 Spyder,必须运行所有这些文件,这就是为什么当您将 .py 文件指向一个 exe 时它不起作用的原因。

您可以右键单击任何*.py文件,转到属性并选择 Spyder 作为“打开方式”选项。

Right click on your file, and select open with or Choose default program to open this file.. and then in your system... select .. \\Anaconda3\\Scripts\\spyder.exe .右键单击您的文件,然后选择打开方式或选择默认程序以打开此文件.. 然后在您的系统中...选择 .. \\Anaconda3\\Scripts\\spyder.exe 。

I have also provided you the screenshot of the above path in my system for your reference.我还提供了我系统中上述路径的截图供您参考。

在此处输入图片说明

In Windows 10 Anaconda installs itself into a hidden folder called ".anaconda" which is placed in the Users directory under your own profile sub directory.在 Windows 10 中,Anaconda 将自身安装到一个名为“.anaconda”的隐藏文件夹中,该文件夹位于您自己的配置文件子目录下的用户目录中。

When you first try to use the right-click menue "Open with" it opens up in C:\\Program Files so you have to go up one folder and down into Users.当您第一次尝试使用右键单击菜单“打开方式”时,它会在 C:\\Program Files 中打开,因此您必须向上移动一个文件夹并向下进入“用户”。 You may need to have previously set one of the options in the View Menu of the file manager so that you can see hidden files.您可能需要事先在文件管理器的“查看”菜单中设置其中一个选项,以便您可以查看隐藏文件。 You can't do this from the "right-click open with" place, you have to set that in the regular file manager.您不能从“右键单击打开方式”位置执行此操作,您必须在常规文件管理器中进行设置。

You will find a file called Spyder.bat a couple of folders down within that, eg C:\\Users\\Your_profile.anaconda\\navigator\\scripts您会在其中的几个文件夹中找到一个名为 Spyder.bat 的文件,例如 C:\\Users\\Your_profile.anaconda\\navigator\\scripts

It will take forever to open each time.每次打开都需要很长时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Anaconda 3 (Spyder) 启动 Pygubu? - How do I launch Pygubu with Anaconda 3 (Spyder)? 如何在 Spyder 中读取/写入文件 - How do I read/write to files in Spyder 如何在Mac OS上默认使.py文件可执行? - How do I make .py files executable by default on mac OS? 我找不到答案如何从包含所有依赖库的 py 文件中制作 exe - I cannot find answer how to make exe out of py files with all dependent libraries in it 如何运行在 Spyder 的单独.py 文件中定义的 function - How do I run a function which is defined in a seperate .py file in Spyder 如何在没有.py文件位于源位置的情况下使程序移动文件 - How do I make my program move files without the .py file being in the source location 在浏览器中显示的Plesk Django .py文件。 如何使其安全? - Plesk Django .py files showing in browser. How do I make it safe? 如何使“setup.py bdist_egg”忽略特定的源文件? - How do I make “setup.py bdist_egg” to ignore specific source files? 在Eclipse中,如何使用py.test执行文件夹中的所有文件? - In Eclipse, how do I execute all files in a folder using py.test? 如何使用 discord.py 列出不和谐服务器中的所有成员? - How do I make a list of all members in a discord server using discord.py?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM