Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using easy install from python

Posted on 2011-03-04
1
Medium Priority
?
385 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 500 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Last article we focus in how to VMware: How to create and use VMs TAGs – Part 1 so before follow this article and perform the next tasks, you should read the first article how to create the TAG before using them in Veeam Backup Jobs.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
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…
Suggested Courses
Course of the Month7 days, 12 hours left to enroll

824 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