Search code examples
pythonenthoughtcanopy

Trying to directly run .py file using Enthought Canopy Python on Windows 7


I am trying to set up Canopy with Windows so that it will not, by default, try to open as a GUI. Essentially I want to do exactly this:

http://docs.enthought.com/canopy/configure/canopy-cli.html#create-epd-dist

The only problem is that the instructions listed here do not seem to work as expected.

Here's what I want to happen. I have a folder full of scripts. The folder (my_program/) is in my path. I want to call script_1.py on the command line from any directory and have it execute. With the old Enthought distribution this is what happens. It is also what happens with Canopy on Mac. However, running Canopy on Windows, instead the Canopy GUI pops up with script_1.py open for editing.

I ran this command as in the docs:

Canopy\App\Canopy_cli.exe setup C:\Python27 --set-default

It created a "Canopy 64 bit (standalone) Command Prompt" in addition to the regular Command Prompt. However, the behavior in both this new Command Prompt and the regular Command Prompt remains the same -- script_1.py simply opens the Canopy GUI.

Here is my PATH variable:

c:\python27\scripts;  
c:\users\****\appdata\local\enthought\canopy\user\scripts;  
C:\Users\****\AppData\Local\Enthought\Canopy\User; 
C:\Users\****\AppData\Local\Enthought\Canopy\User\Scripts;   
C:\Python27;  
C:\Python27\Scripts;  
C:\Users\****\Documents\my_program;

Any ideas why I'm not able to set up Canopy as an EPD-like environment, or how to do so? Thanks!

Update:

First, I ran this command as Jonathan March outlined in his answer:

ftype Python.File=c:\Users\**\AppData\Local\enthought\Canopy\User\Scripts\python.exe %1

However, with this the behavior remained the same. The above turned out to be half of the solution.

Fortunately, I was able to get it working using regedit. I had to edit Computer\HKEY_CLASSES_ROOT.py by changing the default from "Enthought.Canopy" to "Python.File". And I also changed Computer\HKEY_CLASSES_ROOT.py\OpenWithProgIds by deleting the "Enthought.Canopy" key and adding a "Python.File" key.

I'm really happy to have it working, however mucking around with regedit is a difficult task for Windows users of my software. Now I'm wondering, is there a simpler way to do this, perhaps in the install script that puts my folder of command-line scripts into their path? Any ideas are appreciated.


Solution

  • Sorry for the confusion -- "EPD-like" refers to running python directly, not to the windows file associations, but I can definitely see your point. Here's how to get what you want:

    1) Even if you are a full admin on this system, open an "Administrator:Command Prompt" window as described in in steps 1 and 2 in this article: https://support.enthought.com/entries/23736288-Windows-On-some-systems-admin-users-cannot-immediately-install-for-all-users-

    2) In this window, type the following command at the command prompt:

    ftype Python.File=c:\Users\**\AppData\Local\enthought\Canopy\User\Scripts\python.exe %1
    

    Test that it now works as desired, then close this window.