0

I use a script under virtualenv, that requires bzrlib package which is not available in my virtualenv but is included in my system python packages: /usr/lib/python2.7/dist-packages/bzrlib/

If I want to use it, one option is to extend sys.path, but I would have to include the parent folder /usr/lib/python2.7/dist-packages/ which contains many other packages, that I don't want to make available. Is there any easy way to include just bzrlib package?

vlad
  • 771
  • 2
  • 10
  • 21
  • 1
    What about creating a link in different directory and importing using that? Or even in your own project. – Reut Sharabani Dec 14 '14 at 15:33
  • @ReutSharabani I just did that, thanks for confirming same idea. I thought that there is maybe some tweak that would allow me to extend sys.path as explained. – vlad Dec 14 '14 at 15:37
  • @unutbu, thanks for you suggestion. I'll go with symlink to avoid changing import statements in initial script/package. – vlad Dec 14 '14 at 15:40

1 Answers1

1

What about creating a link in different directory and importing using that? Or even in your own project.

ln -s /package/dir/path /project/dir/path

If you have to load it remotely, here is the link provided by @unutbu showing how to do it:

How to import a module given the full path?

import imp

foo = imp.load_source('module.name', '/path/to/file.py')
foo.MyClass()
Community
  • 1
  • 1
Reut Sharabani
  • 30,449
  • 6
  • 70
  • 88