Sublime Forum

Trouble with Python and Sublime

#1

When I write the code:
print(‘Hello world’)

sublime responds by with
can’t find ‘main’ module in ‘’

I’ve been having trouble with python working on any text platform for months now, but am unsure of what the issue is. I’ve downloaded and deleted countless python files (which could be the problem as I’m not sure if I’ve deleted all of the previous files, not sure how to).

Let me know if this issue can be solved,
Cheers

0 Likes

#2

Sublime Text’s build system is not a terminal nor an interactive (python) shell nor a Jupyter notebook to run arbritary interactive python scripts.

It just invokes an interpreter with the file name of the active view. Python expects a __main__ entry point to be present. Otherwise it doesn’t know where to start.

You could add one with the help of the ifmain snippet

if __name__ == '__main__':
	print("foo")

Save the content as file and run ctrl+b. The build system then outputs:

grafik

But again, this is a very basic approach which doesn’t support user input().

An interactive build system can be created via Terminus package. IIRC there are some OdatNurd tutorial videos about it out there. A short search should quickly reveal some results.

0 Likes

#3

Note also that in this error:

The empty quotes at the end are the Python interpreter telling you what file it was trying to run when it couldn’t find __main__ ; the quotes are empty because you created a new file and didn’t save it to disk before you tried to run it for the first time.

0 Likes