文档章节

【原创】Tribler开发--BG Process的编译

摩云飞
 摩云飞
发布于 2012/10/28 12:35
字数 2172
阅读 404
收藏 0

遵照 http://www.tribler.org/trac/wiki/BrowserPlugin 中对SwarmPlugin的说明,首先需要编译出BG Process这个东东。

下载源码 svn co http://svn.tribler.org/abc/branches/mainbranch/,将源码放到你自己指定路径后执行
C:\Python27>python.exe Tribler\Plugin\Build\Win32\setupBGexe.py py2exe
Traceback (most recent call last):
  File "Tribler\Plugin\Build\Win32\setupBGexe.py", line 8, in <module>
    import py2exe # Not a superfluous import!
ImportError: No module named py2exe
提示缺少py2exe模块,从SourceForge上下载py2exe-0.6.9.win32-py2.7.exe并安装到默认路径C:\Python27\Lib\site-packages\
=======================================     
This package is a distutils extension to build
standalone Windows executable programs from
Python scripts.

    Author: Thomas Heller
    Author_email: theller@python.net
    Description: Build standalone executables for Windows
    Maintainer: Jimmy Retzlaff
    Maintainer_email: jimmy@retzlaff.com
    Name: py2exe
    Url: http://www.py2exe.org/
    Version: 0.6.9
=======================================    
重新执行得到 
C:\Python27>python.exe Tribler\Plugin\Build\Win32\setupBGexe.py py2exe
running py2exe
creating C:\Python27\build
creating C:\Python27\build\bdist.win32
creating C:\Python27\build\bdist.win32\winexe
creating C:\Python27\build\bdist.win32\winexe\collect-2.7
creating C:\Python27\build\bdist.win32\winexe\bundle-2.7
creating C:\Python27\build\bdist.win32\winexe\temp
creating C:\Python27\dist
*** searching for required modules ***
C:\Python27\Tribler\Player\swarmplayer.py:451: SyntaxWarning: name 'START_TIME' is assigned to before global declaration
  global START_TIME
*** parsing results ***
creating python loader for extension 'vlc' (C:\Python27\vlc.pyd -> vlc.pyd)
creating python loader for extension 'unicodedata' (C:\Python27\DLLs\unicodedata.pyd -> unicodedata.pyd)
creating python loader for extension 'win32pdh' (C:\Python27\lib\site-packages\win32\win32pdh.pyd -> win32pdh.pyd)
creating python loader for extension '_ctypes' (C:\Python27\DLLs\_ctypes.pyd -> _ctypes.pyd)
creating python loader for extension 'select' (C:\Python27\DLLs\select.pyd -> select.pyd)
creating python loader for extension 'win32event' (C:\Python27\lib\site-packages\win32\win32event.pyd -> win32event.pyd)
creating python loader for extension 'wx._controls_' (C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_controls_.pyd -> wx._co
ntrols_.pyd)
creating python loader for extension 'apsw' (C:\Python27\lib\site-packages\apsw.pyd -> apsw.pyd)
creating python loader for extension 'win32evtlog' (C:\Python27\lib\site-packages\win32\win32evtlog.pyd -> win32evtlog.pyd)
creating python loader for extension 'win32file' (C:\Python27\lib\site-packages\win32\win32file.pyd -> win32file.pyd)
creating python loader for extension 'wx._windows_' (C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_windows_.pyd -> wx._wind
ows_.pyd)
creating python loader for extension '_hashlib' (C:\Python27\DLLs\_hashlib.pyd -> _hashlib.pyd)
creating python loader for extension 'bz2' (C:\Python27\DLLs\bz2.pyd -> bz2.pyd)
creating python loader for extension '_ssl' (C:\Python27\DLLs\_ssl.pyd -> _ssl.pyd)
creating python loader for extension '_sqlite3' (C:\Python27\DLLs\_sqlite3.pyd -> _sqlite3.pyd)
creating python loader for extension 'wx._core_' (C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core_.pyd -> wx._core_.pyd)

creating python loader for extension 'wx._misc_' (C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_misc_.pyd -> wx._misc_.pyd)

