Search code examples
pythoncygwinsave

where to save a file in cygwin


noobiest question ever: I'm trying to work with python via cygwin on my pc laptop - I have a file (foo.py) but python can't find it. The error it's giving me is:

$ chmod +x foo.py
chmod: cannot access `foo.py': No such file or directory

Is there a special location within the Cygwin folder that I need to save my foo.py? Thanks! AP


Solution

  • It's not python that can't find your file, it's the chmod command. C drive is mapped to /cygdrive/c in Cygwin, and D drive is mapped to /cygdrive/d and so on and so forth.

    Are you in the same directory as the file when you are running chmod?

    If your file is at C:\mycode\python\foo.py then you should either change to that directory first -

    $ cd c:
    $ cd mycode/python/
    

    or as @Ahmed mentioned above, you could also run the command as

    $ chmod +x /cygdrive/c/mycode/python/foo.py
    

    But you only need chmod if your python script starts with

    #!/bin/python
    

    To execute such a file, you'd say

    $ /cygdrive/c/mycode/python/foo.py
    

    Or if you are in the same directory

    ./foo.py
    

    If the first line of the python script isn't "#!/bin/python" then you can skip the chmod and just type

    python /cygdrive/c/mycode/python/foo.py