Reputation: 2375
main.py:
print('test')
I can build using this command:
python setup.py build_ext --inplace --compiler=msvc
This will create *.pyd files and put them to needed folders in my package.
But my main.py is compiled as main.pyd.
Extension(
'main',
sources=['main.c','main.py'],
include_dirs=[np.get_include()],
)
Tried this:
cl.exe /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\P\Python27-32\include /Tcmain.c /link /OUT:"main.exe" /SUBSYSTEM:WINDOWS /MACHINE:X86 /LIBPATH:C:\P\Python27-32\libs
But it fails:
main.c Creating library main.lib and object main.exp MSVCRT.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup main.exe : fatal error LNK1120: 1 unresolved externals
Is there a way to build it as Windows executable main.exe using Cython?
Upvotes: 0
Views: 1307
Reputation: 2375
I figured it.
setup.py has to expose entry_point:
entry_points={
'console_scripts': [
'mypackage-cli=mypackage.command_line:main',
],
},
command_line.py:
from . import cli
def main():
print cli()
__init__.py:
from markdown import markdown
def cli():
return markdown(u'It''s a CLI!')
after python setup.py develop
it creates executable file mypackage-cli.exe
with 'shim' script mypackage-cli-script.py
in %PYTHONPATH%\Scripts
c:\tmp\mypackage>C:\Python27-32\Scripts\mypackage-cli.exe
<p>It's a CLI!</p>
It requires Python distribution to be at C:\Python27-32
I posted demo here: github:mycyexepackage
Upvotes: 2
Reputation: 313
Try use PyInstaller
pip install pyinstaller
From my experience this framework works allways
And download Cython bundling if it necessary : https://github.com/prologic/pyinstaller-cython-bundling
Upvotes: 2