uWSGI installation exception on Amazon Linux EC2 instance - django

I'm a newbie trying to set a server for my first phone-App on Amazon EC2 with nginx, django, uWSGI and mySQL.
I'm following those tutorials (actually the second is based on the first one):
http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html
http://www.oliverelliott.org/article/computing/tut_setup_nginx_django/
I'm using a MacbookPro and once in terminal I ssh into the Amazon Linux EC2 instance.
When it comes to install uwsgi..troubles arise.
I executed:
$ sudo yum install python-pip
$ sudo yum install python-devel
$ sudo pip install uwsgi
First two worked fine, last command thrown an exception:
Downloading/unpacking uwsgi
Running setup.py egg_info for package uwsgi
Installing collected packages: uwsgi
Running setup.py install for uwsgi
using profile: buildconf/default.ini
detected include path: ['/usr/include', '/usr/local/include']
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-root/uwsgi/setup.py", line 109, in <module>
distclass=uWSGIDistribution,
File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup
dist.run_commands()
File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands
self.run_command(cmd)
File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command
cmd_obj.run()
File "/tmp/pip-build-root/uwsgi/setup.py", line 71, in run
conf = uc.uConf(get_profile())
File "uwsgiconfig.py", line 687, in __init__
raise Exception("you need a C compiler to build uWSGI")
Exception: you need a C compiler to build uWSGI
Complete output from command /usr/bin/python26 -c "import setuptools;__file__='/tmp/pip-build-root/uwsgi/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-l8npX4-record/install-record.txt --single-version-externally-managed:
running install
using profile: buildconf/default.ini
detected include path: ['/usr/include', '/usr/local/include']
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-root/uwsgi/setup.py", line 109, in <module>
distclass=uWSGIDistribution,
File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup
dist.run_commands()
File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands
self.run_command(cmd)
File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command
cmd_obj.run()
File "/tmp/pip-build-root/uwsgi/setup.py", line 71, in run
conf = uc.uConf(get_profile())
File "uwsgiconfig.py", line 687, in __init__
raise Exception("you need a C compiler to build uWSGI")
Exception: you need a C compiler to build uWSGI
----------------------------------------
Command /usr/bin/python26 -c "import setuptools;__file__='/tmp/pip-build-root/uwsgi/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-l8npX4-record/install-record.txt --single-version-externally-managed failed with error code 1 in /tmp/pip-build-root/uwsgi
Storing complete log in /root/.pip/pip.log
I've tried two suggestions I read, but doesn't seem to work for me:
$ export CC=gcc && pip install -r requirements.txt
and
$ sudo CC=gcc pip install uwsgi
Any suggestions? Thanks a lot in advance!!

I was helped by this link: uWSGI: Installing from a distribution package
I did:
yum groupinstall "Development Tools"
yum install python-devel
and then:
pip install uwsgi
and after that it works.

This installation helped me:
sudo yum groupinstall "Development Tools"
sudo yum install python3-devel

Related

Install google chrome for python selenium in a google cloud run app

I'm trying to use selenium in a cloud run app that I'm working on. The app works correctly on my local machine but it's not working after I deploy it on google cloud run. The error I'm getting is related to not having chromedriver.exe installed on google cloud.
This is the traceback error from the logs:
Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception reraise(exc_type, exc_value, tb) File "/usr/local/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise raise value File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/app/main.py", line 22, in daily_login login.create_access_token() File "/app/scripts/loginFlow/login.py", line 30, in create_access_token request_token = generate_request_token() File "/app/scripts/loginFlow/login.py", line 61, in generate_request_token driver = webdriver.Chrome() File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__ self.service.start() File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 83, in start os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
The relevant part of that traceback seems to be Message: 'chromedriver' executable needs to be in PATH. How do I get the chromedriver executable in PATH for this google cloud run app?
Now, what have I tried to do about it?
First, I found this post: unable to run selenium chrome-driver on google-cloud-run and followed the instructions left in the comments. I looked at this post on dev.to and modeled my Dockerfile similar to what was suggested. The only difference is that I'm using Python3.6 instead of Python3.7:
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.6-slim
# Install manually all the missing libraries
RUN apt-get update
RUN apt-get install -y gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils
# Install Chrome
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install
# Install Python dependencies.
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 main:app
I also added chromedriver-binary==77.0.3865.40.0 to my requirements.txt file.
When I try to deploy it using gcloud builds submit, I get this error:
/bin/sh: 1: wget: not found
The command '/bin/sh -c wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb' returned a non-zero code: 127
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 127
I'm been trying to find a solution for this error online but I'm lost. Your help would be greatly appreciated!
Add a command to install wget.
# Install manually all the missing libraries
RUN apt-get update
RUN apt-get install wget
I was facing the same problem, finally got this to work! here is my Dockfile:
FROM python:3.7
# Install manually all the missing libraries
RUN apt-get update
RUN apt-get install -y gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils default-jdk
# Install Chrome
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install
# Install Python dependencies.
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
# Copy local code to the container image.
WORKDIR /app
COPY . .
CMD gunicorn --bind :$PORT --workers 1 --threads 3 main:app --timeout 90

