简体   繁体   中英

Compile a Python project Windows

I have the following directory structure to my python project:

eplusplus/
    |
    |
    ----__main__.py
    ----model/
    ----exception/
    ----controller/
    ----view/

The directories: model, exception, controller and view each one has its __init__.py . When I run the program at my machine I always use this following command: py -m eplusplus . But when I tried to use py2exe or pytinstaller the the points to: permission denied . For what I found, this is because its a directory I trying to compile, but when I compiled the __main__.py it compiled normally, but when I try to execute it says: Error! No eplusplus module founded! Error! No eplusplus module founded!

I have no setup.py file and I don't know how they worked.

After some very intensive research and error and try I succeeded by doing this:

  • I added an empty __init__.py at the eplusplus folder

  • Out of the eplusplus folder, I had to write a compilation.py file (the file doesn't necessary must have this) to include all libraries I was using (I will post the file at the end of this answer)

  • Finally, at the PowerShell, all I have to type was py compilation.py py2exe

Thanks for all that tried to help me!

compilation.py file:

#To compile we need to run: python compilation.py py2exe
from distutils.core import setup
from glob import glob
import os
import py2exe
import pyDOE

VERSION=1.0

includes = [
    "sip",
    "PyQt5",
    "PyQt5.QtCore",
    "PyQt5.QtGui",
    "PyQt5.QtWidgets",
    "scipy.linalg.cython_blas",
    "scipy.linalg.cython_lapack",
    "pyDOE"
]

platforms = ["C:\\Python34\\Lib\\site-packages\\PyQt5\\plugins" +
             "\\platforms\\qwindows.dll"]

dll = ["C:\\windows\\syswow64\\MSVCP100.dll",
       "C:\\windows\\syswow64\\MSVCR100.dll"]

media = ["C:\\Users\\GUSTAVO\\EPlusPlus\\media\\title.png",
         "C:\\Users\\GUSTAVO\\EPlusPlus\\media\\icon.png"]

documents = ["C:\\Users\\GUSTAVO\\EPlusPlus\\docs\\"+
             "documentacaoEPlusPlus.pdf"]

examples = ["C:\\Users\\GUSTAVO\\EPlusPlus\\files\\"+
            "\\examples\\baseline2A.idf",
            "C:\\Users\\GUSTAVO\\EPlusPlus\\files\\"+
            "\\examples\\vectors.csv",
            "C:\\Users\\GUSTAVO\\EPlusPlus\\files\\"+
            "\\examples\\BRA_SC_Florianopolis.838970_INMET.epw"]

datafiles = [("platforms", platforms),
         ("", dll),
         ("media", media),
         ("docs", documents),
         ("Examples", examples)]

imageformats = glob("C:\\Python34\\Lib\\site-packages\\PyQt5\\"+
        "plugins\\imageformats\\*")

datafiles.append(("imageformats", imageformats))

setup(
    name="eplusplus",
    version=VERSION,
    packages=["eplusplus"],
    url="",
    license="",
    windows=[{"script": "eplusplus/__main__.py"}],
    scripts=[],
    data_files = datafiles,
    options={
        "py2exe": {
            "includes": includes,
        }
    }
)

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