This question already has answers here:
How do I run Python code from Sublime Text 2?
(16 answers)
Closed 7 years ago.
New to Python & Sublime
Problem:
I type 'print ("Hello world")
How do I get it to show me the output (Hello world), is it in a separate window? or...
I understand I can use the Python Console built in, but that's a command line, what about when I get to use a ton of code, how do I get the output?
Click on tools > build systems > select Python, then Build with using ctr+shif B and select python, and it ll work. Second time you can use the build command, ctr + B since python is now set as default
My Sublime Extras extension, and MiniPy, the extension I stole it from, both allow this. Search "eval" on the Extras Github page or use MiniPy.
Maybe SublimeREPL, too, depending in what you are after.
Press CtrlB
Alternatively, if you're on linux or mac, save the file as hello.py in your home directory and do the following in a terminal / command line:
$ cat hello.py
print("Hello World")
$ python3 hello.py
Hello World
If you're on Windows you're best off using the built-in functionality of sublime.
Related
I installed package called Anaconda into my Sublime Text 3
Simple command such as 1+1 doesn't show anything but function print does.
Simple code like 1+1 doesn't work
But python's print function works well.
Can you tell me what am I doing wrong?
Sublime console is not made an interactive console. When you run the python code it actually runs the file. You can check this by typing 1+1 in a file, saving it in a .py format and then running the file as
python -u filename.py
which is how sublime executes the code as seen in https://www.youtube.com/watch?v=6ZpuwW-9T54 at 2:36.
You can check the same response to a similar question in this discussion forum as well. https://forum.sublimetext.com/t/running-python-on-sublime-console/18621/2
Yes it may give you correct answers for the script part i.e print but for things such as 1+1 you need an interactive console. You can just install anaconda directly in your os from this link this would be better.
This question already has answers here:
Running a python script from the command line in Windows
(3 answers)
Closed 6 years ago.
I have pycharm installed and do my class assignment in it and things work well. The teacher wants on to now run some of the programs in command prompt. Given that my programs and the path is here: "C:\Python27\python.exe C:/Users/sz5062/PycharmProjects/untitled1/main.py", how can I run a program that is saved the above path in command line? So, example, how would I run the main.py in command line, not shell prompt?
I have searched and searched for answers here, but I can't fine one. Thanks very much for your help.
This is the full instruction: Install Python and a programming text editor and write a program that prints one line other than 'hello world', then take two screen shots and upload them below. You should use the command line to execute the Python program you wrote in the text editor. Please do not use the IDLE Python Shell, the Python Interpreter (>>>), or a shortcut in your text editor to run the code.
When i run "python main.py", I get an error message "python is not recognized as inernal or external command".
On you Commandline enter:
C:\Python27\python.exe C:\Users\sz5062\PycharmProjects\untitled1\main.py
The above command should work from every directory.
First part is the program you start (python.exe). Second part is the argument you pass to the program(C:\Users\sz5062\PycharmProjects\untitled1\main.py). This is the path to your python code so that python.exe knows what you want to execute.
If you add C:\Python27\ to your PATH variable, you can navigate to your directory C:\Users\sz5062\PycharmProjects\untitled1\ and start your programm with:
python main.py
I'd recommend making sure that python is on your PATH (if you type python does it open a shell?) and then navigate to the C:/Users/sz5062/PycharmProjects/untitled1 directory. Once there you can do:
python main.py
and that should work.
I think I made this hard. since python was in installed on C:\python27, all I needed to run the command line was simply to write the code in a text editor, save it in the same directory and call it from there. So, essentially, c:\python27\code.py
This question already has answers here:
How do you run a python script from within notepad++? [duplicate]
(6 answers)
Closed 7 years ago.
I'm having trouble executing my programs in Notepad++. I'm currently operating on Windows 7.
When attempting to run the program in the the interpreter, I have to jump through numerous hoops to actually get my program to execute. In Notepad++, I'm unable to provide additional text if I'd like to run a sys.argv command, or need to write in a name for a function.
Are there any solutions? Any easier way to run my code?
Run your code from command interpreter.It will look like this
C:\Python27\python.exe programe_name.py
change directory where your program is save before the command.I recommend you to download IDLE editor.It is easy way to learn python.
What I have been doing is this:
Press F5 to run.
Paste this | C:\Python27\python.exe "$(FULL_CURRENT_PATH)"
Replace Python27 with whatever version you use.
Then run.
It should take what you're writing and run it, make sure to select Python as the current language too.
Sorry if this isn't what you're looking for, I'm just starting too!
There are better editors which can run python without a problem. Github's atom can do this easily and is a great free solution and Sublime Text 2 is also both free and paid.
However, if you absolutely have to run on NotePad++, do click Run on the Menu and then Run again. Now, type in the shell command you would like to run (Path-to-python.exe + Path-To-File) and click run
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Can’t run Python from cmd line
I've decided on learning Python, and I'm running Windows 7 Starter Edition on an Acer Aspire One netbook. I installed Python 2.7 directly under the C:/ directory.
I've added it to the PATH. When I type Python in the CMD, I get the appropriate message, talking about my version.
I made a file via Programmer's Notepad containing the following:
print "Hello world"
That is all I typed, and saved it as hello.py on my desktop.
I opened up CMD, and typed hello.py expecting to have Hello World pop up, but there is just a blank line, then prompts a command again.
Here is exactly what happens.
C:\Users\Shane>hello.py
C:\Users\Shane>
Please help. Thank you.
1) You saved your hello.py to your Desktop, but then you are running it from your home directory. That should actually produce an error
2) Try running it like this from your desktop: python Desktop\hello.py
This question already has answers here:
Can't send input to running program in Sublime Text
(5 answers)
Closed 2 years ago.
I use Sublime Text 2 but it won't let me enter any value when my code asks for user input. (In other words: input() in Python and gets in Ruby fail to correctly prompt me for input).
Python throws an EOFError error (what you get when user doesn't enter anything).
Simply USER INPUT isn't working in Sublime Text 2 for me.
EDIT: FOR EXAMPLE
try:
text = input('Enter something: ')
print text
except EOFError:
print('\nEOFError')
=> Enter something: #cannot enter anything to var "text"
=> EOFError
=> [Finished]
Sublime text doesn't support that. But you can get around it (at least in python) by using SublimeREPL, I use this for everything, it works pretty great. Its a little cooky though, as the tab is still editable like a normal sublime tab (which is good and bad)...
It also allows you to run the interpreter in multiple tabs, its basically awesome.
To install it you need package control this lets you easily install plugins. To get it go here, and follow the instructions. Once thats done:
in Sublime press ctrl + shift + P (linux command in ST for 'goto anything').
Type in 'install',
click on 'sublime package control: install package'.
Then select SublimeREPL. It will install it automatically.
To use it go to Tools>sublimerepl>python from the menus.
To make the default build system SublimeREPL, you can follow these instructions.
Since, Sublime not directly support for input console. So, it is easy to get input in Sublime with following extra steps:
Make sure that you have install Package control in Sublime.
If you have no install Package control then, go to here then, click install Now button (top right) copy those code and paste it in your Console (make sure you have tick the Show Console option) and Press Enter. (after that restart sublime)
Go to ->Command Palette(Cltr + Shift + p) click "Package Control: Install Package"
Search : "SublimeRepl" and wait for Installing.
Once, it is Installed, ,Restart Sublime
Go to Tools you will see ""SublimeRepl" option at the bottom (which indicates that it is successfully installed in your sublime)
To run python scripts: Go to Tools->SublimeRepl->Python->Python-RUNcurrentfile option and your code is run in new Repl Tab.
Note: This works fine for sublimeText3 (windows )