I have multiple commands and would like to run them using os.system() and in a .py script. however, i have realized that some of the commands do not get executed, and I cannot figure out what the problem is. this is how the content of my .py script look like:
import os
def main():
commands= ['python -m venv test_venv & '
'source ./test_venv/bin/activate &'
'pip install -U pip setuptools wheel & '
'pip install -U spacy & '
'python -m pip freeze > packages_information/spacy_packages.txt & '
'python -m pip install -r packages_information/spacy_packages.txt & '
'python -m spacy download de_core_news_sm & '
'python -m pip freeze > packages_information/de_core_news_sm_spacy_requirements.txt & '
'python -m pip install -r packages_information/de_core_news_sm_spacy_requirements.txt & '
'pip uninstall de_core_news_sm & '
'python -m spacy download de_dep_news_trf & '
'python -m pip freeze > packages_information/de_dep_news_trf_spacy_requirements.txt & '
'python -m pip install -r packages_information/de_dep_news_trf_spacy_requirements.txt &'
'pip uninstall de_dep_news_trf & '
'deactivate test_venv &'
'rm -r test_venv']
for command in commands:
os.system(command)
# clears out the files containing '.txtpython' extentions
directory = os.curdir
files_in_directory = os.listdir()
filtered_files = [file for file in files_in_directory if file.endswith(".txtpython")]
for file in filtered_files:
path_to_file = os.path.join(directory, file)
os.remove(path_to_file)
if __name__ == '__main__':
main()
in particular the uninstallation of Spacy and the delete/remove of the virtual environment do not get executed.