Solved

Using easy install from python

Posted on 2011-03-04
1
382 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

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

#Citrix #Citrix Netscaler #HTTP Compression #Load Balance
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.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

636 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