Knowledge Base/Canopy/Introduction to Canopy

Make Canopy User Python be your default Python (i.e. on the PATH)

Jonathan March
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". 

Notes:

  1. 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.
  2. 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.

Fairly easy:

Alternatively, you can prepend your PATH with the following platform-specific directory:

 Platform

Word length
  Location
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
Mac OSX 64 ~/Library/Enthought/Canopy_64bit/User/bin
Mac OSX 32 ~/Library/Enthought/Canopy_32bit/User/bin
Linux 64 ~/Enthought/Canopy_64bit/User/bin
Linux 32 ~/Enthought/Canopy_32bit/User/bin

Most conservatively, you can modify PATH temporarily within a terminal session.

Windows: Just open a "Canopy Command Prompt" window from the Start Menu, and the PATH will have been set up for you!

Mac: "export PATH=/Users/<your-user-name>/Library/Enthought/Canopy_64bit/User/bin:$PATH"

Linux: "export PATH=/home/<your-user-name>/Enthought/Canopy_64bit/User/bin:$PATH"

Or you can modify PATH persistently, following these instructions: 

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 .)

Windows

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.

 

 

Comments

User photo
pierre puiseux

Anyway it's not completely clear.

From user point of view, Yes or No, setting/unsetting CanoPython as default python, is EQUIVALENT to uncomment/comment this line in the .profile user ?  

# VIRTUAL_ENV_DISABLE_PROMPT=1 source [...] activate
November 22, 2013 09:03
User photo
Marc Moncrief

Hi. I very stupidly and very rashly deleted the lines above from by bash_profile. I have tried re-installing Canopy to replace the text, but this hasn't worked.

I set up the environment in the default location, but did not make Canopy my default Python. Are you able to provide the text of the lines that Canopy adss to bash_profile so I can re-instate them?

November 24, 2013 18:06
User photo
Jonathan March
Enthought

@Marc, see the end of the "Environment setup" section of the Users Guide for your OS:

http://docs.enthought.com/canopy/quick-start.html

November 24, 2013 18:39
User photo
Deatrick Foster

Hello,

Is there an "activate" script for c-shell users (especially in the recently released version 1.2)?  I use tcsh as my shell for a number of reasons, so the bash-only activate script doesn't do me any good.  I know that using c-shell makes me a horrible person, but I can't switch to bash and would really like to use canopy-installed python at the command line for my work.  If there's no c-shell version of activate, could you please outline a useful workaround?  Many thanks for your help!

January 13, 2014 12:39
User photo
Jonathan March
Enthought

@Deatrick, you don't need activate at all; just write an alias that prefixes `<home-dir>/Enthought/Canopy_64bit/User/bin` to your PATH.

January 13, 2014 12:50
User photo
Honglin Han

I am unable to set Canopy as default right after installing. My system is 64-bit Mac OS X. I tried uninstall and remove all associate files then reinstall. I clicked on  "Start using Canopy", but it was unable to start the application.

January 17, 2014 19:22
User photo
dong qunxi

The first time I use it and set the  Canopy to be my default Python. But now I want to cancel the option, how to do?

January 22, 2014 14:46
User photo
Sharath Chandra Guntuku

When I start python, I get the following:

Enthought Canopy Python 2.7.6 | 64-bit | (default, Jan 29 2014, 17:35:36)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2

Does this mean it is running GCC version 4.1.2?

I am working with CUDA and that throws an error that gcc 4.6 and up are not supported. Is there any workaround for making GCC 4.1.2 system-wide?

I am on a cluster and do not have root access!

Thanks :)

January 31, 2014 21:19