creating python loader for extension 'wx._xrc' (C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_xrc.pyd -> wx._xrc.pyd)
creating python loader for extension 'M2Crypto.__m2crypto' (C:\Python27\lib\site-packages\M2Crypto\__m2crypto.pyd -> M2Crypto.__m2
crypto.pyd)
creating python loader for extension '_win32sysloader' (C:\Python27\lib\site-packages\win32\_win32sysloader.pyd -> _win32sysloader
.pyd)
creating python loader for extension 'wx._gdi_' (C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_gdi_.pyd -> wx._gdi_.pyd)
creating python loader for extension 'pyexpat' (C:\Python27\DLLs\pyexpat.pyd -> pyexpat.pyd)
creating python loader for extension 'win32ui' (C:\Python27\lib\site-packages\Pythonwin\win32ui.pyd -> win32ui.pyd)
creating python loader for extension 'win32api' (C:\Python27\lib\site-packages\win32\win32api.pyd -> win32api.pyd)
creating python loader for extension '_socket' (C:\Python27\DLLs\_socket.pyd -> _socket.pyd)
*** finding dlls needed ***
error: python25.dll: No such file or directory
本人装的python版本为2.7.3,这里报没有找到python25.dll,奇怪,没办法,只好分析源码。
先查看setupBGexe.py,没有发现特别的东西
import os

from distutils.core import setup
import py2exe # Not a superfluous import!

from Tribler.__init__ import LIBRARYNAME
mainfile = os.path.join(LIBRARYNAME,'Plugin','SwarmEngine.py')

# Arno: 2009-06-09: changed from console= to make sure py2exe writes
# a BackgroundProcess.exe.log
#
setup(windows=[mainfile])
再查看py2exe包的__init__.py文件 
# py2exe/__init__.py

# 'import py2exe' imports this package, and two magic things happen:
#
# - the 'py2exe.build_exe' submodule is imported and installed as
#   'distutils.commands.py2exe' command
#
# - the default distutils Distribution class is replaced by the
# special one contained in this module.
#
__version__ = "0.6.9"
import distutils.dist, distutils.core, distutils.command, build_exe, sys

class Distribution(distutils.dist.Distribution):
    def __init__(self, attrs):
        self.ctypes_com_server = attrs.pop("ctypes_com_server", [])
        self.com_server = attrs.pop("com_server", [])
        self.service = attrs.pop("service", [])
        self.windows = attrs.pop("windows", [])
        self.console = attrs.pop("console", [])
        self.isapi = attrs.pop("isapi", [])
        self.zipfile = attrs.pop("zipfile", "library.zip")
        distutils.dist.Distribution.__init__(self, attrs)

distutils.core.Distribution = Distribution
distutils.command.__all__.append('py2exe')

sys.modules['distutils.command.py2exe'] = build_exe
由注释可以看出,该文件干了两件事,其中导入build_exe作为py2exe是和我相关的,于是查看build_exe文件。在该文件中能够找到上面出错的最后一行打印的对应代码 print "*** finding dlls needed ***"。

由经验知道 error: python25.dll: No such file or directory 意思是打开文件的时候出错,要么是文件路径不对,要么是文件名不对,总之未找到对应文件,搜索python27.dll,发现其位于C:\WINDOWS\system32下面,确实没有python25.dll的影子(其实不搜索也应该猜得到,毕竟我没装过python2.5嘛)

两种解决办法:
a) 下载python25.dll,放置到和python27.dll相同的目录下
b) 对build_exe.py进行修改

下载python25.dll的方法可以参考百度百科说明 http://baike.baidu.com/view/6590620.htm
这里说明下如何对build_exe.py进行修改,和这个问题有关的代码如下 
......
def bin_depends(path, images, excluded_dlls):
    import py2exe_util
    warnings = FileSet()
    images = FileSet(images)
    dependents = FileSet()
    others = FileSet()
    while images:
        for image in images.copy():
            images.remove(image)
            if not image in dependents:
                dependents.add(image)
                abs_image = os.path.abspath(image)
                loadpath = os.path.dirname(abs_image) + ';' + path
                for result in py2exe_util.depends(image, loadpath).items():
                    dll, uses_import_module = result
                    if os.path.basename(dll).lower() not in excluded_dlls:
                        if isSystemDLL(dll):
                            others.add(dll)
                            continue
                        if dll not in images and dll not in dependents:
                            images.add(dll)
                            if uses_import_module:
                                warnings.add(dll)
    return dependents, warnings, others


