Solved

Using easy install from python

Posted on 2011-03-04
1
369 Views
Last Modified: 2012-05-11
hi,

I have the following code in python
cmd = "easy_install boto"
os.system(cmd)
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?
0
Comment
Question by:dmontgom
1 Comment
 
LVL 25

Accepted Solution

by:
clockwatcher earned 125 total points
ID: 35042968
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:
    paths[path]=""

# add any new locations that we don't know about
for fname in sitepackages:
    if fname in paths:
        continue 
    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.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

#Citrix #XenApp #Citrix Scout #Citrix Insight Services #Microsoft VMMAP #Microsoft ADEXPLORE #Microsoft RAMMAP #Microsoft TCPVIEW #Microsoft AUTORUNS #Microsoft PROCESS EXPLORER #Microsoft PROCESS MONITOR
David Varnum recently wrote up his impressions of PRTG, based on a presentation by my colleague Christian at Tech Field Day at VMworld in Barcelona. Thanks David, for your detailed and honest evaluation!
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this video tutorial I show you the main steps to install and configure  a VMware ESXi6.0 server. The video has my comments as text on the screen and you can pause anytime when needed. Hope this will be helpful. Verify that your hardware and BIO…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question