tl;dr -- Quick & easy method for a single terminal/command session
In Canopy 1.4 and above, you can make Canopy be the default Python for the duration of a single terminal session:
Windows: Open a "Canopy Command Prompt" window from the Canopy Tools menu. Please see Note #3 below.
Mac/Linux: Open a "Canopy Terminal" window from the Canopy Tools menu.
For more persistent settings, read on.
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 usually 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 persistently, you have two options:
Set Canopy Preference - usually very easy but not for everyone:
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 other 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.
- (Windows): If you wish to use binary package installers such as Chris Gohlke's, this is your only option; such installers typically require that Windows registry entries be set, so just modifying PATH, as is done by the following options, will not suffice.
Manually set PATH - fairly easy:
To make Canopy be your default Python in all subsequent Terminal/Command sessions, you can manually prepend your PATH with the following platform-specific directory:
|Windows XP||64||C:\Documents and Settings\<username>\Local Settings\Application Data\Enthought\Canopy\User\Scripts|
|Windows XP||32||C:\Documents and Settings\<username>\Local Settings\Application Data\Enthought\Canopy32\User\Scripts|
|Windows 7 & Vista||64||C:\Users\<username>\AppData\Local\Enthought\Canopy\User\Scripts|
|Windows 7 & Vista||32||C:\Users\<username>\AppData\Local\Enthought\Canopy32\User\Scripts|
To do this:
Linux or Mac OS X
Edit your ~/.bash_profile file, and uncomment (remove the initial "# " from) the line that looks like one of the following (depending on how early you installed Canopy; more details here):
# source [...] /activate
# VIRTUAL_ENV_DISABLE_PROMPT=1 source [...] activate
(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 .)
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.
Please do not enter support requests in article comments
Please use article comments for suggestions to improve the article. For individual support requests, please follow these guidelines.