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

Question:

I installed Spyder using Anaconda, and I am able to launch the IDE using the Spyder icon in my start menu (Win10). 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. The problem is that I cannot launch pythonw.exe by clicking it.

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? Also, when I double click spyder.exe in AnacondaScripts a command prompt opens along with the IDE, which does not happen when I click the start menu icon.

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?

Cheers

Asked By: shtuken

||

Answers:

You can right click any of your *.py file, go to properties and choose Spyder as “Opens with” choice.

Answered By: TYZ

I found the answer in this question, answer by xyzjayne.

You create a bat file with the following contents:

start YOURPATHAnaconda2pythonw.exe YOURPATHAnaconda2cwp.py YOURPATHAnaconda2 "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. For me it was:

C:ProgramData

And you select the Choose default program to open this file… – and you choose that bat file.

When you go to Spyder shortcut’s properties, the target includes a few files. 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.

Answered By: Scruffy

Right click on your file, and select open with or Choose default program to open this file.. and then in your system… select .. Anaconda3Scriptsspyder.exe .

I have also provided you the screenshot of the above path in my system for your reference.

enter image description here

Answered By: Mohd Naved

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.

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. 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, e.g. C:UsersYour_profile.anacondanavigatorscripts

It will take forever to open each time.

Answered By: Puffin

for Anaconda3 on win11:

start YOURPATHAnaconda3pythonw.exe YOURPATHAnaconda3cwp.py YOURPATHAnaconda3 "YOURPATHAnaconda3pythonw.exe" "YOURPATHAnaconda3Scriptsspyder-script.py" %1

Answered By: sojacookie

Below a baby-step guide to make Spyder your default program to open .py, including an icon!

  1. First, search for Spyder in windows, and open the folder that contains spyder. Spyder will be a short-cut file. Right-click the spyder shortcut file and choose "Properties". Copy all the contents of the "target" content.

  2. Open a Notepad. Write the word start and the paste the contents you obtained in step 1. Now, save the file as .bat, with any name you want, let’s say "myspyderlauncher.bat", in a convenient location for you.

  3. Go to any .py file, and choose "open with", and look for your .bat file (following the example above, the "myspyderlauncher.bat" file). Choose "always" to always open .py files with your bat.

Now double click the .py file and Spyder will automatically be started. VoilĂ !

Did you say you want a nice spyder icon too instead of that ugly white icon? Here are the next steps (optional):

  1. Download Bat to exe converter (not worries, you will not need to install the software): https://web.archive.org/web/20190304134631/http://www.f2ko.de/en/b2e.php

  2. Unzip the Bat_To_Exe_Converter.zip and go to the "portable" folder and run the .exe file. Open your .bat file ("myspyderlauncher.bat" in the example above), and then go to the right menu, click and look in the "icon" option and look for the Spyder icon (.ico file), which is normally in …Anaconda#Scripts.

  3. Now press "convert" in Bat_to_Exe and save your new .exe file in a convenient location with a convenient name you want. (Let’s say we call it "spyderlauncher.exe")

  4. Go to any .py file, and choose "open with", and look now for your .exe file (following the example above, the "spyderlauncher.exe" file). Choose always to always open .py files with your bat.

You will see that all your .py files are now associated to spyder, with a beautiful icon attached, and opening in Spyder.

Some screenshots below
screenshots

Answered By: Rolando Gonzales
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.