How to make Spyder open python scripts (.py files) directly from Windows Explorer

I recently installed the Anaconda distribution on Windows 7 (Anaconda 3-2.4.0-Windows-x86_64). Unlike IDLE, I cannot right-click and open the py file in the Spyder IDE. First I will need to open Spyder, and then go to the file or drag it to the editor. Is there a way to open a file in an editor directly from Widows Explorer?

+15
source share
5 answers

In the current version of Anaconda (4.1.0), you can simply right-click on the python script in Windows Explorer and select "Open with." The first time you do this, you need to select "Choose the default program" and then go to spyder.exe in the script directory in your Anaconda installation. Also make sure that β€œAlways use the selected program to open such a file” is not installed, and then click β€œOK”. From now on, spyder.exe will always be displayed as one of the options when you select "Open with" in the right-click menu in Windows Explorer.

+7
source

I had a similar problem with other software that I use.

My way around this problem is to set the .py file association to C:\Anaconda\Scripts\spider-script.py through the Open With dialog box. If you now try to open your File.py double-clicking, you will get an error message like

~ \ file.py is not a valid Win32 application.

This can be solved by editing the spyder-script.py registry spyder-script.py :

 HKEY_USERS\S-1-5-21-3559708500-1520960832-86631148-1002\Software\Classes\Applications\spyder-script.py\shell\open\command 

and replacing the default value "C:\Anaconda\Scripts\spyder-script.py" %1 with "C:\Anaconda\python.exe" "C:\Anaconda\Scripts\spyder-script.py" %1 . Use the search function for this key if the path does not match for your computer, and of course, use the appropriate path for your Python installation. spyder-script.py should now run in the Python shell.

From the document line ftype,

... In the open command line,% 0 or% 1 are replaced with the name of the file that is launched through the association.

+3
source

Right now there is no way to open a file in Spyder from Windows Explorer when using Anaconda. But we are working to ensure that this functionality is in a future version.

It will work by adding an entry to the Open With menu, which you can see when you right-click on a file in Explorer.

+1
source

What works fine for me on Windows (10) associates *.py files with a batch file (say, "SpyderBATCH.bat") containing this line:

 [ANACONDA_FOLDER_PATH]\pythonw.exe" "[ANACONDA_FOLDER_PATH]\cwp.py" "[ANACONDA_FOLDER_PATH]" "[ANACONDA_FOLDER_PATH]/pythonw.exe" "[ANACONDA_FOLDER_PATH]/Scripts/spyder-script.py" %1 

Where [ANACONDA_FOLDER_PATH] must be replaced with the full path to the Anaconda folder (usually in the "Program Files" section).

What does Windows do when double-clicking on a python script (say "file.py") goes to SpyderBATCH, as parameter number %1 , the full path to file.py.

Spyder then launches and displays the script "file.py" in the editor view.

+1
source

I could not find spyder.exe in my conda installation. However, in my /.anaconda/navigator/scripts users, I found the spyder.bat file. When using this to open a file, Anaconda prompt opens and shortly afterwards Spyder opens the file. The file icon does not work, but it works for me. Hope this helps.

0
source

Source: https://habr.com/ru/post/1236387/


All Articles