# DLLs to be excluded
# XXX This list is NOT complete (it cannot be)
# Note: ALL ENTRIES MUST BE IN LOWER CASE!
EXCLUDED_DLLS = (
    "advapi32.dll",
    "comctl32.dll",
    "comdlg32.dll",
    "crtdll.dll",
    "gdi32.dll",
    "glu32.dll",
    "opengl32.dll",
    "imm32.dll",
    "kernel32.dll",
    "mfc42.dll",
    "msvcirt.dll",
    "msvcrt.dll",
    "msvcrtd.dll",
    "ntdll.dll",
    "odbc32.dll",
    "ole32.dll",
    "oleaut32.dll",
    "rpcrt4.dll",
    "shell32.dll",
    "shlwapi.dll",
    "user32.dll",
    "version.dll",
    "winmm.dll",
    "winspool.drv",
    "ws2_32.dll",
    "ws2help.dll",
    "wsock32.dll",
    "netapi32.dll",

    "gdiplus.dll",
    )


# XXX Perhaps it would be better to assume dlls from the systemdir are system dlls,
# and make some exceptions for known dlls, like msvcr71, pythonXY.dll, and so on?
def isSystemDLL(pathname):
    if os.path.basename(pathname).lower() in ("msvcr71.dll", "msvcr71d.dll"):
        return 0
    if os.path.basename(pathname).lower() in EXCLUDED_DLLS:
        return 1
    # How can we determine whether a dll is a 'SYSTEM DLL'?
    # Is it sufficient to use the Image Load Address?
    import struct
    file = open(pathname, "rb")
    if file.read(2) != "MZ":
        raise Exception, "Seems not to be an exe-file"
    file.seek(0x3C)
    pe_ofs = struct.unpack("i", file.read(4))[0]
    file.seek(pe_ofs)
    if file.read(4) != "PE\000\000":
        raise Exception, ("Seems not to be an exe-file", pathname)
    file.read(20 + 28) # COFF File Header, offset of ImageBase in Optional Header
    imagebase = struct.unpack("I", file.read(4))[0]
    return not (imagebase < 0x70000000)

......
      分析后可知,错误打印 error: python25.dll: No such file or directory 应该是代码 file = open(pathname, "rb") 产生的,从函数isSystemDLL()的注释可以看出,应该对一些特别版本的dll进行排除,那么可以做如下修改: 
if os.path.basename(pathname).lower() in ("msvcr71.dll", "msvcr71d.dll"):
改为
if os.path.basename(pathname).lower() in ("msvcr71.dll", "msvcr71d.dll", "python25.dll"):
此时执行结果为
C:\Python27>python.exe Tribler\Plugin\Build\Win32\setupBGexe.py py2exe
running py2exe
*** searching for required modules ***
C:\Python27\Tribler\Player\swarmplayer.py:451: SyntaxWarning: name 'START_TIME' is assigned to before global declaration
  global START_TIME
*** parsing results ***
......
......
*** finding dlls needed ***
Traceback (most recent call last):
  File "Tribler\Plugin\Build\Win32\setupBGexe.py", line 16, in <module>
    setup(windows=[mainfile])
  File "C:\Python27\lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 243, in run
    self._run()
  File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 305, in _run
    dlls = self.find_dlls(extensions)
  File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 389, in find_dlls
    self.dll_excludes)
  File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 1064, in find_dependend_dlls
    bin_depends(loadpath, images + [sys.executable], excludes_use)
  File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 1438, in bin_depends
    for result in py2exe_util.depends(image, loadpath).items():
