Running a python module using python3 -m

I know that the run location can be changed by using the .replit and replit.nix files. Given a module “foo” is installed in a python venv, I’d like to be able to run the command “python3 -m foo bar” every time I press the Run button. Is there a way I could go about doing this while preserving the python virtual environment? I have tried simply changing the "run = " line in .replit but looking further into things, it appears it’s not that simple as there’s a whole interpreter section as well. Would appreciate any help!

1 Like

Hi @teamvista welcome to the forums and thank you for your question.

I spoke with the engineering team and they confirmed you can do this if you comment out or remove the interpreter section from the .replit file. If the interpreter section isn’t commented out the run = section is ignored.

Hope this helps you solve the issue. Let me know if this is the answer!

if for any reason you want the interpreter, you could also put in

__import__("os").system("python -m foo bar")

You could have it do it from the file for example:


or if you already have functions in the file try:

def start():
  print("Hello World")

and to call the start function from a different file use:

import os
os.system('from main import start; start()')

Thanks @RetroWolf but the OP never replied to our suggestions. I’m going to close this topic.