Julia .jl in Jupyter notebook - terminal

I'm new to Julia, I have a file called "example.jl" and I want to open it in Jupyter. I added the Julia kernel to my jupyter kernels.
My question is:
Is there a terminal command like:
jupyter notebook blabla.ipynb [that I use to open my notebooks]
Which opens my "example.jl" script in my jupyter notebook with the right jl kernel?
I looked into many pages and couldn't find an answer.
P.S: What I do now is to open a notebook with jl kernel and copy the Julia script into it. But I'd like to know if there are more elegant ways to open .jl s.

Generally you need to create a new empty Jupyter notebook with Julia kernel and copy-paste your code there.
There is also a nice Julia implementation - Weave.jl. Since Jupyter's format is more complex, special code formatting is required (for hints see pictures at https://github.com/JunoLab/Weave.jl) - once it is done you can do the conversion in the following way:
convert_doc("examples/some_code.jl", "some_notebook.ipynb")
There are some other (usually Python-based) tools available, that under some circumstances can be used to split source code file into several Jupyter cells but again every time this assumes some specific code formatting.
P.S.
If you are looking for and IDE try Visual Studio Code with Julia extension which is great.

Related

How to debug a code block in Pycharm Scientific View

I have code blocks that begin with # %%.
I would like the debuger to start inside a particular code block and then pause at my breakpoint.
It just runs through the entire script by default.
Thanks
It is not supported at the moment: https://youtrack.jetbrains.com/issue/PY-29672
Perhaps Jupyter notebooks in PyCharm can be a good alternative. They do support independent cell debugging.

Is there anyway to link iPython notebooks and PyCharm, especially regarding debugging?

