Make Canopy User Python be your default Python (i.e. on the PATH)
posted this on April 21, 2013 10:48
(Updated March 7, 2014)
At the end of Canopy's initial setup, there is an option, which is selected by default, to make Canopy's Python be your default Python at the terminal / shell / command prompt. (This option will not apply to any terminal sessions that are already open, but rather to terminal windows opened subsequently.)
You might reasonably decide not to accept this default, for example if you are currently using another Python distribution (such as EPD) for production work, or do not want .py files to be associated with Canopy's editor at this time. This will not affect operation inside the Canopy GUI application.
However not making Canopy your default Python does complicate your ability to use Canopy Python from a command prompt, including installing external packages, because it may not be immediately obvious where Canopy's User Python is actually located if you want to refer to it explicitly. Canopy uses virtual environments as described here, so that there are actually three Canopy Pythons. You should only use the Canopy User Python! Running the wrong Python (or IPython) will lead to confusing misbehavior.
How to check whether Canopy User Python is your default Python
Start python or ipython from a terminal session, do import sys; sys.prefix, and check that the output value ends in "Enthought/Canopy[something]/User" (specifically, it should match most of the path shown in the platform-specific table below. It should also match the value of sys.prefix that is shown when you type the same command in the Canopy GUI's Python panel.
If you did not initially make Canopy your default Python, but would now like to make it so, you have two options:
Usually very easy but not for everyone:
In Canopy 1.0.3 or higher, open the Canopy Preferences dialog (on the General tab) and click on "Set [Canopy] as default".
This does not always succeed; sometimes this Canopy GUI dialog can't actually decide whether Canopy Python would be the default in a terminal. We apologize for the inconvenience, and are working to improve the behavior. If this happens to you, we suggest using one of the "Fairly easy" options below.
This will subsequently cause the OS to open all python files, by default, in the Canopy editor (file association). This is the safest approach because it protects you from inadvertently running malicious scripts. After a python file has been opened in the Canopy editor, you can run it with a single keystroke. Nonetheless, this will be not be the desired behavior for all users, and in this case you should not use this functionality.
Alternatively, you can prepend your PATH with the following platform-specific directory:
C:\Documents and Settings\<username>\Local Settings\Application Data\Enthought\Canopy\User\Scripts
C:\Documents and Settings\<username>\Local Settings\Application Data\Enthought\Canopy32\User\Scripts
(On some systems, this line will be in the ~/.profile or ~/.bashrc file. Wherever you find it, you can usually just uncomment it when you want Canopy to be your default Python. Note that if you have both .bash_profile and .profile on OSX, then only .bash_profile will be used, unless another config file explicitly invokes .profile .)
If all you want to do is run some scripts in Canopy User Python at a Windows command line (i.e. you don't need to do special package builds or installations), the easiest way is simply to open a "Canopy Command Prompt" window from the Start Menu.
If your needs go beyond this case, read on:
Editing the Windows PATH through the Control Panel (System / Advanced / Environment / User) is awkward and error-prone. We recommend using a utility such as the free Rapid Environment Editor, to back up your existing PATH settings, modify them, and/or switch between different PATH settings.
One possible source of confusion in Windows: if Canopy was installed for current user, and you already have a Python (e.g. EPD 7.3) which was installed for all users, then even if you specified that Canopy should be your default Python, the "all user" python default will take precedence. The way to override this is to modify the System PATH environment variable to begin with the Canopy Python directory, or to remove Python altogether from this environment variable. (Again, Rapid Environment Editor makes this much easier to do.) You will need admin permission to do this.
Undoing Canopy as the default Python
To remove Canopy from your PATH, simply reverse the (OS-specific) manual process described above.
Manually changing file associations (.py in this case) is more difficult. The usual process, which applies to most applications including Canopy, is that when you install another application which you wish to assume control of a particular file association, it will do so for you. Metaphorically speaking, you change color by re-painting rather than by attempting to scrape off the previous layer.