Error when running command activate when re-enter the Julia project - julia

I was learning this https://mitmath.github.io/18S096SciML/lecture2/ml
But when I re-enter the activate MLTest command, I get
ERROR: syntax: extra token "MLTest" after end of expression
Stacktrace:
[1] top-level scope at none:0

Turns out I didn't ] to activate Package manager.

Related

How can we run a script in Julia

I'm new to programming and am having difficulty running a script in Julia. I will try to be as detailed as possible so that it will be easier to help me. I am using VS code as my code editor and have made a folder on my desktop called: FirstProgram. In this folder I have created a file called: HelloWorld.jl. This file has the following code in it:
println("Hello World")
So in order to run this code, I opened the julia terminal in VS code and typed
include("HelloWorld.jl")
When I did this, nothing happened.
Next I tried to run this code in the julia repl outside of VS code by typing:
include("HelloWorld.jl")
When I did this, I was met with the following error:
julia> include("HelloWorld.jl")
ERROR: could not open file C:\Users\User\AppData\Local\Julia-1.1.1\HelloWorld.jl
Stacktrace:
[1] include at .\boot.jl:326 [inlined]
[2] include_relative(::Module, ::String) at .\loading.jl:1038
[3] include(::Module, ::String) at .\sysimg.jl:29
[4] include(::String) at .\client.jl:403
[5] top-level scope at none:0
julia>
After doing more research, I tried running this code in command prompt with julia and was met with the same error as above.
Lastly, I tried the code runner extension in VS code. This time I was not met with errors however nothing would output.
Can anyone explain how to run a julia script and how I can avoid the above errors? Moreover, can someone explain how to use the code runner extension successfully? Thanks in advance.

Failed proccess error when downloading file from GitHub on Jupyter Notebook in Julia

I'm trying to download a file from GitHub using Julia in Jupyter Notebook:
isfile("housing.data") ||
download("https://raw.githubusercontent.com/MikeInnes/notebooks/master/housing.data",
"housing.data")
rawdata = readdlm("housing.data")'
I have Windows and Julia v1.1.1 version. I get the error message that doesn't say anything to me:
failed process: Process(`'C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe' -Version 3 -NoProfile -Command "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; (New-Object System.Net.Webclient).DownloadFile('https://raw.githubusercontent.com/MikeInnes/notebooks/master/housing.data', 'housing.data')"`, ProcessExited(3221225477)) [3221225477]
Stacktrace:
[1] error(::String, ::Base.Process, ::String, ::Int64, ::String) at .\error.jl:42
[2] pipeline_error at .\process.jl:785 [inlined]
[3] download(::String, ::String) at .\download.jl:20
[4] top-level scope at In[3]:1
I tried googling the message but it's too long to find anything, I didn't find any related topic with problems like this. What might be the reason for this error? Do I need to provide you with some other information?
Base.download relies on availability and configuration of system commands. In particular its documentation reads:
"this function relies on the availability of external tools such as curl, wget or fetch to download the file and is provided for convenience. For production use or situations in which more options are needed, please use a package that provides the desired functionality instead."
Following this advice you should do:
using Pkg
Pkg.add("HTTP")
using HTTP
HTTP.download("https://raw.githubusercontent.com/MikeInnes/notebooks/master/housing.data", "housing.data")
In this way you use pure Julia to download the file rather then various system tools and maintain the homogeneous behavior of your code across platforms.

JuliaPro can not start in Atom

