I want to make an executable file (.exe) of my Python application.
I want to know how to do it but have this in mind: I use a C++ DLL!
Do I have to pu开发者_C百科t the DLL along side with the .exe or is there some other way?
py2exe can generate single file executables. see this link for examples.
The setup.py I use uses the following combination of options:
'compressed': 1,
'optimize':2,
'bundle_files': 1
I usually add external dlls (p.e. msvcr71.dll) in the same folder where the executable is.
To facilitate distribution and to automate installation after generating your exe you can use Inno Setup to create an installer that puts your exe and your dlls, and other documents (readme, etc) into the application directory
Follow These Steps: You can find this documentation in this site.
1) Install PyInstaller:
Assuming you have PIP installed in this directory c:\PythonXX\Scripts if not go to this site and see instructions on how to "Install Python Indexing Project (PIP)". Go to your command prompt and type the following command.
- cd c:\Python27\Scripts to go to this directory press Enter
- Then type -> pip install pyinstaller press Enter again
- This should install PyInstaller successfully!
- Obs: You don't need to have pyinstaller inside the Scripts folder after installation this was done because we needed PIP to install the pyinstaller files. To make things more organized I usually move the pyinstaller files to another folder. To move the pysintaller files go to the Scripts folder where the pyinstaller files are located and look for all the files that start with "pyi" you can also look at the Modified Date column to see which files where created at the same time. It should be 24 pyi files that where created when you ran the script above. Copy those files into another folder of your choice I usually create a folder within the C:\ drive and call it "CreateExecutables" with another folder within called "pyinstaller_files".
2) Install PyWin32:
Go to this SITE and look for the executable named pywin32-218.win32-py2.7.exe 2.7 which is for 32 bit systems for python27 look for the one that corresponds to you. Run the executable file and it should install PyWin32 successfully which works hand in hand with pyinstaller!
3) Create Single Executable file
Now that you have PyInstaller and PyWin32 you can start to create the single executable file. The single executable file will be created inside another folder called “dist” this folder is also created dynamically when you run the pyinstaller command. To make things clear your pyinstaller files where copied by you to another folder probably called "pyinstaller_files" folder so now type the following command in your command prompt.
- c:\python27\CreateExecutables\pyinstaller_files>pyinstaller --onefile c:\test\test1\yourscript.py
- Obs: The directory of yourscript.py is where you have your pydev module located.
4) Overview
The above command will create a folder called “dist” inside the pyinstaller_files folder this folder will contain your single executable file “yourscript.exe”. You can now move the single executable file somewhere of your choice and delete the “dist” & “build” folder with the “yourscript.spec” file as they are no longer needed to run your single executable file.
Use py2exe. You can put the DLL in the same folder as the final EXE and it should be loaded fine.
Have a look at pyinstaller. It should find (and correspondingly ship) these dependencies for you.
I've built exe files from Python 2.7 code using each of these tools:
- Cython (with --embed option)
- Nuitka
- Py2exe
These all will produce a standalone exe. Your installer will have to include the requisite CRT dlls. Your end result will be indistinguishable from any other exe to the typical user.
The first two compile to C first, then compile that to a final exe using whatever compiler you have installed. Py2Exe bundles Python and all your .pyo files into a zip which it embeds in the exe. When launched it unzips to the temp directory and runs the python from there. You'll need to add your dll to the .spec file so it is included in the zip resource. Alternatively, install your dll alongside the exe and load it using an absolute path in python.
cx_Freeze is a good one as well.
cx_Freeze is a set of scripts and modules for freezing Python scripts into executables
PyInstaller is the best choice, because it works well on both Windows and Linux.
If you are using arch linux, use this link: PyInstaller or try yaourt pyinstaller
.
精彩评论