4 ms·
Has anyone gotten this to work on Windows? I wanted to use this trick for some tooling for a game mod I'm working on but couldn't get the shebang trick to work.
by dharmab 2y ago
Has anyone gotten this to work on Windows? I wanted to use this trick for some tooling for a game mod I'm working on but couldn't get the shebang trick to work.
- seabrookmx 2y agoI haven't done dev on windows in many years, but IIRC windows doesn't have shebang support.
- deleted 2y ago[deleted]
- magicalhippo 2y agoBut it does support registering extension handlers[1], so if you name your scripts with say .pyuv and register "uv run --script %1", or whatever it would take to run uv, as the handler of .pyuv files, it should work. Unless uv does something funky that is. You could do this during an installation step, for example. [1]: https://learn.microsoft.com/en-us/windows/win32/shell/fa-file-types https://learn.microsoft.com/en-us/windows/win32/shell/fa-fil...
- _mlbt 2y agoYou could always use something like PyInstaller... https://pyinstaller.org https://pyinstaller.org
- quickslowdown 2y agoI use this frequently on Windows and Linux. These are the steps I take: $> uv init --script <script_name>.py $> uv add --script <script_name>.py <pkg1> <pkg2> ... $> uv add --script <script_name>.py --dev <dev_pkg1> <dev_pkg2> ... $> uv run <script_name>.py Hope this helps :) Source: https://docs.astral.sh/uv/guides/scripts/ https://docs.astral.sh/uv/guides/scripts/
- networked 2y agoUnfortunately, `uv add --dev` doesn't work with `--script`: > uv -V uv 0.6.10 > uv add --script foo.py --dev ruff error: the argument '--script <SCRIPT>' cannot be used with '--dev' Usage: uv add --script <SCRIPT> --link-mode <LINK_MODE> <PACKAGES|--requirements <REQUIREMENTS>> For more information, try '--help'. There is currently no mention of `uv add --script foo.py --dev ...` in https://docs.astral.sh/uv/guides/scripts/ https://docs.astral.sh/uv/guides/scripts/. Inline script metadata in Python doesn't standardize development dependencies. I wrote a recent comment about how I develop scripts with `pyproject.toml` to have a regular development environment: https://news.ycombinator.com/item?id=43503171 https://news.ycombinator.com/item?id=43503171.
- quickslowdown 2y agoInteresting about the --deb flag not working with scripts. I wrote this from memory and feel like I've installed dev dependencies for a script, but it must be a hallucination because I just tried and it doesn't work. Thanks for the correction.
- mixmastamyk 2y agoAside: angle brackets should be avoided in shell examples; one mistaken enter and work can be destroyed.
- sorenjan 2y agoThe regular CPython installer on Windows installs the py launcher and associates it with .py files. The py launcher supports shebang lines. This was covered in a blog post about this same topic that was posted here a few days ago. According to that you have to omit the -S: https://thisdavej.com/share-python-scripts-like-a-pro-uv-and-pep-723-for-easy-deployment/ https://thisdavej.com/share-python-scripts-like-a-pro-uv-and... https://news.ycombinator.com/item?id=43500124 https://news.ycombinator.com/item?id=43500124 I haven't tried it myself, I simply changed the file association so all .py files are opened with uv run as standard. https://docs.python.org/3/using/windows.html#python-launcher-for-windows https://docs.python.org/3/using/windows.html#python-launcher... https://peps.python.org/pep-0397/ https://peps.python.org/pep-0397/
- dharmab 2y agoInteresting. The workflow I've been using skips the CPython installer and only uses uv.
- sorenjan 2y agoWindows doesn't support shebang lines as you probably know, but if you associate uv with .py files you'll get the same result. I think it should be something like this: ftype Python.File=C:\Path\to\uv.exe run %L %* If you don't use the CPython installer the Python.File file type might not be defined, so you might need to set that with `assoc` first: assoc .py=Python.File
- skeledrew 2y agoShebang should work fine from WSL.
- gus_massa 2y agoI'm not sure it's useful, but someone posted how to do a similar thing for Racket with PoweScript https://onor.io/2025/01/more-scripting-with-racket.html https://onor.io/2025/01/more-scripting-with-racket.html