Search code examples
pythonsublimetext3

[How to run code by using cmd from sublime text 3 ]


I am a newbie in Python, and have a problem. When I code Python using Sublime Text 3 and run directly on it, it does not find some Python library which I already imported. I Googled this problem and found out Sublime Text is just a Text Editor.

I already had code in Sublime Text 3 file, how can I run it without this error?

For example:

'ModuleNotFoundError: No module named 'matplotlib'.

I think it should be run by cmd but I don't know how.


Solution

  • Depending on what OS you are using this is easy. On Windows you can press win + r, then type cmd. This will open up a command prompt. Then, type in pip install matplotlib. This will make sure that your module is installed. Then, navigate to the folder which your code is located in. You can do this by typing in cd Documents if you first need to get to your documents and then for each subsequent folder.

    Then, try typing in python and hitting enter. If a python shell opens up then type quit() and then type python filename.py and it will run.

    If no python shell opens up then you need to change your environment variables. Press the windows key and pause break at the same time, then click on Advanced system settings. Then press Environment Variables. Then double click on Path. Then press New. Then locate the installation folder of you Python install, which may be in C:\Users\YOURUSERNAME\AppData\Local\Programs\Python\Python36 Now put in the path and press ok. You should now be able to run python from your command line.