Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a python script produces: ImportError: no module named termcolor

I created a new virtual environment:

$ virtualenv --no-site-packages venv --python=python3.2

Then, I activate the virtual environment and install packages:

$ source venv/bin/activate
$ pip install termcolor
$ python -m termcolor

This all works just fine. I then install my own project called Hermes which uses termcolor:

$ python setup.py install

But when I run the executable that's installed to the virtualenv's bin directory, I get an error:

ImportError: no module named termcolor

How do I install termcolor?

like image 480
Scott Frazer Avatar asked Oct 03 '11 20:10

Scott Frazer


1 Answers

The error:

ImportError: no module named termcolor

Means you have not installed termcolor. Here is how you install it for Ubuntu:

sudo apt-get install python-pip
sudo pip install termcolor

The exact command to install it for your linux distribution will depend on the package manager. When you're done with that, put this in a python script to make sure it works:

#!/usr/bin/python
from termcolor import colored
print colored('hello', 'red'), colored('world', 'green')

The script should print hello in red, and world in green. Then you know it is installed.

like image 188
Eric Leschinski Avatar answered Oct 07 '22 00:10

Eric Leschinski