So I have some experience using a Java IDE, I’ve done some online courses for python, and my computer science class uses this Jes IDE to make coding in Jython easy. I wanted to further develop my skills in python, so I have been trying to find an IDE to use python the same way I’ve done with Jython and Java.
Someone pointed me in the direction of Sublime Text 2, and I’ve got it downloaded and I can write in it, but for the life of me I cannot figure out how to run my code (in any IDE for that matter).
I know that Sublime Text doesn’t have a built-in function for running the program.
I’ve downloaded other IDE’s that have a run function and tried to run my code through that, but with no luck.
I’ve downloaded Python 3.5 and I’m not sure if this has anything to do with the problem but its worth noting that when I type “python” into my command prompt it doesn’t detect the version I have installed, it says the file doesn’t exist or whatever.
I’ve been looking for a way to run python code for the past week, so any help would be greatly appreciated.
Just Want to Run a Program
What operating system are you running. I’m assuming Windows, but want to make sure.
Yeah its windows 10. I don’t even know how I would run a program even if everything was installed correctly,(which I don’t know if it is or not) but I do get this error message when I try to build the program
[Error 2] The system cannot find the file specified
[cmd: [u’python’, u’-u’, u’C:\\Users\\Ian\\Music\\Pythonage\\test.py’]]
[dir: C:\Users\Ian\Music\Pythonage]
[path: C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files\Intel\Intel® Management Engine Components\DAL;C:\Program Files\Intel\Intel® Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel® Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel® Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Skype\Phone;C:\Program Files (x86)\nodejs;C:\python35;C:\Users\Ian\AppData\Roaming\npm;C:\Program Files (x86)\Java\jre7\bin]
[Finished]
I am a Python 3 Buff and I just happened across your post… Maybe I can help.
So, Python is so popular with the robotics communities, Raspberry Pi, MagPi Magazine, and Ardunio communities because it is remarkably easy learn and use. You just write the code, and run it. Compiling is completely not even needed. This means you can run your code, later on some day you can reopen it right on your robot and modify it to do something better , save it, and then restart the program right there and not even need a second computer or a compiler.
Python also tends to be averaging around 30% faster than Java or C# code to execute because it is written with fewer lines of code and is well known for being remarkably cleanly written and visually easy to follow.
Here is a simple easy to understand example:
~Hello World in PYTHON 3~ Written in 1 line of code, taking 1 cycle in the CPU to process.
print “Hello, world!”
~~~Hello World in JAVA ~~~ Written in 7 lines of code, taking 7 cycles in the CPU to process.
public class HelloWorld
{
public static void main (String] args)
{
System.out.println(“Hellold!”);
}
}
HOW TO EXECUTE A PYTHON PROGRAM FOR THE FIRST TIME~
FIRST!!! Go to python.org and click on DOWNLOAD and get the correct version for your needs. When installing Python, MAKE SURE YOU CHECK THE BOX FOR ADDING PYTHON TO PATH.EXE for WINDOWS!
After installing in windows, REBOOT! so it will load into path!
Fedora Users already likely have python on your PCs. but in that rare case,
dnf install python3
sudo apt-get install python3
No need to reboot on linux machines.
I personally use the Fedora 22 KDE and Windows 7 SP1 for my operating systems, let me see if I can make the instructions universal enough for anyone to learn how to use. I will put the LINUX Only commands in** BOLD **and windows commands I will leave normal.
the file name doesnt really matter. At all. you can give it any ending, or no ending if you like. you can even write code into a .txt file and then execute the text file and it will run. However, its considered good practice to keep your system neat and organized and make files recognizable upon a glance. so what we do in the python community is create a file and use the ending .py
So create a file called HelloWorld.py
In windows, just open up your Documents folder and rightclick in there and select NEW —> Text file. Rename the text file from NewTextFile.txt to HelloWorld.py
In Fedora or any linux, just go to command line and type:
touch HelloWorld.py
In windows, open a command prompt by clicking start and typing CMD Then Press ENTER.
once in command line, you need to navigate in command line to the file you just created by typing
CD Documents Then press ENTER.
dir Then Press ENTER.
this should show you a listing of all the files and directories in that Documents folder. look for your HelloWorld.py file.
After you found it, just type:
Notepad HelloWorld.py
Fedora users have many options here. Kate is recommended as it is literally a program designed for coding.
Kate HelloWorld.py
Now you should have it open in front of you a blank file in a simple text editor of some sort. lets enter our first line of code…
Type the following:
print "Hello, world!"
Click FILE at the top, SAVE and close it, then go back to command prompt…
type the following to execute it.
python HelloWorld.py
Linux users Type:
python3 HelloWorld.py
now, to take it to the next level, back to command prompt, reopen your basic program and edit the file to contain the following by typing:
Notepad HelloWorld.py
For Fedora Users:
Kate HelloWorld.py
Here is the new enhanced Hello World Code:
[code]# Necessary TKinter Imports for functionality.
from tkinter import *
from tkinter import ttk
import tkinter.messagebox as box
Command to Generate a basic window, Also tied to the window01.mainloop() line.
window01 = Tk()
window01.title( ‘Main Window Title Here’ )
Frame boxes are more complicated. This process shows how to make an entry box
as well as how to get the information from it and use it when you click the button
there are a lot of lines here for this but it kind of shows the whole process.
frame = Generate a box that text can be written into.
entry = call that data that is written in the text box “entry” so I can use it later.
frame = Frame( window01 )
frame.pack( padx = 20 , pady = 20 )
entry = Entry( frame )
entry.pack( side = LEFT )
The DEF command is used to define your own command. In this case, I wrote a small
Program called “entrycalculate” that runs when you click the “Enter Name” button.
def entrycalculate():
box.showinfo( ‘Greetings!’ , 'Welcome ’ + entry.get())
entrybutton = Button( frame, text = ‘Enter Name’ , command=entrycalculate )
entrybutton.pack( side = RIGHT , padx = 5 )
Label is just text inside the generated box. Its how you write on a window box.
Labels are very simple, all you need is the follwing two lines.
label = Label( window01, text = “HELLO WORLD!” )
label.pack( padx = 20, pady = 20 )
This is the basic code for creating a “Exit” or Close button.
button_exit = Button( window01, text = ‘Exit’ , command=exit)
button_exit.pack( padx = 10 , pady = 10 )
command necessary to cause the window to stay active until you click EXIT to close it.
Without the window01.mainloop() command, the program will run but the box will
close almost instantly because there is no command to hold it open.
window01.mainloop()[/code]
Now run that code by typing:
python HelloWorld.py
Fedora users type the following:
python3 HelloWorld.py
EXCELLENT SOURCE FOR HELP:
docs.python.org/3/tutorial/index.html
I honestly never would have figured that out
Everything works fine now, including my code in Sublime Text
I think I either needed to restart after installation of python or just check that box to save it to the path for my PC, mainly I was just thrown off because everything was new and I wasn’t sure if something was actually wrong or I just didn’t know what I was doing lol
Many thanks
Hello,
Glad I could help, If you are interested in GUIs, Try this out, look at how little code AND CLEAN this actually is to do what it is doing…
[code]# Necessary TKinter Imports for functionality.
from tkinter import *
from tkinter import ttk
import tkinter.messagebox as box
Command to Generate a basic window, Also tied to the window01.mainloop() line.
window01 = Tk()
window01.title( ‘Main Window Title Here’ )
Frame boxes are more complicated. This process shows how to make an entry box
as well as how to get the information from it and use it when you click the button
there are a lot of lines here for this but it kind of shows the whole process.
frame = Generate a box that text can be written into.
entry = call that data that is written in the text box “entry” so I can use it later.
frame = Frame( window01 )
frame.pack( padx = 20 , pady = 20 )
entry = Entry( frame )
entry.pack( side = LEFT )
The DEF command is used to define your own command. In this case, I wrote a small
Program called “entrycalculate” that runs when you click the “Enter Name” button.
def entrycalculate():
box.showinfo( ‘Greetings!’ , 'Welcome ’ + entry.get())
entrybutton = Button( frame, text = ‘Enter Name’ , command=entrycalculate )
entrybutton.pack( side = RIGHT , padx = 5 )
Label is just text inside the generated box. Its how you write on a window box.
Labels are very simple, all you need is the follwing two lines.
label = Label( window01, text = “HELLO WORLD!” )
label.pack( padx = 20, pady = 20 )
This is the basic code for creating a “Exit” or Close button.
button_exit = Button( window01, text = ‘Exit’ , command=exit)
button_exit.pack( padx = 10 , pady = 10 )
command necessary to cause the window to stay active until you click EXIT to close it.
Without the window01.mainloop() command, the program will run but the box will
close almost instantly because there is no command to hold it open.
window01.mainloop()[/code]
if you want more info on TKINTER and making GUIs, try this site…
tkdocs.com/tutorial/index.html
@IRTrapGod: Your initial error message seems to indicate that the python
executable has not been found on your PATH. Considering it worked after a reboot, I suspect the following (order important):
- You opened ST.
- You installed Python.
- You created a new .py file in ST and saved it somewhere. Then you attempted to “build”.
- It didn’t work.
The reason it didn’t work is probably that you didn’t restart ST (or reboot, which has the same effect) because changes to system variables such as %PATH% are not retrospectively applied to running processes and the processes they spawn, except for the basic exlorer.exe which you’ll most likely be using to launch Sublime Text (task bar or desktop). Thus, any changes to %PATH% or other system variables require you to restart the application you needed it for.
If you want to know more about system variables, refer to your search engine of choice.