Properly Uninstalling Canopy Python Installation from Linux

Motivation for this blog post:

I had downloaded Canopy at the insistence of the instructors of MIT’s introductory course on computer science using Python. That said, I rarely ever used it. I’ve all along been working on Python using a text editor and command line only. I also downloaded Anaconda and started working on IPython since I began working on a new machine learning MOOC offered by the University of Washington via Coursera. Anaconda is awesome! It has all the best scientific libraries and I love IPython compared to PyCharm or Canopy, which pale in comparison to IPython, especially if you’re using Python for Machine Learning.

Anyway, I was working on IPython, trying to import matplotlib, when I got the following ImportError:

ImportError in importing matplotlib in IPython notebook

I noticed that the matplotlib library was trying to be accessed in Canopy’s Enthought directory. Since I never used or liked Canopy anyway, I decided to uninstall, bitch!

Step by step process of uninstalling Canopy from Linux:

1) From the Canopy preferences option in the Edit menu, mark off Canopy as your default Python (this step is not available on very early versions of Canopy).

2) Restart your computer.

3) Remove the “~/Canopy” directory (or the directory where you installed Canopy).
rm -rf Canopy

4) For each Canopy user, delete one or more of the directories below, which contain that user’s “System” and “User” virtual environments, and any user macros.

  • Deleting “System” removes the environment where the Canopy GUI application runs; it will be re-created the next time that you start Canopy.
  • Deleting “User” removes all your installed Python packages; it will be re-created with only the packages bundled into the Canopy installer, the next time that you start Canopy.
  • Deleting the third directory will remove any Canopy macros which you may have written. It is usually empty. I did this from the desktop home directory itself.

(for 32-bit Canopy, replace “64bit” with “32bit”):

~/Enthought/Canopy_64bit/System
~/Enthought/Canopy_64bit/User
~/canopy

For a 64 bit system:
cd Enthought/Canopy_64bit

for a 32 bit system:
cd Enthought/Canopy_32bit

rm -rf System
rm -rf User

5) Delete the file “locations.cfg” from each user’s Canopy configuration / preferences directory. For complete Canopy removal, delete this directory entirely; if you do so, the user will lose individual preferences such as fonts, bookmarks, and recent file list.

cd ~/.canopy
cd ..
rm -rf .canopy

6) If you are uninstalling completely, edit the following files to delete any lines which reference Canopy (usually, the Canopy-related lines will have been commented out by step 1 but on some system configurations the lines might remain):

For this step, refer to my blog post on opening files in a text editor from the CMD / Terminal (Using Python).

~/.bashrc
~/.bash_profile
~/.profile

7) Restart your computer.

All these steps in one:

Screenshot from 2015-09-26 11:48:43

Once I was done with these steps, I no longer encountered any issues importing matplotlib on IPython anymore.

Screenshot from 2015-09-26 12:06:47

Advertisements

Opening Files in a Text Editor from the CMD / Terminal (Using Python)

Motivation for this blog post:

I recently had to edit the .bashrc file in Ubuntu and comment / delete a subset of its contents. The file .bashrc had to be located (home directory) and opened in a text editor. The file isn’t visible in the desktop environment, so it can’t be opened from there, so I had to use bash. I’m no command line expert, so I used Python to open and edit the file. I intended to open the file in gedit text editor, so I had to run Python from the directory containing .bashrc. [Click image below to enlarge]

openGeditFromPythonInCommandPrompt

Which opened up .bashrc

Screenshot from 2015-09-26 13:46:01

Put simply:

Opening a file in text editor is a matter of two simple lines of code. First, navigate to the directory containing the file you wish to open in a text editor (such as gedit) in bash or terminal or CMD. Then type the following:


$ python
>>> import sys, os
>>> os.system("<text editor> <file name with extension>")

That’s all there is to it!