Running a python .py file on Jetbrain Pycharm - console

I write my .py files using Pycharm JetBrains editors. When I run my codes, the output is shown in a console entitled "Run", without any prompt. Therefore, I dont have access to the variables of my code output. How can I force the pycharm to show the output of my codes in ipython console?

You can edit the Run Configuration and check the box "Show command line afterwards". This will run your script, but leave you in an interactive prompt. Everything from your script will have been imported and available.
As a note, if you install the IPython package (Preferences -> Project -> Project Interpreter, click + to add packages) then you can get a nicer console interpreter.
Finally, a different way to accomplish what you are looking for: run under Debug rather than Run. You can set a breakpoint and then use the debugger's Console right at the line you might be interested in.

Related

I want to run magic command % somefile.py inside a jupyter notebook. However, this program requires variables from the main script

To clarify, somfile.py needs variables that are generated from main.ipynb. So, when I simply do %run somefile.py I get this error:
NameError: name 'viewer' is not defined
This viewer is defined in the main code above. However, now if I use %load somefile.py and THEN run it, it works fine. But, the whole point of me doing this is to not show the users of my script, the nitty gritty details. I am preparing this for some students.
The documentation of the magic command %run covers use of the -i option to "run the file in IPython’s namespace instead of an empty one." You want to add that flag to your %run command:
viewer = "something"
%run -i my_script.py
It applies to notebook kernel namespace as IPython was incorporated into the IPython notebook, which became the Jupyter notebook project later.

Error that says Rscript is not recognized as an internal or external command, operable program or batch file [duplicate]

shell_exec("Rscript C:\R\R-3.2.2\bin\code.R ");
This is the call to script.On calling the above script, the error occurs.
I am trying to call my R script from the above path but no output is being shown. While checking the error logs of PHP, it says 'Rscript' is not recognized as an internal or external command, operable program or batch file.' The script is working fine on the Rstudio but not running on the command line.
Add the Rscript path to your environment variables in Windows:
Go to Control Panel\System and Security\System and click Advanced System Settings, then environment variables, click on path in the lower box, edit, add "C:\R\R-3.2.2\bin"
Restart everything. Should be good to go. Then you should be able to do
exec('Rscript PATH/TO/my_code.R')
instead of typing the full path to Rscript. Won't need the path to your my_code.R script if your php file is in the same directory.
You need to set the proper path where your RScript.exe program is located.
exec ("\"C:\\R\\R-3.2.2\\bin\\Rscript.exe\"
C:\\My_work\\R_scripts\\my_code.R my_args";
#my_args only needed if you script take `args`as input to run
other way is you declare header in your r script (my_code.r)
#!/usr/bin/Rscript
and call it from command line
./my_code.r
If you are running it in Git Bash terminal, you could follow a revised version of the idea suggested by #user5249203: in the first line of your file my_code.R, type the following
#!/c/R/R-3.2.2/bin/Rscript.exe
I assumed that your path to Rscript.exe is the one listed above C:\R\R-3.2.2\bin. For anyone having a different path to Rscript.exe in Windows, just modify the path-to-Rscript accordingly. After this modification of your R code, you could run it in the Git Bash terminal using path-to-the-code/mycode.R. I have tested it on my pc.
I faced the same problem while using r the first time in VS Code, just after installing the language package (CRAN).
I restart the application and everything worked perfectly. I think restarting would work for you as well.

Run npm start in Atom Text Editor

In Atom text editor, after saving a file, I'd like to have a hotkey like ctrl-alt-b that will run "npm build" and display the results in an embedded terminal.
I'm also hoping that after seeing the terminal output, I'd be able to click anywhere outside that embedded terminal to make it go away, (instead of having to mouse-travel to some small exit button and click it).
It may be relevant to mention that my OS is Ubuntu 16.04.5.
I did find a really nice tool called the atom build package, but it seems to take over the whole build process, which is something I've already got setup via "npm build".
Setting up a hotkey is the trivial part, but you need some package that provides the actual build command. You can add something like the following to your Atom keymap:
'atom-workspace atom-text-editor:not([mini])':
'ctrl-alt-b': 'package-name:command-name'
Other than that, I recommend using a general purpose package like process-palette. It lets you define a command (or a chain of commands) and run it in your project directory at the press of a custom hotkey.

Running a Python file with atom

I'm using atom for 2 months to run Julia files and it works.
I would like to run some python files too
To do that, I installed the IDE-python package
When Atom is started, there is the following picture:
I can run a Julia file without problem, but I can't run a python file (and there is not a python console...)
How can I add it and run the python file ?
You should load the Script module into Atom. Once loaded, it will show up under the packages menu or you can use the command-I keystroke to run your python code.
To use a shell to run python install the module platformio-ide-terminal. When you click this under packages you'll get an option to toggle a terminal window. It will show up in the bottom third of Atom window.

Send line to console in Notepad++

Is there a way to execute commands line-by-line written in NPP editor in a console.
I have already looked at the following plugins, but they seem to execute a line or chunk of code as a standalone script (i.e. not interactive):
NPPExec;
NPPConsole;
This question is similar to this one:
Run selected line in notepad++ console
but in their case the code is being saved, executed, and stopped. But I would like an interactive console, i.e. it would bring up an instance of shell (or any other console), and I can send line-by-line code from NPP editor.
It sounds like you are looking for behaviour similar to IPython and the Jupyter Notebook or maybe just a regular debugger. I don't know of any plugin that can do that in Notepad++.
If interactive behaviour after initial execution will do (e.g. for inspection of variables), you can achieve that using the interactive flag -i in NppExec like this:
cd $(CURRENT_DIRECTORY)
python -u -i $(FILE_NAME)

Resources