简体   繁体   中英

Using third-party library in py2exe single EXE file

I'm making some script files in Python 2.7.9 and additionally use a third-party library, pyautoit 0.4 .

I would like to make my scripts as a single EXE (want to run in single file so they don't need to setup files) and by using py2exe , tried this:

# -*- coding: utf-8 -*-
from setuptools import setup
import py2exe, sys, os
setup(name = "My Test Application",
      description = "My Test Application for Windows",
      version = "1.01",
      console = [{"script": "myprogram.py"}],
      #data_files - make directory at ./dist, not in exe file
      #data_files=[("./autoit/lib", ["AutoItX3.dll"])],
      options = {
          "py2exe": {
               "includes": ["win32api",,
                            "autoit",
                            "os" ,
                            "time"],
              "bundle_files": 1,
          }
    },
    zipfile = None,
)

It has been successfully packed in a single EXE file, but there is no AutoItX3.dll file in the EXE.

I found that py2exe cannot include .dll file in its EXE file, so in my main script I tried importing AutoItX3.dll manually:

# -*- coding: utf-8 -*-
import os, sys
from ctypes import cdll
autoitdll = cdll.LoadLibrary('./modules/AutoItX3.dll')
autoitdll.run("wordpad.exe")

and it can't be loaded. (err msg :

Traceback (most recent call last): File "C:/Users/win7x64kor/PycharmProjects/treesearch_27/myprogram.py", line 26, in autoitdll.run("wordpad.exe")

File "C:\\Python27\\lib\\ctypes__init__.py", line 378, in getattr func = self. getitem (name)

File "C:\\Python27\\lib\\ctypes__init__.py", line 383, in getitem func = self._FuncPtr((name_or_ordinal, self))

AttributeError: function 'run' not found

Is there any method for loading libraries including .dll files?

Or an easier way to just include 'pyautoit' library feature by adding some options like in py2exe "options > includes : "autoit" " a single EXE files?

If you don't need to pass command line arguments to your exe you can try the steps suggested at http://www.py2exe.org/index.cgi/SingleFileExecutable

The basic idea is to bundle your exe with the required dll's etc using NSIS (Nullsoft Install System). When your exe is run, it will unpack everything into the temporary folder and execute. When it closes, the temporary files are deleted automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM