This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Windows-style path is not recognized under cygwin
Type: behavior Stage:
Components: Windows Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, eryksun, lazka, mikekaganski, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2022-02-14 18:42 by mikekaganski, last changed 2022-04-11 14:59 by admin.

Messages (8)
msg413247 - (view) Author: Mike Kaganski (mikekaganski) Date: 2022-02-14 18:42
Using cyqwin 3.3.4-2, and python3:

Python 3.9.10 (main, Jan 20 2022, 21:37:52)
[GCC 11.2.0] on cygwin

Trying this bash command line:

> python3 C:/path/to/script.py

results in this error:

"python3: can't open file '/cygdrive/c/path/to/curdir/C:/path/to/script.py': [Errno 2] No such file or directory"

OTOH, calling it like

> python3 /cygdrive/c/path/to/script.py

gives the expected output:

"usage: script.py [-h] ..."

It seems that python3 doesn't recognize "C:/path/to/script.py" to be a proper full path under cygwin, while most other cygwin apps handle those fine. E.g.,

> nano C:/path/to/script.py

opens the script for editing without problems.

The mentioned path syntax is useful and supported under cygwin, so it would be nice if python3 could support it, too. Especially useful it is in mixed development environment, mixing Windows native tools and cygwin ones; using such path style allows to use same paths for both kinds of tools, simplifying scripts.
msg413250 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-02-14 19:00
Are you running from bash (or another cygwin shell), or from cmd.exe, or something else?

How did you install the version of python you're executing in the examples you provided? To my knowledge, cygwin's installer doesn't have a 3.9 available.

I don't see this behavior on cygwin's python3.8, either from cmd.exe or from zsh.
msg413256 - (view) Author: Mike Kaganski (mikekaganski) Date: 2022-02-14 20:04
Thanks for looking at this!

> Are you running from bash (or another cygwin shell), or from cmd.exe, or something else?

:) Citing myself:

> Trying this *bash* command line:

> To my knowledge, cygwin's installer doesn't have a 3.9 available.

It does: https://cygwin.com/packages/summary/python3.html
msg413259 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-02-14 20:24
>:) Citing myself:

>> Trying this *bash* command line:

Oops, sorry for missing that.

As for 3.9: it's not available through the 64 bit installer (at least, I don't see it there). I'll look and see what's involved in installing it.

Are you running the 32- or 64-bit version?

Also: I suspect this is a cygwin problem that will need to be reported upstream.
msg413261 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2022-02-14 20:47
Does Cygwin not use : as a path list separator? (What would normally be 
; on Windows.)

Perhaps the CPython build needs to be patched specially here to handle 
different separator character.
msg413264 - (view) Author: Mike Kaganski (mikekaganski) Date: 2022-02-14 21:19
> As for 3.9: it's not available through the 64 bit installer (at least, I don't see it there). I'll look and see what's involved in installing it.

I don't remember if I did something special to install it; however, just maybe you need to install python39 directly.

> Are you running the 32- or 64-bit version?

64-bit.

> Does Cygwin not use : as a path list separator?

It uses : as path separator:

$ echo $PATH
/opt/lo/bin:/usr/local/bin:/usr/bin:/cygdrive/c/Program Files/AdoptOpenJDK/jdk-11.0.7.10-hotspot/bin:/cygdrive/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/cygdrive/c/ProgramData/Oracle/Java/javapath:/cygdrive/c/Windows/System32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:...

But obviously, it can't use Windows-style paths in the $PATH (for that reason?).
msg413272 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2022-02-14 23:41
MSYS2 has basically the same problem when the script is passed as a Windows path, except it uses "/c" for the "C:" drive instead of "/cygdrive/c".

    # python3 -VV
    Python 3.9.9 (main, Dec 28 2021, 11:05:23)
    [GCC 11.2.0]

    # echo $PWD
    /proc

    # python3 C:/Temp/test.py
    python3: can't open file '/proc/C:/Temp/test.py': [Errno 2] No such file or directory

Windows paths in the command-line arguments appear to be passed without conversion:

    # python3 -ic 1 C:/Temp/test.py
    >>> import os
    >>> open(f'/proc/{os.getpid()}/cmdline').read().split('\0')
    ['python3', '-ic', '1', 'C:/Temp/test.py', '']

They're generally supported:

    >>> open('C:/Temp/test.py').read()
    'import sys\nprint(sys.executable)\n\n'

    >>> os.path.samefile('C:/Temp/test.py', '/c/Temp/test.py')
    True

    >>> os.path.abspath('C:/Temp/test.py')
    'C:/Temp/test.py'

realpath() doesn't support them:

    >>> os.path.realpath('C:/Temp/test.py')
    '/:/Temp/test.py'

But the C API _Py_wrealpath() does:

    >>> import ctypes
    >>> path = (ctypes.c_wchar * 1000)()
    >>> ctypes.pythonapi._Py_wrealpath('C:/Temp/test.py', path, 1000)
    1484496
    >>> path.value
    '/c/Temp/test.py'
msg413277 - (view) Author: Christoph Reiter (lazka) * Date: 2022-02-15 07:40
Afaik Cywin programs only work with native Windows paths if the paths happen to get directly passed to the OS APIs and not interpreted in any way before that. So I don't think this is a bug and expected behavior.

Use "cygpath C:/path/to/script.py" to convert the path to the right format first.
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 90907
2022-02-15 07:40:35lazkasetnosy: + lazka
messages: + msg413277
2022-02-14 23:41:25eryksunsetnosy: + eryksun
messages: + msg413272
2022-02-14 21:19:27mikekaganskisetmessages: + msg413264
2022-02-14 20:47:37steve.dowersetmessages: + msg413261
2022-02-14 20:24:05eric.smithsetmessages: + msg413259
2022-02-14 20:04:57mikekaganskisetmessages: + msg413256
2022-02-14 19:00:11eric.smithsetnosy: + eric.smith
messages: + msg413250
2022-02-14 18:42:01mikekaganskicreate