iPython notebooks and PyCharm have complementary features, so I'm switching a lot from one to the other. But I would like to make the relationship tighter.
For example, when I'm in a notebook and some code blows up, I would like to set a break point in PyCharm, run my code snippet again, and explore the variables in the breakpoint's scope.
At this point, when I'm in this situation I have to either:
Use the debug command in the notebook, but the navigation within this debugger is a bit clunky (no context autofill, no back-history, no function help display... basically, it seems I'm not in a notebook anymore!)
Go to PyCharm, write a script to recreate the same environment (i.e. imports, variables with their values, etc.) as I was in in the notebook, and launch debug on that script.
This is the main use case I'd like to see solved. Of course, things like triggering PyCharm's "find usages" and "jump to definition" from iPython notebook itself would be a charm (pun not initially intended), but I'll curb my desires for the perfect IDE. For now.
PyCharm 4.0 just came out with iPython integration and allows you to edit *.ipynb files. The official notes are here. Here's how it looks on my screen:

How to make a Python PyQT program not open the command line in Windows

I have a Python program that is mostly complete, and there is one thing that I'd like to change, which may or may not be possible.
This program uses PyQT to display a GUI and I have it pretty much pinned up so I was wondering if I can make Python not open up a termianl when I open the program.
I am using Windows XP right now, but the machines it will run on will be Windows 7. I generally work with Linux, so I'm not terribly familiar with Windows.
If the terminal has to be there, it's no big deal, but I feel like it's extraneous at this point.
Thanks!
Use the python extension .pyw.
E.g program.pyw
This causes your program to be run with pythonw.exe instead of python.exe which suppresses the terminal.

How can I simply "run" lisp files

Python
When I learned Python I installed it on windows with a nice gui installer and all .py files would automatically run in python, from the command line or explorer.
I found this very intuitive and easy, because I could instantly make plain text files and run them.
Lisp
I'm starting to learn lisp and have decided (from reviews) that SBCL is not a bad lisp implementation.
Is there a way to setup SBCL to run .lisp files as easily as with Python?
Are there other lisp implementations that have this?
Executables
SBCL can save executable images, as Greg Harman mentions (see the :EXECUTABLE keyword): http://www.sbcl.org/manual/index.html#Saving-a-Core-Image
Scripts
Lisp files can be executed as scripts, see: http://www.sbcl.org/manual/#Shebang-Scripts
Command Line Options
SBCL has command line options to evaluate/load lisp code on start: http://www.sbcl.org/manual/#Command-Line-Options
SLIME
SLIME is an Emacs interface for Common Lisp. One can use SBCL via SLIME from within Emacs. Many people prefer Emacs Lisp listeners over typical shell interfaces.
Most Common Lisp implementations have similar capabilities. For details consult their manual or ask here for specific implementations.
A few minutes ago someone replied with an answer nearing what I was looking for.
The reply linked to http://www.sbcl.org/manual/Shebang-Scripts.html which was a great help in figuring out my solution. Whoever it was shouldn't have removed their answer as I was about to mark it as correct ;)
My final solution was to create a batch script that is linked through normal program file association as the program to open .lisp files (Right click file->Properties->Opens With->[Change]).
#ECHO OFF
"C:\Program Files\Steel Bank Common Lisp\1.0.37\sbcl.exe" --script %1
When you double click files in explorer it executes them and when you run them in the command line it does the same.
SBCL can save an executable core image via sb-ext:save-lisp-and-die
If you have already downloaded and installed the SBCL interpreter, then in order to run your programs by simply entering them into the command line you need to add the location of the interpreter to your system PATH variable, so that your machine knows where to look.
This is true for any language. What the Python installer did was add the location of the Python interpreter to your PATH environment variable.
Depending on your platform, do a quick Google search on how to set environment variables.

Matlab on cmd (winxp)

I've just started experimenting something with Matlab, and since I'm used to Vim's interface, I try to stay out of Matlab's editor as much as possible. What's troubling me is that every time I start a .m file, it brings up the interface.
Is there a way to start test.m from a cmd line, and let it give output out on a cmd, as it would normally do in Matlab's environment.
Something like a "Matlab shell" (like Python's, only Matlab's)?
To answer your question, start matlab like this:
matalb -nodesktop -nosplash
This does work on both linux and windows. On linux, you type this at the command prompt, and matlab will run in that same command window in text mode. So you would get the "matlab shell" you wanted. On windows, cd into the directory where matlab is installed, and type the same command. It will open a stripped-down matlab command line window, without all the bells and whistles of the matlab desktop.
Now in my personal opinion, the matlab editor with its integrated debugger is your friend. It also has emacs key bindings, if that helps. It is also easier to execute commands and look at the results in matlab desktop then when matlab is run in text mode. The only time you really want to use the text mode is if your matlab code takes a long time to run, and you are only interested in the final result. Or if you are running multiple instances of matlab. The text mode takes much less memory, and on linux you can easily start a run from the command line and put it into background.
In fact, check the command line arguments for matlab. You can do other interesting things, like have matlab execute a single function and exit, a la perl, or redirect a script into matlab like this: matlab < script.m
Are you really willing to do dev work with no m-file debugger? Seems to me that would limit you to practically trivial programs. After a very brief learning curve, I think you'd find the Matlab integrated debugger to be fantastic (and I'm a VS person).
If you insist on doing so, your best option is to compile your m-files to be runnable stand alone. That would require access to the (not cheap) matlab compiler.
Note that there is a significant difference between the compiler distributed with matlab versions up to 6.5, and those distributed with matlab 7+ (don't know the compiler version numbers). In 6.5, the compiler generated c-code, that could be than edited and compiled separately. From 7 onwards, the compiler did no compiling, converting, or any code generation for that matter: running a 'compiled' program today practically runs it on a virtual Matlab machine called the MCR - which encompasses almost all matlab functionality. It is a massive one - MCR installer (installer!) weighted 130M last time I checked.
Some debate on this can still be found on newsgroups, but that's not important now. In fact, the MCR approach seems closer to what you seek.
And btw, for me matlab -nosplash -nodesktop works perfectly on windows - it launches matlab as a console, but that would deprive you both of a text editor and a debugger...
What I would do is:
Start MATLAB
Do not open the .m file within matlab
Open the file in your editor of choice
Run the function from within MATLAB as usual
I can't imagine any reason why this wouldn't work as MATLAB should not care what was used to edit the file.
This won't give you a "shell", but the whole GUI, but I can't think of any reason why you would not want to have that, if it is available.
On Linux environments, Matlab can be started in text mode
matlab -nosplash -nodesktop
but this doesn't work on Windows. which starts it in the current shell. On Windows, this opens a new text-only window. I know of no way to get it to run inside the current console on Windows.
Perhaps there's some way you can attach to it running it in http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/matlabwindows.shtml&http://www.google.com/search?rlz=1C1GGLS_enUS302US311&sourceid=chrome&ie=UTF-8&q=matlab+command+line+windows'>automation server mode.
Another option if you're really desperate could be to make a virtual machine and install linux in it. Then I imagine there are ways to configure vim to work nicely with Matlab (I'm an emacs person these days and there are solutions for emacs).
I had the same problem as Kigurai. I needed to drive Matlab with Python so I found this solution:
In Python:
import os
os.chdir('W:\\monrépertoire')
os.spawnl(os.P_NOWAIT, 'monscript.bat')
In monscript.bat:
matlab.exe -r interp_3D -nodesktop –nosplash
There are cases when indeed not much debugging is needed and state of the Matlab shall be preserved between invocations. One (the only?) example would be Emacs org-mode . it can be used to write text interleaved with code according to literate programming etc. While it is possible to use comments in Matlab and publish code be it HTML or LaTeX, it does however require to leave the comfort of Emacs.
There is a standalone program available that uses Matlab engine to evaluate commands received on stdin, and dump the result. This particular version, however, lacks support for multiline commands like if/else/end or for/end. This is a limitation of engEvalString that expects everything at once. There is an ugly workaround available that makes it usable enough for org-mode.
#+begin_src matlab :session *MATLAB* :exports none :cache no :results value
if 3>1
'wow!!!'
end
#+end_src
#+RESULTS:
: wow!!!

Resources