How to install Python modules needed by plugins?

Alexander Belchenko bialix at ukr.net
Wed Mar 9 10:48:10 UTC 2011


Eli Zaretskii пишет:
>> Date: Wed, 09 Mar 2011 12:26:03 +0200
>> From: Alexander Belchenko <bialix at ukr.net>
>> CC: John Arbash Meinel <john at arbash-meinel.com>, 
>>  bazaar at lists.canonical.com
>>
>>>> Something like:
>>>>
>>>> C:\Program Files\Bazaar\site-packages
>>>>
>>>> I don't know if it can easily be done as part of bzr-windows-installers.
>>>> But certainly we could put in 'bzr':
>>>>
>>>>  if sys.frozen and sys.platform == 'windows':
>>>>    sys.path.append(os.path.join(os.path.dirname(sys.executable),
>>>>                                 'site-packages'))
>>> Excuse me my ignorance, but why something like that is not already
>>> working?  
>> "like that" - like what?
> 
> Like bzr (or its Python interpreter) looking in site-packages
> subdirectory of some directory.

That's a Python interpreter magic. py2exed application has different 
kind of sys.path magic inside.

>> Standalone bzr.exe uses different path for Python modules.
>>
>> You can put the file path.py with the following content into your 
>> plugins directory:
>>
>> #------------
>> import sys
>> print sys.path
>> #------------
>>
>> And run any bzr command, e.g. `bzr rocks` and you will see what bzr.exe 
>> puts into sys.path
> 
> Thanks for this.  I wish I knew this trick a few days ago, then I'd
> realized much sooner that library.zip is my only chance.

Sorry, I haven't had a chance to answer yesterday.

>> If you really want to understand what's going on under the hood you need 
>> learn how py2exe tool works.
> 
> On to read about that.  Thanks again for pointing me to the right
> place to look.

Actually we can mangle sys.path for bzr.exe using plugin, but we need to 
put it first in the loading list, so let's name it a.py:

#-----------------------------------------------------------------
if getattr(sys, 'frozen', None) is not None:
     sys.path.append(os.path.join(os.path.dirname(sys.executable),
                                  'site-packages'))
#-----------------------------------------------------------------

And after that you should be able to put extra python libs into
C:\Program Files\Bazaar\site-packages

-- 
All the dude wanted was his rug back



More information about the bazaar mailing list