3

Is it possible to make a python session aware of new libraries which have been easy_installed since the session was launched?

I have a console which has run for a few days, and finally came up with the (large) result. I realized upon inspecting the results that I would require another package (nltk) for processing, which I installed, but the session can't import it (new ones can). The problem is, I can't seem to save the unprocessed results (pickle and marshal give me errors about string lengths) and I really don't want to re-run the week-long procedure.

Sam Mussmann
  • 5,883
  • 2
  • 29
  • 43
mitchus
  • 4,677
  • 3
  • 35
  • 70
  • Can you write the data to a file, without pickle/marshal? What kind of data are you dealing with? – Junuxx Oct 31 '12 at 10:17
  • 1
    Possible duplicate of http://stackoverflow.com/questions/3231011/how-to-easy-install-egg-plugin-and-load-it-without-restarting-application – Mattie Oct 31 '12 at 10:23
  • They are tweets (as provided by `tweetstream`) -- highly nested structures, dictionaries in lists etc, so not straightforward to save. – mitchus Oct 31 '12 at 10:23
  • Have you tried using pickle with a different protocol than teh default? (pass pickle.dump the number "-1" for protocol) – jsbueno Oct 31 '12 at 10:27
  • @zigg : although it is not a duplicate of the question you point to (the other question is a bit more complex), the answer works for me! Thanks. – mitchus Oct 31 '12 at 10:28

1 Answers1

2

You could try loading the new package using the imp module:

from imp import *
file, pathname, description = find_module('nltk')
nltk = load_module('nltk', file, pathname, ('.py', 'U', 1))

You may need to specify a path argument for find_module if python can't find the newly installed module:

file, pathname, description = find_module('nltk', '/path/to/nltk')

Replacing the last argument with the path that nltk was installed to.

Rob Z
  • 36
  • 2