mlhub
mlhub

Reputation: 129

Error while trying to install custom package on Julia

I am trying to install a custom package in Julia using command Pkg.add(PackageSpec(path = "")), which is in my local directory. I created my package using the Julia documentation. But every time when I am trying to install my custom package using PackageSpec from my local path it throws an error. The folowing error is -

Cloning git-repo `D:\df_sql\src\df_sql.jl`
ERROR: failed to clone from D:\df_sql\src\df_sql.jl, error: GitError(Code:ERROR, Class:Net, failed to resolve address for D: No such host is known. )
Stacktrace:
 [1] pkgerror(::String) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.0\Pkg\src\Types.jl:120
 [2] #clone#2(::Nothing, ::Base.Iterators.Pairs{Symbol,Any,Tuple{Symbol,Symbol},NamedTuple{(:isbare, :credentials),Tuple{Bool,LibGit2.CachedCredentials}}}, ::Function, ::String, ::String) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.0\Pkg\src\GitTools.jl:107
 [3] #handle_repos_add!#32(::Bool, ::Nothing, ::Function, ::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1}) at .\none:0
 [4] #handle_repos_add! at .\none:0 [inlined]
 [5] #add_or_develop#15(::Symbol, ::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1}) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.0\Pkg\src\API.jl:59
 [6] #add_or_develop#14 at .\none:0 [inlined]
 [7] #add_or_develop at .\none:0 [inlined]
 [8] #add_or_develop#10 at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.0\Pkg\src\API.jl:32 [inlined]
 [9] #add_or_develop at .\none:0 [inlined]
 [10] #add#20 at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.0\Pkg\src\API.jl:74 [inlined]
 [11] add(::Pkg.Types.PackageSpec) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.0\Pkg\src\API.jl:74
 [12] top-level scope at none:0

My project Structure is-

enter image description here

I am using Julia version 1.6.0 Any idea how to solve the issue!!!

Upvotes: 4

Views: 825

Answers (1)

Przemyslaw Szufel
Przemyslaw Szufel

Reputation: 42264

I believe you need to have an initialized Git repo in that folder to add it as a package. Here are the steps I made to get a package that I could install locally in Julia:

  1. Setup
using Pkg
Pkg.generate("MyPackage")
open("MyPackage/src/MyPackage.jl","w") do f
    println(f, """
module MyPackage
foo(what) = println("Hello " * what)
export foo
end
    """)
end
  1. Press ; to go to the command line shell mode:
shell> cd MyPackage

shell> git init

shell> git add *

shell> git commit -m init

shell> cd ..
  1. Now you can install the package
julia> Pkg.add(path="MyPackage")
     Cloning git-repo `C:\temp\MyP\MyPackage`
    Updating git-repo `C:\temp\MyP\MyPackage`
    Updating registry at `C:\JuliaPkg\Julia-1.7.0\registries\General.toml`
   Resolving package versions...
    Updating `C:\JuliaPkg\Julia-1.7.0\environments\v1.7\Project.toml`
  [7e0d665f] + MyPackage v0.1.0 `..\..\..\..\temp\MyP\MyPackage#master`
    Updating `C:\JuliaPkg\Julia-1.7.0\environments\v1.7\Manifest.toml`
  [7e0d665f] + MyPackage v0.1.0 `..\..\..\..\temp\MyP\MyPackage#master`
Precompiling project...
  1 dependency successfully precompiled in 5 seconds (316 already precompiled)
  1. Package is installed so it can be used
julia> using MyPackage

julia> foo("world")
Hello world

Note

You could avoid initializing Git repo by using Pkg.develop instead, after step 1 from the above instruction you could do:

julia> Pkg.develop(path="MyPackage")
   Resolving package versions...
    Updating `C:\JuliaPkg\Julia-1.7.0\environments\v1.7\Project.toml`
  [7e0d665f] + MyPackage v0.1.0 `..\..\..\..\temp\MyP\MyPackage`
    Updating `C:\JuliaPkg\Julia-1.7.0\environments\v1.7\Manifest.toml`
  [7e0d665f] + MyPackage v0.1.0 `..\..\..\..\temp\MyP\MyPackage`

julia> using MyPackage
[ Info: Precompiling MyPackage [7e0d665f-f51f-4097-93d9-367fa446d15a]

julia> foo("world")
Hello world

Upvotes: 4

Related Questions