py2exe_util.bind_error: (2, '', 'python25.dll')
呵呵,貌似不行,并且只有py2exe_util.pyd文件,没有源文件,无法进一步知道不行的原因,故换另外一种方法:在EXCLUDED_DLLS增加"python25.dll",执行结果如下
C:\Python27>python.exe Tribler\Plugin\Build\Win32\setupBGexe.py py2exe
running py2exe
*** searching for required modules ***
C:\Python27\Tribler\Player\swarmplayer.py:451: SyntaxWarning: name 'START_TIME' is assigned to before global declaration
  global START_TIME
*** parsing results ***
......
*** finding dlls needed ***
error: MSVCP90.dll: No such file or directory
解说说明错误说明找不到 python25.dll的问题已经没有了,但是 需要库MSVCP90.dll。该库是Microsoft C++ Runtime Library,是使用Microsoft Visual Studio 2008编译出的程序默认依赖的库文件。按道理我电脑已经安装了VS2008,该库应该是存在的,但是现在的情况是其确实不在C:\WINDOWS\system32目录下面(和其他系统路径下),故搜索出我电脑上该文件并拷贝到C:\WINDOWS\system32下面,执行程序,终于得到了正确的结果,如下
C:\Python27>python.exe Tribler\Plugin\Build\Win32\setupBGexe.py py2exe
running py2exe
*** searching for required modules ***
C:\Python27\Tribler\Player\swarmplayer.py:451: SyntaxWarning: name 'START_TIME' is assigned to before global declaration
  global START_TIME
*** parsing results ***
......
*** finding dlls needed ***
*** create binaries ***
*** byte compile python files ***
......
skipping byte-compilation of ......
skipping byte-compilation of C:\Python27\Tribler\vlc.py to Tribler\vlc.pyc
byte-compiling C:\Python27\build\bdist.win32\winexe\temp\M2Crypto.__m2crypto.py to M2Crypto\__m2crypto.pyc
byte-compiling ......
......
skipping byte-compilation of C:\Python27\lib\zipfile.py to zipfile.pyc
*** copy extensions ***
*** copy dlls ***
copying C:\Python27\lib\site-packages\py2exe\run_w.exe -> C:\Python27\dist\SwarmEngine.exe
The following modules appear to be missing
['ElementC14N', 'Tribler.Core.BuddyCast.buddycast', '_curses', '_scproxy', 'core.bootstrap', 'core.identifier', 'core.message', 'c
ore.node', 'core.ptime', 'core.routing_table', 'meliae', 'netifaces', 'prctl', 'psyco', 'simplejson', 'test_const', 'vlc.lib.vlc',
 'win32com.shell']

*** binary dependencies ***
Your executable(s) also depend on these dlls which are not included,
you may or may not need to distribute them.

Make sure you have the license if you distribute any of them, and
make sure you don't distribute files belonging to the operating system.

   ole32.dll - C:\WINDOWS\system32\ole32.dll
   OLEAUT32.dll - C:\WINDOWS\system32\OLEAUT32.dll
   USER32.dll - C:\WINDOWS\system32\USER32.dll
   python25.dll - python25.dll
   SHELL32.dll - C:\WINDOWS\system32\SHELL32.dll
   MSWSOCK.dll - C:\WINDOWS\system32\MSWSOCK.dll
   WINMM.dll - C:\WINDOWS\system32\WINMM.dll
   WSOCK32.dll - C:\WINDOWS\system32\WSOCK32.dll
   COMDLG32.dll - C:\WINDOWS\system32\COMDLG32.dll
   ADVAPI32.dll - C:\WINDOWS\system32\ADVAPI32.dll
   mfc90.dll - C:\Python27\lib\site-packages\Pythonwin\mfc90.dll
   msvcrt.dll - C:\WINDOWS\system32\msvcrt.dll
   WS2_32.dll - C:\WINDOWS\system32\WS2_32.dll
   WINSPOOL.DRV - C:\WINDOWS\system32\WINSPOOL.DRV
   GDI32.dll - C:\WINDOWS\system32\GDI32.dll
   gdiplus.dll - C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\gdiplus.dll
   VERSION.dll - C:\WINDOWS\system32\VERSION.dll
   KERNEL32.dll - C:\WINDOWS\system32\KERNEL32.dll
   COMCTL32.dll - C:\WINDOWS\system32\COMCTL32.dll
   RPCRT4.dll - C:\WINDOWS\system32\RPCRT4.dll
   MSVCP90.dll - C:\WINDOWS\system32\MSVCP90.dll