centOS install mysqlclient fail (via pip3)

I am trying to run Django2.0 on centOS server,
I have installed python3 and pip3,
django2.0 also installed under virtualenv,
but an error pop out when I tried to install mysqlclient under virturlenv, error msg below:
Collecting mysqlclient
Using cached mysqlclient-1.3.12.tar.gz
Complete output from command python setup.py egg_info:
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-7hd8p93o/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/tmp/pip-build-7hd8p93o/mysqlclient/setup_posix.py", line 44, in get_config
libs = mysql_config("libs_r")
File "/tmp/pip-build-7hd8p93o/mysqlclient/setup_posix.py", line 26, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-7hd8p93o/mysqlclient/
Any idea please
I solved the same issue with:
sudo yum install python36u-devel mysql-devel
I solved the same issue with!
yum install -y python3-devel.x86_64

Ipython broke: doesn't start, says missing 'pathlib2' distribution

When i execute ipython in terminal i see following error
aman#ebex-MacBookPro:~/ipython_work$ ipython
Traceback (most recent call last):
File "/usr/local/bin/ipython", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3141, in <module>
#_call_aside
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3127, in _call_aside
f(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3154, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 640, in _build_master
ws.require(__requires__)
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 941, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 828, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pathlib2' distribution was not found and is required by ipython
Just before that i followed
$ git clone --recursive https://github.com/ipython/ipython.git
$ cd ipython
$ pip install -e ".[notebook]"
From the link [How to autosave ipython notebook]
http://stackoverflow.com/questions/21517296/how-to-autosave-ipython-notebook
I tried to uninstall and install using apt-get but its still not working and throwing missing distribution error.
I installed pathlib2 though
sudo pip install pathlib2
But again while accessing ipython
I see another error
pkg_resources.DistributionNotFound: The 'backports.shutil_get_terminal_size' distribution was not found and is required by ipython
You need install some packages manually as follows:
pip install pathlib2
pip install backports.shutil_get_terminal_size
pip install enum34
For me, I also had to pip install enum34 but otherwise int32bit's answer worked.
pip install pathlib2 backports.shutil_get_terminal_size enum34
I see the same error When i execute ipython interminal. The problem was solved by installing libraries about the exception.
I launched the Jupyter notebook from Anaconda "Environments" and the dos Windows open with all the launching packages in issues appearing.
Then I just had to install packages missing and mentioned in this window in your environment one by one. You can retry the same process as many times as needed.

Installing aws cli

I am getting this message when I try to install aws. Anyone have any ideas of what's going on?
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 209, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 725, in install
requirement.uninstall(auto_confirm=True)
File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 756, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 266, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
copy2(src, real_dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
copystat(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/tmp/pip-TIuiKe-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'
The command I'm using is pip install awscli
The problem is about permisson. The installer are trying to write in a folder that doesnt have permission.
try sudo pip install awscli
It looks like it is trying to uninstall six-1.4.1. I had the same issue. Telling pip to ignore installed package should work.
sudo pip install --ignore-installed awscli
sudo pip install --upgrade --user awscli
--upgrade : tells pip to upgrade any requirements that are already installed

Unable to install MySQL-python

Okay I recently upgraded from Ubuntu 10.04 to 12.04
Only to be faced by a lot of problems. I am a newbie at this so you might have to tell me in a little more detail or step-by-step
I had a django project that was working perfectly but now it gives me this error :
File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 16, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
or in python :
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.linux-i686/egg/MySQLdb/__init__.py", line 19, in <module>
File "build/bdist.linux-i686/egg/_mysql.py", line 7, in <module>
File "build/bdist.linux-i686/egg/_mysql.py", line 6, in __bootstrap__
ImportError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
Anyways I thought there was some problem with my MySQL-python so I tried re-installing it.
sudo pip install mysql-python
gives :
Downloading/unpacking mysql-python
Running setup.py egg_info for package mysql-python
The required version of distribute (>=0.6.28) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U distribute'.
(Currently using distribute 0.6.24dev-r0 (/usr/lib/python2.7/dist-packages))
Complete output from command python setup.py egg_info:
The required version of distribute (>=0.6.28) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U distribute'.
(Currently using distribute 0.6.24dev-r0 (/usr/lib/python2.7/dist-packages))
----------------------------------------
Command python setup.py egg_info failed with error code 2 in /tmp/pip-build/mysql-python
Storing complete log in /home/nabeel/.pip/pip.log
If I do :
sudo easy_install -U distribute
It gives this error :
Searching for distribute
Reading http://pypi.python.org/simple/distribute/
Reading http://packages.python.org/distribute
Best match: distribute 0.6.29
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.29.tar.gz#md5=1aad767bfca8bebaccafee25f85696cf
Processing distribute-0.6.29.tar.gz
Running distribute-0.6.29/setup.py -q bdist_egg --dist-dir /tmp/easy_install-K8ZuMX/distribute-0.6.29/egg-dist-tmp-Fj0gj_
Before install bootstrap.
Scanning installed packages
Setuptools installation detected at /usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Egg installation
Patching...
Renaming /usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg to /usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg.OLD.1350776909.4
Patching complete.
Relaunching...
Traceback (most recent call last):
File "/usr/local/bin/easy_install", line 9, in <module>
load_entry_point('distribute==0.6.8', 'console_scripts', 'easy_install')()
File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/command/easy_install.py", line 1708, in main
with_ei_usage(lambda:
File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/command/easy_install.py", line 1696, in with_ei_usage
return f()
File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/command/easy_install.py", line 1712, in <lambda>
distclass=DistributionWithoutHelpCommands, **kw
File "/usr/local/lib/python2.7/distutils/core.py", line 152, in setup
dist.run_commands()
File "/usr/local/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/local/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/command/easy_install.py", line 236, in run
self.easy_install(spec, not self.no_deps)
File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/command/easy_install.py", line 471, in easy_install
return self.install_item(spec, dist.location, tmpdir, deps)
File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/command/easy_install.py", line 501, in install_item
dists = self.install_eggs(spec, download, tmpdir)
File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/command/easy_install.py", line 680, in install_eggs
return self.build_and_install(setup_script, setup_base)
File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/command/easy_install.py", line 957, in build_and_install
self.run_setup(setup_script, setup_base, args)
File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/command/easy_install.py", line 946, in run_setup
run_setup(setup_script, args)
File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/sandbox.py", line 29, in run_setup
lambda: execfile(
File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/sandbox.py", line 70, in run
return func()
File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/sandbox.py", line 31, in <lambda>
{'__file__':setup_script, '__name__':'__main__'}
File "setup.py", line 131, in <module>
File "/tmp/easy_install-K8ZuMX/distribute-0.6.29/distribute_setup.py", line 368, in _before_install
File "/tmp/easy_install-K8ZuMX/distribute-0.6.29/distribute_setup.py", line 441, in _fake_setuptools
File "/tmp/easy_install-K8ZuMX/distribute-0.6.29/distribute_setup.py", line 450, in _relaunch
NameError: global name '_cmd1' is not defined
Again now I have gone to this link :
http://pypi.python.org/pypi/setuptools/0.6c11
to download and install setuptools..
I have also installed the latest distribute 0.6.8 from here :
http://pypi.python.org/pypi/distribute/0.6.8
I have also tried uninstalling the previous versions and installing back but it doesn't seems to work.
I have got Python 2.7.3 installed
Could someone please explain to me what is going on... How I can install Mysqldb...
I have also ran these commands on shell :
sudo apt-get install mysql-server mysql-client python-mysqldb libmysqlclient-dev python-dev
But it didn't help ...
UPDATE I JUST DID THIS AND GOT THIS ERROR :
nabeel#nabeel-pc:~$ pip uninstall setuptools
Uninstalling distribute:
/usr/bin/easy_install
/usr/bin/easy_install-2.7
/usr/lib/python2.7/dist-packages/distribute-0.6.24dev_r0.egg-info
/usr/lib/python2.7/dist-packages/easy_install.pyc
/usr/lib/python2.7/dist-packages/pkg_resources.pyc
/usr/lib/python2.7/dist-packages/setuptools
/usr/lib/python2.7/dist-packages/site.pyc
/usr/share/pyshared/easy_install.py
/usr/share/pyshared/pkg_resources.py
/usr/share/pyshared/site.py
Proceed (y/n)? y
Successfully uninstalled distribute
nabeel#nabeel-pc:~$ sudo easy_install -U distribute
Searching for distribute
Reading http://pypi.python.org/simple/distribute/
Reading http://packages.python.org/distribute
Best match: distribute 0.6.29
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.29.tar.gz#md5=1aad767bfca8bebaccafee25f85696cf
Processing distribute-0.6.29.tar.gz
Running distribute-0.6.29/setup.py -q bdist_egg --dist-dir /tmp/easy_install-Xcer8d/distribute-0.6.29/egg-dist-tmp-K0E7gP
Before install bootstrap.
Scanning installed packages
Setuptools installation detected at /usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Egg installation
Already patched.
After install bootstrap.
Creating /usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info
Creating /usr/local/lib/python2.7/site-packages/setuptools.pth
Removing distribute 0.6.8 from easy-install.pth file
Adding distribute 0.6.29 to easy-install.pth file
Installing easy_install script to /usr/local/bin
Installing easy_install-2.7 script to /usr/local/bin
Installed /usr/local/lib/python2.7/site-packages/distribute-0.6.29-py2.7.egg
Processing dependencies for distribute
Finished processing dependencies for distribute
nabeel#nabeel-pc:~$ sudo pip install mysql-python
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources
UPDATE 2 :
I have managed to install virtualenv
now in the environment I have also managed to install MySQLdb.
Here's theh error I get while running my server :
sudo python manage.py syncdb
I get this error:
File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 16, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
(myenv)nabeel#nabeel-pc:~/workspace/gteam/metrics$ python
Python 2.7.3 (default, Oct 6 2012, 21:57:36)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> exit()
Using virtualenv
First things first. Make sure you have Mysql, Setuptools and some essentials:
sudo apt-get install mysql-server
sudo apt-get install python-setuptools python-dev build-essential
Now install VirtualEnv:
sudo easy_install -U virtualenv
Create a Virtual Environment. As the documentation says: virtualenv is a tool to create isolated Python environments. This means that the chances of getting a conflict are really small. Here "myenv" is the name of a folder where you can access your environment, so create it where you want.
virtualenv --distribute myenv
Then go to "myenv" directory and run this to activate it:
source myenv/bin/activate
You need to install libmysqlclient-dev to get MySQL-python working:
sudo apt-get install libmysqlclient-dev
Now you're ready to install MySQL-python:
pip install MySQL-python
and everything should be working.
When you don't want to work in that environment anymore, write in the terminal:
deactivate
UPDATE:
Since this answer keeps getting upvotes, let me show you how to do the same using conda, which has become my favorite environment nowadays. First you have to install anaconda (I believe you can also install miniconda, which is a lighter version that includes conda and some packages.) Here you will find the installer for Linux, OS X and Windows. It is a big file but contains a lot of pre-compiled packages ready to be installed. Assuming you already have installed anaconda, you can simply run:
conda create -n mysql-env python
mysql-env is the name of the environment (you can call it whatever you want) and python is the default version of python to be installed (currently, 2.7.10). Alternatively, install other version of python with conda create -n my-new-env python=3.4.
Then you activate your environment:
source activate mysql-env
and finally install mysql-python:
conda install MySQL-python
(I think conda install mysql-python also works)
And that's all.
easy_install -U distribute solved my problem
In some Ubuntu installations, you'll also want to consider libmysqlclient-dev:
sudo apt-get install python-dev libmysqlclient-dev
It also held me back. The other responders probably already had it installed and didn't realize it was required.