I just install Julia and then JuliaPro for the IDE.
I can start Julia and work on it normally. However, when I open JuliaPro, I can not start Julia. I got this message after press Enter.
Do you know what happens and how to solve it ?
Press Enter to start Julia.
fatal: error thrown and no exception handler available.
InitError(mod=:BinaryProvider, error=ErrorException("No download engines found. We looked for: power
shell, C:\Windows\System32\WindowsPowerShell\v1.0\powershell, curl, wget, fetch, busybox. Install on
e and ensure it is available on the path.
"))
rec_backtrace at /home/Administrator/buildbot/worker/package_win64/build/src\stackwalk.c:94
record_backtrace at /home/Administrator/buildbot/worker/package_win64/build/src\task.c:246
jl_throw at /home/Administrator/buildbot/worker/package_win64/build/src\task.c:577
error at .\error.jl:33
macro expansion at .\logging.jl:318 [inlined]
#probe_platform_engines!#30 at C:\Users\julia\AppData\Local\Julia-1.0.1\share\julia\stdlib\v1.0\Bina
ryProvider\src\PlatformEngines.jl:258
unknown function (ip: 0000000012498FCE)
jl_fptr_trampoline at /home/Administrator/buildbot/worker/package_win64/build/src\gf.c:1831
jl_apply_generic at /home/Administrator/buildbot/worker/package_win64/build/src\gf.c:2184 [inlined]
jl_apply at /home/Administrator/buildbot/worker/package_win64/build/src\julia.h:1537 [inlined]
jl_invoke at /home/Administrator/buildbot/worker/package_win64/build/src\gf.c:56
probe_platform_engines! at C:\Users\julia\AppData\Local\Julia-1.0.1\share\julia\stdlib\v1.0\BinaryPr
ovider\src\PlatformEngines.jl:134 [inlined]
__init__ at C:\Users\julia\AppData\Local\Julia-1.0.1\share\julia\stdlib\v1.0\BinaryProvider\src\Bina
ryProvider.jl:28
jl_apply_generic at /home/Administrator/buildbot/worker/package_win64/build/src\gf.c:2184
jl_apply at /home/Administrator/buildbot/worker/package_win64/build/src\julia.h:1537 [inlined]
jl_module_run_initializer at /home/Administrator/buildbot/worker/package_win64/build/src\toplevel.c:
90
_julia_init at /home/Administrator/buildbot/worker/package_win64/build/src/home/Administrator/buildb
ot/worker/package_win64/build/src\init.c:813
julia_init__threading at /home/Administrator/buildbot/worker/package_win64/build/src\task.c:302
wmain at /home/Administrator/buildbot/worker/package_win64/build/ui\repl.c:227
__tmainCRTStartup at /usr/src/debug/mingw64-x86_64-runtime-5.0.3-1/crt\crtexe.c:329
mainCRTStartup at /usr/src/debug/mingw64-x86_64-runtime-5.0.3-1/crt\crtexe.c:212
BaseThreadInitThunk at C:\windows\system32\kernel32.dll (unknown line)
RtlUserThreadStart at C:\windows\SYSTEM32\ntdll.dll (unknown line)
At the first time Atom installs at Julia Atom.jl at Juno.jl packages.
Start a Julia console (outside of Atom), go to package manager by pressing ] and type:
(v1.0) pkg> add Juno
(v1.0) pkg> add Atom
Just in case check if they precompile:
julia> using Juno
julia> using Atom
Once installed, go to Atom options by pressing Ctrl+,. Now select Packages and for julia-client click settings - in the settings Julia Path enter the full path for your Julia executable (the same one that has Juno and Atom installed).
Now Julia has good chance to work.
If it does not try to delete the .atom folder (it can be found at JuliaPro-1.0.1.1/.atom or at YOUR_HOME_DIRECTORY/.atom). Sometimes Atom package updates cause Atom Juno to stop working properly and this is the only good option.
Let me know if that helped.

Julia : JLD package doesn't work when running Julia development version

The current version of Julia is 0.4.6. I, however, am running the development version 0.5. Suddenly JLD doesn't work. It's installed and updated. Yesterday I compiled code using JLD but this morning it doesn't work.
julia> using JLD
INFO: Precompiling module JLD...
WARNING: Method definition convert(Type{#T<:AbstractString}, AbstractArray{#S<:Union{Char, Int32, UInt32}, 1}) in module Base at unicode/utf32.jl:131 overwritten in module LegacyStrings at /root/.julia/v0.5/LegacyStrings/src/utf32.jl:133.
WARNING: Method definition isvalid(Array{Char, 1}) in module Base at unicode/utf32.jl:177 overwritten in module LegacyStrings at /root/.julia/v0.5/LegacyStrings/src/utf32.jl:179.
WARNING: New definition
string(Union{Char, LegacyStrings.UTF8String, LegacyStrings.ASCIIString}...) at /root/.julia/v0.5/LegacyStrings/src/utf8.jl:161
is ambiguous with:
string(Union{Char, UTF8String, ASCIIString}...) at unicode/utf8.jl:166.
To fix, define
string(Char...)
before the new definition.
WARNING: both LegacyStrings and Base export "UTF16String"; uses of it in module JLD must be qualified
ERROR: LoadError: LoadError: UndefVarError: UTF16String not defined
in include(::ASCIIString) at ./boot.jl:234
in include_from_node1(::ASCIIString) at ./loading.jl:417
in include(::ASCIIString) at ./boot.jl:234
in include_from_node1(::ASCIIString) at ./loading.jl:417
[inlined code] from ./boot.jl:237
in anonymous at ./<no file>:4294967295
in eval(::Module, ::Any) at ./boot.jl:237
[inlined code] from ./sysimg.jl:11
in process_options(::Base.JLOptions) at ./client.jl:239
in _start() at ./client.jl:318
while loading /root/.julia/v0.5/JLD/src/jld_types.jl, in expression starting on line 11
while loading /root/.julia/v0.5/JLD/src/JLD.jl, in expression starting on line 130
ERROR: Failed to precompile JLD to /root/.julia/lib/v0.5/JLD.ji
in error(::ASCIIString) at ./error.jl:21
in compilecache(::ASCIIString) at ./loading.jl:496
in compilecache(::Symbol) at ./loading.jl:485
in require(::Symbol) at ./loading.jl:355
in eval(::Module, ::Any) at ./boot.jl:237
When using the development version of Julia, you need to use the development versions of the packages (which works for packages where the developer keeps master up-to-date but hasn't tagged yet). If you run Pkg.checkout("JLD") to checkout master, JLD should work (works on my machine. Note you may need to Pkg.update() before checking out, and you may need to quit Julia and re-open it to recompile the new version).
But as a word of caution, don't use the development versions of Julia as a way to test things out. Remember, the language is still in alpha and there is no guarantee that the package ecosystem or Julia itself will work with the daily master. The dailies are good for working on the language and preparing packages for the next version (and being ballsy I guess).
Well, you're using Julia 0.5 which is still in development. If you switch to 0.4.6 then it should be fine. I'm using that and JLD works fine for me. You could also trying running Pkg.update() closing Julia, then reopening, to see if that helps.

JuliaBox - LoadError: unlink: read-only file system (EROFS) Failed to precompile .julia/lib/v0.4/PyCall.ji

I'm running a small Julia program using PyPlot in Juliabox (IJulia Notebook) but it's errors out with an error mesg as listed below. I not sure if it's trying to use my machine's disk to write to but I have valid R+W access there. Basically I'm trying out the examples as mentioned here: https://www.juliabox.org/notebooks/tutorial/Plotting%20in%20Julia.ipynb#
LoadError: unlink: read-only file system (EROFS)
Pkg.add("PyPlot")
using PyPlot
for i = 1.0:300.0
for j = 1.0+i:250.0, k=1.0:10
plot(i+j, i*k/j, color="red", linewidth=1.0, linestyle="--")
i += 0.1
j += 0.05
k += 0.01
end
end
Error log:
INFO: Nothing to be done
INFO: Precompiling module PyPlot...
INFO: Recompiling stale cache file /opt/julia_packages/.julia/lib/v0.4/Compat.ji for module Compat.
ERROR: LoadError: unlink: read-only file system (EROFS)
in unlink at fs.jl:102
in rm at file.jl:59
in create_expr_cache at loading.jl:330
in recompile_stale at loading.jl:461
in _require_from_serialized at loading.jl:83
in _require_from_serialized at ./loading.jl:109
in require at ./loading.jl:219
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
[inlined code] from none:2
in anonymous at no file:0
in process_options at ./client.jl:257
in _start at ./client.jl:378
while loading /home/juser/.julia/v0.4/PyCall/src/PyCall.jl, in expression starting on line 26
ERROR: LoadError: Failed to precompile PyCall to /home/juser/.julia/lib/v0.4/PyCall.ji
in error at ./error.jl:21
in compilecache at loading.jl:384
in require at ./loading.jl:224
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
[inlined code] from none:2
in anonymous at no file:0
in process_options at ./client.jl:257
in _start at ./client.jl:378
while loading /home/juser/.julia/v0.4/PyPlot/src/PyPlot.jl, in expression starting on line 5
LoadError: Failed to precompile PyPlot to /home/juser/.julia/lib/v0.4/PyPlot.ji
while loading In[10], in expression starting on line 2
in error at ./error.jl:21
in compilecache at loading.jl:384
in require at ./loading.jl:250
If I use 0.3.12 version (IJulia Notebook), then it compiles and shows INFO: Nothing to be done but doesn't show anything as output (some graphics plot diagram etc).
Thanks to ali_m. Here's the main summary on what that post says.
The problem seems to be that JuliaBox ships some precompiled cache files in a read-only directory /opt/julia_packages/.julia/lib/v0.4. If at some point it detects that the cache is stale and tries to recompile it, it fails.
This needs to be fixed in Julia itself—it shouldn't try to delete cache files from a read-only directory when recompiling.
Issue link is https://github.com/JuliaLang/julia/issues/14368
To resolve it only in 0.4.2, one can use (this will remove the 3rd index value from Base.LOAD_CACHE_PATH array/set/tuple) to your .juliarc file on JuliaBox to remove the read-only cache directory from the search path. Or just run this manually before typing using Compat etc to rebuild the cache without using the read-only search path.
splice!(Base.LOAD_CACHE_PATH, 3)
A nice example of splice! function
(PS: A function in Julia which ends with ! with its names means, that function will not only do its work but also will change its arguments data/value).
# Remove elements from an array by index with splice!
arr = [3,4,5]
splice!(arr,2) # => 4 ; arr is now [3,5]
The suggested workaround works for 0.4.2 (using echo 'splice!(Base.LOAD_CACHE_PATH, 3)' > ~/.juliarc.jl to insert the line into juliarc) but apparently LOAD_CACHE_PATH isn't defined while launching Julia 0.3.12 so this would fail there.
Adding the following line in the same file fixed this issue (adding a condition to work when version in Julia is 0.4 or above). I didn't see this issue in the 0.5 development version so we are good there.
VERSION >= v"0.4" && splice!(Base.LOAD_CACHE_PATH, 3)

Resources