Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

702
Vistas
FileNotFoundError: [Errno 2] No such file or directory + os.execv

I am creating a wrapper script to execute my python programs. The logic is like:

  1. I will install all my required modules in a docker container
  2. Pull the container and run the script, so anyone can run my scripts without worrying about the depended modules
  3. I created a wrapper script that will be called to execute the desired program

This is my wrapper script:

import os
import sys
import argparse

parse = argparse.ArgumentParser()
parse.add_argument('command', help="give datacenter name")
parse.add_argument('args', nargs=argparse.REMAINDER)
parse_arguments = parse.parse_args()

'''
Co-relate to the command and corresponding scripts to trigger
'''
scripts = {
    'verify' : '/path/verify.py'
    }

if __name__ == '__main__':

    if parse_arguments.command not in scripts:
        print('These are the available scripts to run:')
        print('\n'.join(sorted(scripts.keys())))
    else:
        os.execv(scripts.get(parse_arguments.command), 
[scripts.get(parse_arguments.command)] + parse_arguments.args) .   

I am running this like,

$ docker run -it --rm --net host run-script verify --listenv tpc1
Traceback (most recent call last):
  File "/path/runme.py", line 28, in <module>
    os.execv(scripts.get(parse_arguments.command), 
[scripts.get(parse_arguments.command)] + parse_arguments.args)
FileNotFoundError: [Errno 2] No such file or directory

My Docker image is run-script

If I run the same code from my local machine, it does work. but inside container it shows this file not find error.

Can anyone help me on this?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

The first argument passed to sys.argv is the path to the running file, here /path/runme.py. The file is found when run from your local machine, but probably not in the docker container (I'm not sure why).

Try to set the prog parameter when instanciating your ArgParser, something like:

parse = argparse.ArgumentParser(prog="run_me.py")
over 4 years ago · Santiago Trujillo Denunciar

0

I managed to solve this issue. The issue was mainly with the shebang that I have provided. So when I was executing the script in the docker container, it was checking to execute code from shebang location.

I would say, that is a mistake from my side, FileNotFoundError was not giving me a clue to shebang. Finally, figured it out.

@olinox14 - Thanks for your update, "prog" parameter in argparse helped me to output a better help message with the script name in docker container, rather than the full path inside docker container.

over 4 years ago · Santiago Trujillo Denunciar

0

os.execv(program, args) by default doesn't search for program (first argument) based on PATH envrionment variable. os.execvp does.

From os.execv documentation :

os.execv(path, args)

The variants which include a “p” near the end (execlp(), execlpe(), execvp(), and execvpe()) will use the PATH environment variable to locate the program file.

So, either user os.execvp or provide full path to program to be run to os.execv.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda