2

I am tinkering with some pet projects with Python in Linux (Mint 13) and I plan to do the following:

  • Create a Dropbox subfolder named "pybin" where I put all my home-made python modules;
  • Put a symlink to this folder somewhere in the system (first candidate: /usr/lib/python2.7/dist-packages, which is in sys.path, or some similar path);
  • Then I just do import mymodule from any python session, and the module is imported.

I tried it and it didn't work. I suspect this has to do with differences between modules and packages, and __init__.py files, but I confess that everytime I read something about this stuff I get pretty confused. Besides learning a bit more about this, all I really want to do is find a way to import my modules the described way. It is crucial that the actual folder is inside Dropbox (or any other file-syncing folder), not in a system folder.

Thanks for any help!

heltonbiker
  • 26,657
  • 28
  • 137
  • 252

1 Answers1

2

Why not simply set the PYTHONPATH envvar in your .bash_profile. That way every time you execute a bash shell (normally happens upon login), this environment variable will be set the wherever you place your user defined modules. The python interpreter uses this variable to determine where to search for module imports:

PYTHONPATH="${PYTHONPATH}:/path/to/some/cool/python/package/:/path/to/another/cool/python/package/"

export PYTHONPATH
ennuikiller
  • 46,381
  • 14
  • 112
  • 137
  • I am very n00b regarding this. Can you explain where this definition is saved in the system, and what actually happens when you run this command? – heltonbiker Sep 16 '12 at 14:17
  • Nice. I put the commands inside a `.bashrc` file I have (also inside Dropox, symlinked in home folder ;o) and stuff is working now. Thanks! ---- Just as a side note, in Windows (7) it goes like this: http://stackoverflow.com/a/4855685/401828 (sumbled upon it just now) – heltonbiker Sep 16 '12 at 14:27
  • @heltonbiker, you need to set your environment in windows. You can modify your registry (there is a key to it) but be cautious here... – oz123 Sep 16 '12 at 14:30