Skip to content
[Python] How to run python shell automatically when REPL started
Profile icon
jha929

Hi, I have embedded REPL shell to my website.

However, when the page is loaded (i.e. REPL loaded), the default page (first page I see) is the bash terminal instead of the python shell.

How do I make the python shell started by default and force the users to stay in the python shell? I don't want my users to see other files in the repository.

Thanks in advance.

[Added]
Basically, I want my REPL terminal looks like this (see image below) when it's loaded (now I have to type python explicitly to start the interactive shell). Moreover, I don't want users to exit the python shell by typing exit().

Screen Shot 2020-09-30 at 7.23.30 PM

You are viewing a single comment. View All
Profile icon
CodeLongAndPros

Make a file called .replit and add this to it:

run="python3"
Profile icon
jha929

@CodeLongAndPros
Hi, thanks for your help, it worked :)

However, I can still escape from the shell by typing exit().

Is there anyway that I can force the users to stay in the python shell? (i.e. prohibit escaping by exit())

Profile icon
CodeLongAndPros

@jha929
try changing python3 to while true; do; python3;done

Profile icon
jha929

@CodeLongAndPros
Ah, that's lit yeh it worked, thanks!

I have another question, if I run import modi in the python shell, it complains that it doesn't have its dependencies installed.

Is there a way that I can install the dependencies (i.e. running python3 setup.py install) implicitly? I don't want my users to type that command explicitly.

FYI, I have configured my .replit file as below:

# https://docs.repl.it/repls/dot-replit run="while true; do python; done" language="python3" onBoot="python3 setup.py install" [packager] afterInstall="echo installation is finished!" ignoredPaths=[".git", ".github", "doc", "tests"] ignoredPackages=["python-can"]

I thought the onBoot option would work as I expected but had no luck there. Maybe I'm not rebooting the shell properly? I just refreshed the page (I'm not sure what triggers the REPL.it to reboot).

I would appreciate it if you'd help on this.

Profile icon
CodeLongAndPros

@jha929
I mean you can create a bash repl and add this:

pip install foo pip install bar==1.0.1 while true; do; python3; done;
Profile icon
jha929

@CodeLongAndPros
Yep, now I defined my run to be something like this run="python setup.py install; while true; do python; done".

Yes, it works but it installs the dependencies every time I click the run button. And this way is quite explicit. I want to preinstall the dependencies so that users don't have to wait for them to be installed. Will there be a way to do that? In fact, my first question was more like how to make my repl's default language to be python (I want to set my repl to be python repl).

I appreciate your help :)

Profile icon
CodeLongAndPros

@jha929
You could always just make a python repl?

Profile icon
jha929

@CodeLongAndPros
I'm importing my python project from github into repl. REPL seems to automatically decide what language type suits to a given project. For my project, bash is assigned as a default project language. Is there a way to change the project language?

Profile icon
CodeLongAndPros

@jha929
Make a python repl and press Ctrl-Shift-s to get a shell. Run git clone {url} .

Profile icon
jha929

@CodeLongAndPros
Ah thanks that worked.

Although I had to git clone the repo then move all its content under the root directory.

Profile icon
CodeLongAndPros

@jha929
Yeah the command should have been cp -r {{repodir}}/* .