import os import tarfile import requests def init_env(): # download geckodriver print("Downloading geckodriver...") r = requests.get('https://github.com/mozilla/geckodriver/releases/download/v0.34.0/geckodriver-v0.34.0-linux64.tar.gz') with open('geckodriver-v0.34.0-linux64.tar.gz', 'wb') as f: f.write(r.content) # extract geckodriver tar = tarfile.open('geckodriver-v0.34.0-linux64.tar.gz') tar.extractall() tar.close() # add geckodriver to PATH variable os.environ["PATH"] += ":" + os.getcwd() print(os.environ["PATH"]) # print directory print(os.listdir()) # output geckodriver version os.system("geckodriver --version")