pack a software in Python using py2exe with 'l

2020-05-25 17:58发布

问题:

I have Python 2.7 on Window 7 OS. I wish to pack my project.py in an Executable using py2exe. Following the instruction i wrote a setup.py file

from distutils.core import setup
import py2exe

setup(console=["project.py"])  

and I got this message

i tried to exclude 'libiomp5md.dll'

from distutils.core import setup
import py2exe

setup(console=["SegmentationAccuracy.py"])

dll_excludes = ['libiomp5md.dll']

but always i got the same error message "error: libiomo5md.dll: No such file or directory"

my executable contains:

import math
import os
import numpy as np
import sys
import ogr
from progressbar import ProgressBar
from shapely.geometry import Polygon
nan = np.nan

回答1:

I had the same problem, but calling import numpy within setup.py resolved the issue



回答2:

libiomp5md.dll is from the Intel C compiler, and is used for OpenMP multiprocessing operations. I expect that your code involves numpy or code compiled with the Intel compiler, and so your py2exe build depends on it.

You can't simply create a build without it, so I would suggest finding it on your system and copying it to the directory where you run python setup.py py2exe . Hint, I have a copy in C:\Python27\Lib\site-packages\numpy\core

[If you really want to exclude it you will have to compile numpy manually with Visual Studio or Msys.]

Once you have libiomp5md.dll in the directory that you're executing python setup.py py2exe then you only need to remove the exclude_dll line (as you don't want to be excluding it...)

from distutils.core import setup
import py2exe

setup(console=["SegmentationAccuracy.py"])


回答3:

I had the same problem. I had to install numpy on a machine, did it with mingw gcc compiler. I confirmed: copy of dll found in C:\Python27\Lib\site-packages\numpy\core\

I just copied it to the working directory before launching setup.

Nothing special to tune in setup.py, dependencies are automatically found.



回答4:

OK, I had the same problem. It turned out that a .pyd file in sklearn was referencing libiomp5md.dll. Py2exe looks in two places for your DLL - on the path environment variable and in the same directory that the .pyd file is in. libiomp5md.dll is in neither. Py2exe pretty much gives up and instead of giving a full path name such as c:\Python27\lib\site-packages\numpy\core\libiomp5md.dll, it says "libiomp5md.dll" which, later on, it can't find.

I'm impatient. I added a line within my setup file:

os.environ["PATH"] += os.pathsep + os.path.dirname(numpy.core.file)

and that's where libiomp5md.dll is. Now everything works. Just make sure you do this in your code prior to calling setup and it will for you too.