How can I configure setup.py
to install scripts with a .py
prefix on Windows platforms but without the prefix on all others? The problem I'm trying to solve is that Windows requires a .py
extension to recognize and execute Python scripts.
I have a package set up like the following:
MyPackage
├── CHANGES
├── ...
├── scripts
│ └── myprogram
├── setup.py
└── mypackage
├── __init__.py
├── ...
└── myprogram.py
In my setup.py file I declare scripts/myprogram
as an installable script with
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from setuptools import setup
...
setup(
name='MyPackage',
...
packages=['mypackage'],
scripts=['scripts/myprogram'],
...
)
The myprogram
script is just a thin wrapper that simply calls mypackage.myprogram.main()
:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from mypackage import myprogram
myprogram.main()
On *nix platforms, this installs myprogram
as an executable by the name of myprogram
, which is what I desire, but on Windows, it also installs as myprogram
in the C:\PythonXX\Scripts
directory, and is thus not recognized on the command line. How can I get the setup script to install myprogram
as myprogram.py
on Windows, so that Windows recognizes the file type to make it executable?