Question:
why am i getting errror in running a simple python file? The error is always “main.py” file not found even when it was there so i deleted it and even then i get the same error. why ?
i need help and quick…
Repl link:
https://replit.com/@PiyushJ2/test-repl-by-Piyush#print.py
code snippet
Can you tell more? Code and error?
If you want replit to run any file other than main.py
in a python repl, you must change the entrypoint
and run
commands in .replit
.
5 Likes
well, how do i do that? where’s the entry point ? It’s my first time using repl.it and i have wasted two hours doing nothing productive, please tell
You need to select the show hidden file clicking on the 3 vertical dots.
Open .replit and change the file name in the run =" command
only “command” ? is there any other change that i must make. ?
Yes, you must change entrypoint
.
as fire pup said
just edit the file .repilit to and where it has run = “python3 main.py” name it to print.py or right click it and press rename it to print.py like this
click on the three sots on the file window
then click on show hidden files
click on .replit and you should find the thing on top then change
entrie point and run to print.py then you are done
hope that helps
4 Likes
will i have to keep doing this for every new file? is there no other solution?
And thanks for all the help
more reliable would be to just have a separate repl for each program, but see
improved: add/change to start of .replit:
onBoot = '''alias n='/nix/store/fbi9r30p3lqk96lmw5b1v1bpbj62cr2l-inotify-tools-3.20.11.0/bin/inotifywait -qe'
w(){(while :
do n -q access $i
sed -i "/^entrypoint/s/\".*\"/\"$i\"/" .replit
done)&}
for i in *.py
do w $i
done
while :
do e=`n moved_to . --include '.*\.py$'`
w ${e/* /}
done'''
Change .*\.py$ to the regex, and *.py to the glob, of the files you want to be auto-set as entrypoint.
You can see this working in the example here : view a file, wai…
1 Like
I have another solution but it’s not too practical either. It may be possible to completely automate this using listdir
but I haven’t tried it. @UMARismyname ’s solution is probably the best.
I need to save this somewhere as I find myself typing it a lot. Editing the hidden files is a totally viable option. However, if you have multiple Py files and don’t wish to manually change stuff every time you want to use one, make the main file (main.py) contain a code similar to this:
choice = int(input("Which file to run?\n1) otherFile\n2) secondFile"))
# Get user input
if choice == 1: # If user chooses option 1
from otherFile import main # Import the function "main" from
# "otherFile.p…
1 Like
system
Closed
May 10, 2023, 3:56am
12
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.