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

后端 未结 8 469
無奈伤痛
無奈伤痛 2020-12-29 07:10

I have recently installed the Anaconda distribution on Windows 7 (Anaconda 3-2.4.0-Windows-x86_64). Unlike IDLE, I can\'t right-click and open a py file in the Spyder IDE. I

相关标签:
8条回答
  • 2020-12-29 07:23

    I have had a similar problem with another piece of software that I use.

    My work around for this problem is to set the file association for .py files to C:\Anaconda\Scripts\spider-script.py via the Open with dialog. If you now try to open your File.py by double clicking you'll receive an error like

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

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

    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 isn't the same for your machine, and of course use the appropriate path for your python installation. spyder-script.py should now execute in a python shell.

    From the docstring of ftype,

    ...Within an open command string, %0 or %1 are substituted with the file name being launched through the association.

    0 讨论(0)
  • 2020-12-29 07:27

    What is working very well for me in Windows (10), is associating the *.py files with a batch file (let's 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] has to be replaced with the full path to the Anaconda folder (usually under "Program Files").

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

    Then Spyder is launched and displays the script "file.py" in the editor view.

    0 讨论(0)
  • 2020-12-29 07:28

    The solution from JoeB152 worked perfectly for me!

    If you are interested in adding the spyder icon (or any other) to the .py-files and if you would like to avoid the cmd-pop-up, I found out the following workaround which is feasible without admin rights:

    1. Download the portable version of Bat To Exe Converter (I used v3.0.10).
    2. Open your custom .bat-file in the Bat to Exe Converter.
    3. In the options settings, activate "Icon" and give the path to the respective icon (for me it's in: .../AppData/Local/Continuum/anaconda3/Scripts/spyder.ico).
    4. Set Exe-Format to Invisible (no empty cmd window would pop up anymore)
    5. Convert your .bat-file to an .exe-file.
    6. As usual, set to open .py-files with the newly created .exe.

    Enjoy!

    Environment: Windows 10, Conda 4.8.2, Spyder 4.0.1, Python 3.7

    0 讨论(0)
  • 2020-12-29 07:30

    I was unable to find a spyder.exe on my installation of conda. However in my users/.anaconda/navigator/scripts I found a spyder.bat file. Using this to open the file opens an anaconda prompt and shortly after spyder will open the file. The file icon is broken but it works for me. Hope this might help.

    0 讨论(0)
  • 2020-12-29 07:35

    This problem is related to anaconda installation defaults - it does not register itself in PATH by default an dicourages users to do so. After proprly registering all directories in path, spyder.exe works as expected.

    How to know, what to register? locate and activate.bat an run it in cmd, then run echo %PATH% and manually register all directories mentioning anaconda.

    Alternatively, reinstall anaconda with PATH registratin enabled. Then you can associate .py files wit spyder.exe and association will work.

    0 讨论(0)
  • 2020-12-29 07:40

    With the current version of Anaconda (4.1.0) you can simply right-click on a python script in Windows File Explorer and choose "Open with". The first time you do this you need to select "Choose default program" and then browse to spyder.exe in the Script directory in your Anaconda installation. Also make sure that the "Always use the selected program to open this kind of file" is unchecked and then click OK. From now on spyder.exe will always be listed as one of the options when you select "Open with" from the right-click menu in Windows File Explorer.

    0 讨论(0)
提交回复
热议问题