Python script gives `: No such file or directory`

前端 未结 4 970
渐次进展
渐次进展 2020-11-29 02:36

I have several python scripts which work just fine but one script has (as of this morning) started giving me this error if I try to run it from the bash:

4条回答
  •  死守一世寂寞
    2020-11-29 02:52

    Personally, I find it kinda wrong using direct path to python interpreter. As you dont use windows platform, you should have program env, usually in /usr/bin (/usr/bin/env). Try using following shebang:

    #!/usr/bin/env python
    

    Different distros store python binary in /bin or /usr/bin (or some weird locations), and this one makes your script config-independent (as far as possible, here we have possibility that env is stored elsewhere; still - it is less possible that env is not in /usr/bin than that python is mislocated).

    I had similiar problem (if not exactly the same) and that worked for me.

    Also, I have both python interpreters (2.7.x and 3.x) installed, so I need to use "python3" argument for env. AFAIR usually distros link different names to different binaries, so "env python" will run python2.7 on my system, "env python3" (also python33, or smth like that) will run p3k, and "env python2" (also python27, etc) will run python 2.7.x. Declaring which version of interpreter should be used seems like a good idea too.

提交回复
热议问题