此时已经编译出了SwarmEngine.exe位于C:\Python27\dist目录下,但是双击执行时,仍旧不能正常安装,错误日志查看SwarmEngine.exe.log解决,本文不再说明。


© 著作权归作者所有

共有 人打赏支持
摩云飞
粉丝 368
博文 534
码字总数 952694
作品 0
徐汇
程序员
私信 提问
加载中

评论(2)

孟凡陆
孟凡陆

引用来自“Mr.6”的评论

good job

what?
扁豆焖面先生
扁豆焖面先生
good job
【原创】研究Tribler过程中遇到的Python相关问题总结

【如何导入包】 两点搞定,就可以import了: package的当前目录下要有init.py文件,表示它自己是个package package的parent目录要在PYTHONPATH中 【打开文件的路径和导入模块的路径】 打开文件...

摩云飞
2012/10/23
0
1
ImageMagick更改图片格式进而缩小图片

在实例的生产环境中有时候我们的网站会用到比较小的图片,但是提供的图片相对来说比较大。像我之前文章中,我做了ImageMagick的安装和简单的使用实例,但是处理1M左右大小的图片最后还回有2...

断臂人
2017/04/22
0
0
Android中关于cpu/cpuset/schedtune的应用

Android中关于cpu/cpuset/schedtune的应用都是基于进程优先级的,根据不同优先级划分进程类型。AMS(ActivityManagerService)和PMS(PackageManagerService)等通过class Process设置进程优先级...

fybon
07/12
0
0
学习动态性能表 第七篇--V$PROCESS

学习动态性能表 第七篇--V$PROCESS   本视图包含当前系统oracle运行的所有进程信息。常被用于将oracle或服务进程的操作系统进程ID与数据库session之间建立联系。在某些情况下非常有用: 1....

jimbuster
2008/03/30
0
0
linux中bg、fg、ctrl+z、ctrl+d和ctrl+c的区别

fg、bg、jobs、&、ctrl + z都是跟系统任务有关的,虽然现在基本上不怎么需要用到这些命令,但学会了也是很实用的 一。& 最经常被用到 这个用在一个命令的最后,可以把这个命令放到后台执行 ...

sandshell
07/12
0
0

没有更多内容

加载失败,请刷新页面

加载更多

如何在Chrome浏览器中启动deviceready事件(尝试调试phonegap项目)?

我正在开发PhoneGap应用程序,我希望能够在Chrome中调试它,而不是在电话上调试。但是,我在onGetReady()函数中初始化我的代码,该函数在PhoneGap触发“deviceready”事件时触发。由于Chr...

kisshua
21分钟前
1
0
支付宝客户端架构分析:自动化日志收集及分析

摘要: 《支付宝客户端架构解析》系列将从支付宝客户端的架构设计方案入手,带领大家进一步了解支付宝在客户端架构上的迭代与优化历程。 小蚂蚁说: 《支付宝客户端架构解析》系列将从支付宝...

阿里云官方博客
24分钟前
1
0
nginx中部署vue打包后的静态文件

如何在nginx中部署静态资源就不描述了, 请看我的这篇博客 将vue脚手架项目打包后的静态文件放到nginx上, 发现有个问题, 即url上有#, 怎么去掉这个#呢. 1 项目中router的mode 路由的mode要为h...

克虏伯
42分钟前
7
0
JS容易理解错误的地方

在这端代码执行的末尾,你会不会hi变量回事函数中的hi了?你会不会认为这不是按引用传递了? 对值传递和引用传递产生质疑了? 1 var hi = {};2 function sayHello(hi) { ...

器石_
43分钟前
4
0
Java开发学习--MongoDB

之前只学过sql,第一次使用非关系型数据库。以前对于关系型数据库与非关系型数据库的概念很模糊,通过这次的学习对这两者有了一个清晰的概念。 主键 在MongoDB中,主键名叫"_id",如果在生成...

微笑向暖wx
47分钟前
4
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部