'Is there a way to run other python scripts in an Anaconda prompt throught my python script?

I'm trying to make a GUI for the image generating AI VQGAN-CLIP since the args are hard to properly use. VQGAN-CLIP uses Anaconda prompt with a virtual environment, created and called by this command in an Anaconda prompt window:

 conda create --name vqgan python=3.9
 conda activate vqgan

I then run this command in the Anaconda prompt, located at C:\vqgan\VQGAN-CLIP, and the AI starts generating the image

python generate.py -p "An apple" -i 10 -s 250 250 -cuts 10 -se 10    

Now, if I want to run this exact command in a python script for the GUI (called vqgan-gui, located in the folder C:\vqgan), I thought I could use something like :

os.system('python generate.py -p "An apple" -i 10 -s 250 250 -cuts 10 -se 10')

Or :

command = 'python .\VQGAN-CLIP\generate.py -p "An apple" -i 10 -s 250 250 -cuts 10 -se 10' 
subprocess.run('conda activate vqgan', shell=True)
subprocess.run(command, shell=True)

Or this command (provided by this useful link):

subprocess.run('call "%USERPROFILE%/anaconda3\Scripts\activate.bat" vqgan & cd "C:\vqgan\VQGAN-CLIP\" & python generate.py -p "An apple" -i 10 -s 250 250 -cuts 10 -se 10')

Turns out that all of them fail with similar exit codes like:

ModuleNotFoundError: No module named 'taming.models'

My question is:

  • Do I run the commands called through Anaconda prompt, called by my python GUI script? If so, how can I do this?

OR:

  • Do I activate the virtual environment prior to the os.system("command") inside my python GUI script? If so, how can I do this?

Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source