On Thu, Oct 27, 2011 at 11:16 AM, Andrea Crotti <andrea.crotti.0@gmail.com> wrote:
Answering to myself, I was using the wrong functions for pkg_resources, and
in theory I should use find_distributions.
So I tried the following
- construct a very minimal egg with a foolproof module
- find and add to the working_set all the distributions found

for d in find_distributions('egg_directory'):
   working_set.add(d)

from foolproof import fool

And in fact in sys.path the foolproof egg is there, but then I can't still
import foolproof...
Is there anything else I need to do?

You're making this way too hard.  ;-)

All of the APIs you're using are low-level things, used only for advanced plugin frameworks or installer tools.  All you need for a simple script is:

sys.path.insert(0, abspath('egg_directory'))
import pkg_resources
pkg_resources.require('foolproof')
import foolproof

(Note: if you want 'egg_directory' to override the default sys.path, it is important that you *not* import pkg_resources until after you've set up the path.)
 
Also, even the above is *completely unnecessary* as long as the script you are running is part of a project with its own setup.py.

If your script is listed in a setup.py, and you install it with setup.py develop or using easy_install, then setuptools creates a wrapper for your script that does all of the pkg_resources stuff for you automatically, using the dependences specified in your setup.py.  99% of the time, if you are using pkg_resources for anything but accessing file resources or implementing some sort of plugin system, you are probably doing it wrong.  ;-)

So, the only reason I'm even listing the above require() call is just in case you can't run those generated script wrappers easily from inside Eclipse.  And, even if that is the case, you should still make sure your setup.py includes those dependencies, so that when you distribute your project the dependencies will still get installed, and a proper wrapper will be generated during installation.