localstack / awscli-local

💲 "awslocal" - Thin wrapper around the "aws" command line interface for use with LocalStack
Apache License 2.0
1.09k stars 86 forks source link

Error when running awslocal #46

Closed avanbecelaere-frb closed 3 years ago

avanbecelaere-frb commented 3 years ago

aws-cli/2.1.35 Python/3.8.8 Windows/10 exe/AMD64 prompt/off

Fatal Python error: _Py_HashRandomization_Init: failed to get random numbers to initialize Python Python runtime state: preinitialized

aeisele commented 3 years ago

Same for me, seems to be a Windows specific problem.

GrzesioG commented 3 years ago

I found a fix for it by modifying "awslocal" python script in Python/Scripts folder. Just add a line that will initialize "env" variable in function "run":

def run(cmd, env={}):

def output_reader(pipe, out):
    out_binary = os.fdopen(out.fileno(), 'wb')
    with pipe:
        for line in iter(pipe.readline, b''):
            out_binary.write(line)
            out_binary.flush()

env=os.environ

process = subprocess.Popen(
    cmd, env=env,
    stderr=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE)

Thread(target=output_reader, args=[process.stdout, sys.stdout]).start()
Thread(target=output_reader, args=[process.stderr, sys.stderr]).start()

process.wait()
sys.exit(process.returncode)

Here is the explanation of the problem: https://www.scivision.dev/python-calling-python-subprocess/

donaldgray commented 3 years ago

The above fix worked for me on Win10. FWIW the file I edited is located: C:\Python38\Scripts\awslocal

UrosOgrizovic commented 2 years ago
  1. @GrzesioG only added the line env = os.environ to awslocal. Their fix also worked for me on Windows 10.

  2. Unlike @donaldgray, the file I edited was in C:\Users\username\AppData\Local\Programs\Python\Python37\Scripts\awslocal. Obviously, that's dependent on the Python installation location.

SingingBush commented 2 years ago

This is still a problem for Windows users installing awslocal. Can that workaround be merged into the codebase.

whummer commented 2 years ago

Hi @SingingBush @UrosOgrizovic @donaldgray @GrzesioG @aeisele @avanbecelaere-frb . Quick update - looks like a missing SYSTEMROOT env variable could be the culprit here under Windows. We have pushed a small fix in 254273bce710eb69f50dcefe09e168f3d61bda60 that should (hopefully) get this resolved. Can you please try upgrading to the latest version and give it another try? Please keep us posted how it goes. Thanks!

pip install --upgrade 'awscli-local>=0.18'
avanbecelaere-frb commented 2 years ago

@whummer, v0.18 works for me. Thank you!