Can a Python script detect it is running in repl.it?
boukeas

Is it possible for a Python script to check if it is running within repl.it?

You are viewing a single comment. View All
Answered by Vandesm14 [earned 5 cycles]
View Answer
Vandesm14

I'm afraid that this is not possible. Repl.it is running a Linux VM which does not provide any info on if it's a normal Linux machine, or a repl.it server.

Vandesm14

@boukeas You can set .env variables manually and pull from that, but it's far from automatic.
https://pypi.org/project/python-dotenv/

boukeas

@Vandesm14 Thank you for your reply. Would it not be possible to set an environment variable in the VM, that would suggest that this is a repl.it server?

I asked this question in the context of a specific issue I am having: https://repl.it/talk/ask/Is-it-possible-to-use-PIL-in-replit-to-show-images/24944. Essentially, this is an example of a program that would need to differentiate its behaviour depending on whether or not it is running in repl.it

MrEconomical

@boukeas if @Vandesm14 answered your question make sure to mark t as correct

boukeas

@Vandesm14 What I am saying is it would be possible for a program to detect if it's running in repl.it if a specific environment variable was automatically set by repl.it in the Linux VM.

qaiik

@Vandesm14 it is, check if REPL_ID env exists