Using easy install from python


I have the following code in python
cmd = "easy_install boto"
import boto

It installed boto but cant find boto unless I restart.

Anyway around this without having to restart?  What is the best way to do this?
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

clockwatcherConnect With a Mentor Commented:
It can't find boto because python's import paths are built at start up.   To import the newly installed module within the running interpreter, explicitly add the new module's path to one of python's import paths-- sys.path, for example.  

Try the following:  
import sys
import os
import os.path
import distutils.sysconfig 

# install the module
from setuptools.command import easy_install
easy_install.main( ["boto"] );

# rebuild the list of available site-packages
sitedir = distutils.sysconfig.get_python_lib()
sitepackages = [sitedir + os.path.sep + i for i in os.listdir(sitedir)]

# current locations our python knows about 
paths = {}
for path in sys.path:

# add any new locations that we don't know about
for fname in sitepackages:
    if fname in paths:
    if os.path.isdir(fname):
        print "Adding path '%s' to sys.path" % fname
        sys.path.insert(1, fname)

import boto
s3 = boto.connect_s3()

Open in new window

Not exactly sure why you'd want to do this though.  Using setuptools or pip to put together a deployment package with dependencies seems like it might be a much better option.
All Courses

From novice to tech pro — start learning today.