Sublime Forum

Python build problem: ImportProblem

#1

Hello there
Cant build an app with cmd+b (using macOS if it’s relevant). The app builds just fine using terminal. I can also build any code, that doesnt require imports. Sublime log is following:
Traceback (most recent call last):
File “/Users/egortsvetkov/Documents/cmc/diploma/code/main.py”, line 1, in
import tkinter as tk
ImportError: No module named tkinter
[Finished in 0.4s with exit code 1]
[shell_cmd: python -u “/Users/egortsvetkov/Documents/cmc/diploma/code/main.py”]
[dir: /Users/egortsvetkov/Documents/cmc/diploma/code]
[path: /anaconda3/bin:/anaconda3/condabin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin]

It could be some sublime variable, but I can’t figure out which one. Open for any ideas/suggestions (except for quitting coding, need to get my bach degree). Thanks!

upd: didnt like the way traceback looked, here is a screen

0 Likes

#2

What command do you type in the terminal to run your program?

0 Likes

#3

python3 main.py

0 Likes

#4

The build system you’re running is executing this command:

[shell_cmd: python -u “/Users/egortsvetkov/Documents/cmc/diploma/code/main.py”]

The Python build system that ships with Sublime executes python and not python3, which is executing a different version of Python than you’re expecting it to. You need to modify your build system to execute the correct version of Python.

0 Likes

#5

Thanks, that totally helped!
P. S. Who I need to speak to, so python3 is default in python build, especially since python2 is no longer supported? :smile:

0 Likes

#6

python often doesn’t mean specifically python 2. There’s plenty of install environments where the python executable is python 3.

0 Likes