This is lecture is a slightly modified version of https://lectures.quantecon.org/jl/tools_editors.html Thank you to the amazing Quantecon.org team!
Co-authored with Arnav Sood.
While Jupyter notebooks are a great way to get started with the language, eventually you will want to use more powerful tools
We’ll discuss a few of them here, such as
Note that we assume you’ve already completed the getting started lecture
Whenever the Julia compiler or REPL starts, it will look for a file called startup.jl
(see Julia Manual)
We provide a file here which does two things
;
for new commands Revise.jl
package on startup, which lets you see changes you make to a package in real-time (i.e., no need to quit the REPL, open again, and load again) The location for the file is relative to your default Julia environment (e.g. ~/.julia/config/startup.jl
or C:\Users\USERNAME\.julia\config\startup.jl
on Windows)
Recall that you can find the location of the ~/.julia
directory by running
DEPOT_PATH[1]
Note: On Mac, this won’t be visible in the Finder unless you specifically enable that option, but you can get to it by running cd .julia; open .
from a new terminal. Alternatively, with your Finder window open at HOME
, just press Shift + CMD + .
to see all hidden files.
To add Revise.jl
:
julia
terminal, type the following] add Revise REPL; precompile
~/.julia/config/
directory if necessary in the terminal or file explorer On Windows, if you have a shortcut on your desktop or on the taskbar, you could: (1) right-click on the icon; (2) right click on the “julia” text; (3) choose “Properties”, and (4) change the “Start In” to be something such as C:\Users\YOURUSERNAME\Documents
Previously, we discussed basic use of the Julia REPL (“Read-Evaluate-Print Loop”)
Here, we’ll consider some more advanced features
;
brings you into shell mode, which lets you run bash commands (PowerShell on Windows)startup.jl
!CTRL + c
#; pwd
pwd()
You can also use Julia variables from shell mode: the shell can "read" the julia variable x!
x = 2
# ; echo $x
Hitting ]
brings you into package mode
] add Expectations
will add a package (here, Expectations.jl
) ] rm Expectations
will remove that package ] st
will show you a snapshot of what you have installed ] up
will (intelligently) upgrade versions of your packages ] precompile
will precompile everytihng possible You can get a full list of package mode commands by running
] ?
On some operating systems (such as OSX) REPL pasting may not work for package mode, and you will need to access it in the standard way (i.e., hit ]
first and then run your commands)
Hitting ?
will bring you into help mode
The key use case is to find docstrings for functions and macros, e.g.
? print
Note that objects must be loaded for Julia to return their documentation, e.g.
? @test
will fail, but
using Test
? @test
will succeed.
There are several reasons to use a text editor like Atom, including
Integration with Julia documentation and plots
sublime is another good alternative (much fewer features than Juno, but very stable. Just send lines of code into the console with sendText)
(Optional, but recommended): Change default Atom settings
Ctrl-,
(CMD ,
on Mac) to get the Settings
pane Packages
tab Type line-ending-selector
into the Filter and then click “Settings” for that package
LF
(only necessary on Windows) Choose the Editor tab
Soft Wrap
Tab Length
default to 4
Ctrl-,
to get the Settings pane Install
tab uber-juno
into the search box and then click Install on the package that appears yes
At that point, you should see a built-in REPL at the bottom of the screen and be able to start using Julia and Atom
Sometimes, Juno will fail to find the Julia executable (say, if it’s installed somewhere nonstandard, or you have multiple)
To do this
Ctrl-,
to get Settings pane, and select the Packages tabjulia-client
and choose Settings
- To find the binary, you could run
Sys.BINDIR
in the REPL, then add in an additional/julia
to the end of the screen output- e.g.
C:\Users\YOURUSERNAME\AppData\Local\Julia-1.0.1\bin\julia.exe
on Windows as/Applications/Julia-1.0.app/Contents/Resources/julia/bin/julia
on OSX
See the setup instructions for Juno if you have further issues
If you follow the instructions, you should see something like this when you open a new file
If you don’t, simply go to the command palette and type “Julia standard layout”
The bottom pane is a standard REPL, which supports the different modes above
The “workspace” pane is a snapshot of currently-defined objects
For example, if we define an object in the REPL
x = 2
Our workspace should read
The ans
variable simply captures the result of the last computation
The Documentation
pane simply lets us query Julia documentation
The Plots
pane captures Julia plots output (the code is as follows)
using Plots
gr(fmt = :png);
data = rand(10, 10)
h = heatmap(data)
Note: The plots feature is not perfectly reliable across all plotting backends, see the Basic Usage page
Shift + Enter
will evaluate a highlighted selection or line (as above) Ctrl+Shift+Enter
) will run the whole file See basic usage for an exploration of features, and the FAQ for more advanced steps (e.g. using with Docker
)
A
may depend on package xzy
B
, however, may depend on an old version of package xzy
!This is fundamental to ensure reproducibility of results!
An environment
is a set of packages specified by a Project.toml
(and optionally, a Manifest.toml
)
registry
is a git repository corresponding to a list of (typically) registered packages, from which Julia can pull (for more on git repositories, see version control) depot
is a directory, like ~/.julia
, which contains assets (compile caches, registries, package source directories, etc.) Essentially, an environment is a dependency tree for a project, or a “frame of mind” for Julia’s package manager
v1.0
) environment as such:] st
] generate ExampleEnvironment
; cd ExampleEnvironment
] activate .
where “.” stands in for the “present working directory”
activate
-ing and environment, all package manager actions are applied to that environment:] add Expectations Parameters
Note the lack of commas!
ExampleEnvironment
directory in an editor like Atom The Project TOML should look something like this
name = "ExampleEnvironment"
uuid = "f92c96ca-1a46-11e9-1b82-d538e194f99a"
authors = ["Florian Oswald <florian.oswald@gmail.com>"]
version = "0.1.0"
[deps]
Expectations = "2fe49d83-0758-5602-8f54-1f90ad0d522b"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
We can also
] precompile
Note The TOML files are independent of the actual assets (which live in ~/.julia/packages
, ~/.julia/dev
, and ~/.julia/compiled
)
You can think of the TOML as specifying demands for resources, which are supplied by the ~/.julia
user depot
] activate
; cd ..
; rm -rf ExampleEnvironment
With this knowledge, we can explain the operation of the setup block
using InstantiateFromURL
# activate the QuantEcon environment
activate_github("QuantEcon/QuantEconLecturePackages", tag = "v0.9.5");