Julia Can't Test User Packages - julia

I have a Julia package I developed locally, let's call it mypack, and I can't automatically test it with Julia in pkg mode. Running pkg>test mypack gives me the following error:
(v1.3) pkg> test mypack
Updating registry at `~/.julia/environments/v1.3/registries/General`
Updating git-repo `https://github.com/JuliaRegistries/General.git`
Testing mypack
Resolving package versions...
[ Info: No changes
Status `/tmp/jl_m6URie/Manifest.toml`
[4e168b6d] mypack v0.1.0 [`~/Documents/mypack`]
ERROR: LoadError: ArgumentError: Package Test not found in current path:
- Run `import Pkg; Pkg.add("Test")` to install the Test package.
Stacktrace:
[1] require(::Module, ::Symbol) at ./loading.jl:887
[2] include at ./boot.jl:328 [inlined]
[3] include_relative(::Module, ::String) at ./loading.jl:1105
[4] include(::Module, ::String) at ./Base.jl:31
[5] include(::String) at ./client.jl:424
[6] top-level scope at none:6
in expression starting at /home/myname/Documents/mypack/test/runtests.jl:1
ERROR: Package mypack errored during testing
My mypack project has the expected structure where there's a root directory with a Project.toml and Manifest.toml generated using ]generate mypack. /test/runtests.jl is just the line
using Test
This works on two machines that I've tested it on, one of which was using Julia 1.1 and one which was using Julia 1.2. The errors are happening on a new install of Julia 1.3.
I am able to test other packages (such as Statistics just fine, which I did to make sure Test was working). I have a more complicated project which brought this to my attention, but this mypack MWE is also broken.

When you run Pkg.test, Pkg creates a test environment. This environment consists of direct dependencies and test dependencies. Any dependency which is imported by test/runtests.jl needs to be in this test environment.
Because your test/runtests.jl imports the Test standard library, you need to add it as a test dependency. You can add test dependencies using this method: https://julialang.github.io/Pkg.jl/v1/creating-packages/#Test-specific-dependencies-in-Julia-1.0-and-1.1-1.

Related

Run a specific version of Julia in Jupyter notebook

I recently installed Julia version 0.7.0 (I need this older version). Prior to that, I had installed Julia 1.6.2, and I can use it in Jupyter notebook. Now, through Julia command line in version 0.7.0, I installed IJulia, and after launching the jupyter notebook through the same command line, I am not able to open notebooks in version 0.7.0. I only see options for 1.6.2.
How can I launch a notebook with version 0.7.0 of Julia?
UPDATE
Now I am able to see Julia 0.7.0 as an option when I open Jupyter notebook, but now the kernel does not connect when I want to use it for this specific version. It works fine for version 1.6.2.
I have tried opening a notebook in two different ways:
From anaconda command line: The notebook launches, but the kernel does not connect. The following error keeps repeating:
ERROR: LoadError: MethodError: no method matching setindex!(::Ptr{Nothing}, ::Ptr{Nothing})
Stacktrace:
[1] start_heartbeat(::ZMQ.Socket) at C:\Users\josh\.julia\packages\IJulia\AQu2H\src\heartbeat.jl:20
[2] init(::Array{String,1}) at C:\Users\josh\.julia\packages\IJulia\AQu2H\src\init.jl:100
[3] top-level scope at none:0
[4] include at .\boot.jl:317 [inlined]
[5] include_relative(::Module, ::String) at .\loading.jl:1038
[6] include(::Module, ::String) at .\sysimg.jl:29
[7] exec_options(::Base.JLOptions) at .\client.jl:239
[8] _start() at .\client.jl:432
in expression starting at C:\Users\josh\.julia\packages\IJulia\AQu2H\src\kernel.jl:24
From Julia command line: I get a message that says Process Exited(1) at the end without opening any notebook.
Try
julia> using Pkg; Pkg.build("IJulia")
within the 0.7 REPL. This should install the Jupyter kernel for Julia 0.7 and make it available as an option.
In case that doesn't work for some reason, you can also try explicitly calling the installkernel function:
julia> installkernel("Julia 0.7")

Cannot install PyCall.jl with Julia 1.6.3 build on FreeBSD 13

I am trying to install PyCall.jl but I get an error. I have installed (bulit) Python 3.10 in the FreeBSD 13. I also, have separately created a python 3.10 virtual environment on the OS from which, I intend to call python packages from. The error is as below.
(dataViz) pkg> add PyCall
Resolving package versions...
Installed VersionParsing ─ v1.2.1
Installed Conda ────────── v1.5.2
Installed MacroTools ───── v0.5.9
Installed JSON ─────────── v0.21.2
Installed PyCall ───────── v1.92.5
Updating `/usr/home/schroter/dataViz/Project.toml`
[438e738f] + PyCall v1.92.5
Updating `/usr/home/schroter/dataViz/Manifest.toml`
[8f4d0f93] + Conda v1.5.2
[682c06a0] + JSON v0.21.2
[1914dd2f] + MacroTools v0.5.9
[438e738f] + PyCall v1.92.5
[81def892] + VersionParsing v1.2.1
Building Conda ─→ `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/299304989a5e6473d985212c28928899c74e9421/build.log`
Building PyCall → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/4ba3651d33ef76e24fef6a598b63ffd1c5e1cd17/build.log`
ERROR: Error building `PyCall`:
<string>:1: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
<string>:1: DeprecationWarning: The distutils.sysconfig module is deprecated, use sysconfig instead
<string>:1: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
<string>:1: DeprecationWarning: The distutils.sysconfig module is deprecated, use sysconfig instead
ERROR: LoadError: Couldn't find libpython; check your PYTHON environment variable.
The python executable we tried was python3 (= version 3.10).
Re-building with
ENV["PYCALL_DEBUG_BUILD"] = "yes"
may provide extra information for why it failed.
Stacktrace:
[1] error(s::String)
# Base ./error.jl:33
[2] find_libpython(python::String; _dlopen::typeof(Base.Libc.Libdl.dlopen))
# Main ~/.julia/packages/PyCall/3fwVL/deps/buildutils.jl:72
[3] find_libpython(python::String)
# Main ~/.julia/packages/PyCall/3fwVL/deps/buildutils.jl:41
[4] top-level scope
# ~/.julia/packages/PyCall/3fwVL/deps/build.jl:82
[5] include(fname::String)
# Base.MainInclude ./client.jl:444
[6] top-level scope
# none:5
in expression starting at /home/schroter/.julia/packages/PyCall/3fwVL/deps/build.jl:43
The installed modules in Julia are as follows:
(dataViz) pkg> status
Status `/usr/home/schroter/.jlmain/dataViz/Project.toml`
[336ed68f] CSV v0.9.10
[54eefc05] Cascadia v1.0.1
[a93c6f00] DataFrames v1.2.2
[708ec375] Gumbo v0.8.0
[cd3eb016] HTTP v0.9.16
[c3e4b0f8] Pluto v0.17.1
[05625dda] WebDriver v0.1.2
EDIT:
My system wide python is at :/usr/local/bin/python3
My python virtual environment is at:~/.pymain/dataViz/bin/activate.csh
Would anyone be able to help me in this matter please?
Thanks & Best Regards
Schroter
You have not mentioned setting the PYTHON environment variable so this is the likely cause of problems:
ENV["PYTHON"]="/usr/local/bin/python3"
using Pkg
Pkg.build("PyCall")
For best results try use Miniconda/Anaconda Python, preferably let Julia install it (I do not know though how easy or difficult it is to install Miniconda on FreeBSD, on any Linux it usually "just works"):
ENV["PYTHON"]=""
using Pkg
Pkg.build("PyCall")
If you want to rather use some Miniconda:
ENV["PYTHON"]="/home/user/miniconda/bin/python"
using Pkg
Pkg.build("PyCall")
Let me know if this helped (I do not have a FreeBSD installation to test)

How to get Pkg in Julia 0.5? ("ERROR: unknown package Pkg")

I need to run a code written in Julia 0.5.
I installed this version on macOS and when I run
using Pkg
It returns the error:
ERROR: ArgumentError: Module Pkg not found in current path.
Run `Pkg.add("Pkg")` to install the Pkg package.
in require(::Symbol) at ./loading.jl:365
in require(::Symbol) at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
When I run
Pkg.add("Pkg")
It returns
INFO: Initializing package repository /Users/henrique/.julia/v0.5
INFO: Cloning METADATA from https://github.com/JuliaLang/METADATA.jl
ERROR: unknown package Pkg
in macro expansion at ./pkg/entry.jl:53 [inlined]
in (::Base.Pkg.Entry.##2#5{String,Base.Pkg.Types.VersionSet})() at ./task.jl:360
in sync_end() at ./task.jl:311
in macro expansion at ./task.jl:327 [inlined]
in add(::String, ::Base.Pkg.Types.VersionSet) at ./pkg/entry.jl:51
in (::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#add,Tuple{String}})() at ./pkg/dir.jl:31
in cd(::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#add,Tuple{String}}, ::String) at ./file.jl:59
in #cd#1(::Array{Any,1}, ::Function, ::Function, ::String, ::Vararg{Any,N}) at ./pkg/dir.jl:31
How to get Pkg in Julia 0.5 then?
That is a very old version of Julia. It is strongly recommended to use a recent version, see the downloads page: https://julialang.org/downloads/. In 0.5 the Pkg module was available by default, so I'm not sure how using Pkg doesn't work. In general, if you're following recent instructions, they're not going to work on such an old version of the language.

PowerModels and JuMP version conflict: Unsatisfiable requirements

I'm new to Julia. I wanted to test out some basic function calls in the PowerModels package with Julia 1.1.0 (it passed the Pkg.test()) so I wrote a few lines according to their tutorial:
using PowerModels
using Ipopt
using JuMP # example didn't have this line
run_ac_opf("case5.m", JuMP.with_optimizer(Ipopt.Optimizer))
I saved it as test1.jl, ran it on REPL with include("test1.jl") and got the following error:
julia> include("test1.jl")
ERROR: LoadError: UndefVarError: with_optimizer not defined
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
I'm not sure what's the cause for this error since when I tried both deleting the using JuMP and changing to using JuMP.with_optimizer, I still get the UndefVarError.
UPDATE
I tried ] rm JuMP and ] rm PowerModels, and added the latest v0.19.1 JuMP (I tried only removing my v0.18.5 JuMP but it conflicted with my installed PowerModels package. However, now when I try ] add PowerModels, it gives me the following error:
(v1.1) pkg> add PowerModels
Resolving package versions...
ERROR: Unsatisfiable requirements detected for package JuMP [4076af6c]:
JuMP [4076af6c] log:
├─possible versions are: 0.19.1 or uninstalled
├─JuMP [4076af6c] is fixed to version 0.19.1
└─found to have no compatible versions left with PowerModels [c36e90e8]
└─PowerModels [c36e90e8] log:
├─possible versions are: [0.1.0, 0.2.0-0.2.3, 0.3.0-0.3.4, 0.4.0, 0.5.0-0.5.1, 0.6.0-0.6.1, 0.7.0-0.7.2, 0.8.0-0.8.8, 0.9.0-0.9.6] or uninstalled
└─restricted to versions * by an explicit requirement, leaving only versions [0.1.0, 0.2.0-0.2.3, 0.3.0-0.3.4, 0.4.0, 0.5.0-0.5.1, 0.6.0-0.6.1, 0.7.0-0.7.2, 0.8.0-0.8.8, 0.9.0-0.9.6]
This is what ] status gives me:
(v1.1) pkg> status
Status `C:\Users\me\.juliapro\JuliaPro_v1.1.0.1\environments\v1.1\Project.toml`
[c52e3926] Atom v0.8.5
[7073ff75] IJulia v1.18.1
[916415d5] Images v0.18.0
[4076af6c] JuMP v0.19.1 [`C:\Users\me\.julia\dev\JuMP`]
[e5e0dc1b] Juno v0.7.0
[91a5bcdd] Plots v0.24.0
[438e738f] PyCall v1.91.2
[d330b81b] PyPlot v2.8.1+ [`C:\Users\me\.julia\dev\PyPlot`]
Seems like I can only use v0.9.6 PowerModels, but according to its github page the stable release is now v0.10.0. Any suggestions?
SOLVED
JuliaPro was the problem. I installed the standalone Julia and was able to use both JuMP and PowerModels.

Dead kernel error when opening a notebook

I had to reinstall a newer version of Julia because the earlier version got broke. Having installed a newer version of Julia, I upgraded to the newer kernel on Jupyter; unfortunately, when I open an existing Julia notebook, the kernel automatically dies.
Following a suggestion from this link I issued this command
conda remove ipykernel
to resolve the problem; because I don't have sudo rights the following error was thrown:
CondaIOError: Missing write permissions in ...
Is there is a way to resolve this issue without creating a virtual environment?
Following your #xiaodai and #Przemyslaw Szufel suggestions, I'm halted by this error
using IJulia
[ Info: Precompiling IJulia [7073ff75-c697-5162-941a-fcdaad2a7d2a]
ERROR: LoadError: ArgumentError: Package ZMQ [c2297ded-f4af-51ae-bb23-16f91089e4e1] is required but does not seem to be installed:
- Run `Pkg.instantiate()` to install all recorded dependencies.
Stacktrace:
[1] _require(::Base.PkgId) at ./loading.jl:929
[2] require(::Base.PkgId) at ./loading.jl:858
[3] require(::Module, ::Symbol) at ./loading.jl:853
[4] include at ./boot.jl:326 [inlined]
[5] include_relative(::Module, ::String) at ./loading.jl:1038
[6] include(::Module, ::String) at ./sysimg.jl:29
[7] top-level scope at none:2
[8] eval at ./boot.jl:328 [inlined]
[9] eval(::Expr) at ./client.jl:404
[10] top-level scope at ./none:3
in expression starting at /storage/home/julia_depot/packages/IJulia/9ajf8/src/IJulia.jl:36
ERROR: Failed to precompile IJulia [7073ff75-c697-5162-941a-fcdaad2a7d2a] to /storage/home/julia_depot/compiled/v1.1/IJu
lia/nfu7T.ji.
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] compilecache(::Base.PkgId, ::String) at ./loading.jl:1197
[3] _require(::Base.PkgId) at ./loading.jl:960
[4] require(::Base.PkgId) at ./loading.jl:858
[5] require(::Module, ::Symbol) at ./loading.jl:853
I have as suggested by the error message issued
Pkg.instantiate()
Also, I have tried
using ZMQ
ERROR: ArgumentError: Package ZMQ [c2297ded-f4af-51ae-bb23-16f91089e4e1] is required but does not seem to be installed:
- Run `Pkg.instantiate()` to install all recorded dependencies.
Although, ZMQ has been installed.
I have this happen to me often. You can try to follow #Przemyslaw's advice and remove the folders or try this
]update
]build IJulia
using IJulia
notebook()
Typically add builds the IJulia, but I find that sometimes after updating, running build manually can help resolve the dead kernel issue.
Use the Anaconda built-into Julia to start the jupyter notebook. In this way you will not have administrative rights nor configure virtual env to manage your Python installation.
julia> ]
(v1.0) pkg> add IJulia
julia> using IJulia
julia> notebook()
Actually you can also run the Julia Jupyter notebook outside of Julia console!
Windows (note that paths on your system might be different):
C:\> %userprofile%\.julia\packages\Conda\hsaaN\deps\usr\Scripts\jupyter-notebook
Linux (note that paths on your system might be different, this should also work on OSX):
$ ~/.julia/packages/Conda/hsaaN/deps/usr/bin/jupyter notebook

Resources