How do we run a Python script in Atom editor? - python

How do we run a Python script in Atom editor? Please see screenshot below with errors:
Below I was testing if i can run python in Atom editor. I have also ran the (c:\Anaconda3\Scripts\activate base)command in Anaconda prompt

In your Atom built-in terminal, you are first typing in "python" without any file arguments, and such bringing you into the Python Interactive Prompt, include the name of your file (num.py).
The SyntaxError you're getting is because your trying to run "python num.py" as code instead of a CMD command.

In addition to #HarryKearney answer, there are a number of packages that will easily run scripts. For example, run-in-terminal allows you to press F5 to open a terminal or command prompt window running the python script. Some other options to do similar things are: atom-python-run, atom-runner, script to run code directly in atom and several others you can find in the package repository. Choosing one of these and installing it will probably make it a lot easy if you will be running python scripts frequently.

Related

Atom python IDE, use command line execution?

I would like to use the Atom IDE since it has nice syntax highlighting for python.
However, when I open a .py file in atom, somehow I cannot execute that file in a terminal any more. When I call the .py file in the terminal, instead of the output the terminal returns nothing and the atom window starts blinking as if it is forcefully taking priority.
Is there a way to set atom to only work as an editor and leave the execution of files to the terminal?
You can use the run-in-terminal package.
you need to install additional packages to run python scripts using atom. You can check this Youtube video.
Credit: #Host Promo

In VS Code, can one run Python code in an integrated Python terminal like in Spyder?

Currently, in Visual Studio Code (under Windows 10 64bits), at a Python file called path\myfile.py, if one clicks with mouse right-button for context menu and then chooses 'Run Python File in Terminal', an integrated CMD terminal is open and file is automatically run there with:
python.exe path\myfile.py
After the file stops running, one is naturally left at the integrated CMD cursor.
This behavior is quite different, for instance, from what one has with an IDE like Spyder. There, when you run code (e.g. with F5), at the end one is left still at the Python cursor and can access content of variables created when code was run.
Is there a way to achieve a similar behavior in Visual Studio Code?
You can configure VS Code Python extension to use the -i command line option
Described in https://docs.python.org/3/using/cmdline.html#cmdoption-i
You only have to add the setting bellow (inside settings.json file)
"python.terminal.launchArgs": ["-i"],
This will execute the command python.exe -i path\myfile.py.
I don't know if it is a new feature, but I've been using it for while.
If you would like to use the terminal IPython, like in Spyder, you can use a different set of options, as the following:
"python.terminal.launchArgs": ["-m","IPython","-i"],
With these, VS Code will execute the command python.exe -m IPython -i path\myfile.py.
Then, it will run IPython module as a "script" (with -m option), which will use the options -i path\myfile.py, i.e., IPython will run the file and remain opened.
BTW, another thing is: you can run "cells" in Spyder's integrarted terminal (regions of code with #%%). But in VS Code it seems you can't.
I've made a question with a "work around" to run cells of Python files in VS Code Integrated terminal, which is posted Here
Yes. Open a terminal window and it's like a terminal window on your computer. You can type python filepathandname and the python script will execute like it does from the command line.
The closest you can come is to run the code under the debugger and set a breakpoint at the end to pause the exiting of the execution. Otherwise feel free to file a feature request at https://github.com/microsoft/vscode-python.

Run python script in Atom

Is it possible to run a python script with atom, in another window? It may use any package, at long as it works with python 3 and tkinter. I tried the script package, but I couldn't find the option. Is there somebody of you who got it working?
I don't think ATOM is an IDE. It is just an Editor.
It cannot create a Development environment. Your best option is use the built-in "Terminal".
Even if there exist some package, all it could do is execute a command line, which is similar to manually running the file on the command line.
Running Python on Eclipse can give you a feel, that you execute by clicking the "Run", but it masks the command line actually.
Only 'notebook' can do the wonders of python kernel.

what can I do if a program can be run by python console while can not be run by ipython console?

It seems that the spyder has removed python console, but I got a program can only be run by python console, what can I do? or is there any thing I am wrong?
I got some codes from github, and it needs ADB driver for Android, after I installed ADB, I can run the program in cmd using python wechat_jump_auto.py, but cannot run in spyder with ipython.
In Spyder3 installed in Windows OS, we can add the path to adb using Tools --> Current user environment variables....
Here, we can add the path to adb.exe file by appending it to the path variable. Then, we need to restart Spyder3. Then you will be able to directly run your script with access to adb.exe from Spyder3 IPython console or simply by clicking Run button.
Just came across the same problem as you recently.
In fact, it seems that program using ADB tools just cannot run in Spyder even by python console (my Spyder IDE is equipped with both Ipython console and Python console).
One practical way to solve this problem is to run your code in cmd.
Open your cmd window and do something like this:
python "xxx(path)\xxxx.py(file name)"
In my case, it looks like this:
example image
Hit Enter, and hopefully your code will run successfully.
If it still cannot run, maybe you haven't set your environment variables correctly.
Hope this can solve your problem. Good luck :)

Opening Python program from Anaconda

I have opened Anaconda - then i maneuvered to the directory where a certain python program i want to run actually lies.
I then tried the %run command.
But the command does not seem to work!
So how am i to run that program?
Does anyone know the right command that one has to use in the black colored Anaconda console command line, to run a Python program existing in a certain directory (to which the command line has been taken to)
%run is a command that's run from inside of IPython. To use it, you should start ipython first. Or just run python program.py (if your program is named program.py).

Categories

Resources