Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

707
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda