# How to add package from a folder (not registered) into the the project?

I am trying to add a package called MyModule (I have designed it) but I am not being able to

(@v1.6) pkg> add MyModule
ERROR: The following package names could not be resolved:


I tried this, but also an error

using Pkg

ERROR: LoadError: Path path\to\file\MyModule does not exist.
Stacktrace:


To use what you have locally, use develop rather than add:

help?> Pkg.develop
Pkg.develop(pkg::Union{String, Vector{String}}; io::IO=stderr)
Pkg.develop(pkgs::Union{Packagespec, Vector{Packagespec}}; io::IO=stderr)

Make a package available for development by tracking it by path. If pkg is
given with only a name or by a URL, the package will be downloaded to the
location specified by the environment variable JULIA_PKG_DEVDIR, with
.julia/dev as the default.

If pkg is given as a local path, the package at that path will be tracked.

Examples
≡≡≡≡≡≡≡≡≡≡

# By name
Pkg.develop("Example")

# By url
Pkg.develop(url="https://github.com/JuliaLang/Compat.jl")

# By path
Pkg.develop(path="MyJuliaPackages/Package.jl")


using Pkg
Pkg.develop(path="path\\to\\file\\MyModule")


However the error is saying that the path to the module does not exist

You can check the directory exists with isdir:

isdir("path\\to\\file\\MyModule")


If that returns false, then there is most likely a typo in the path!

2 Likes

using MyModule

1 Like

The isdir path is different than the one you gave to Pkg.develop

@pdeffebach
Excuse me, I just copied it plus my module name of ModuleClasses so the path will be "C:\\Users\\amroa\\OneDrive\\Desktop\\Test\\Classes\\ModuleClasses",
@mmiller do you agree?

Check with isdir

@pdeffebach
Can you please paste the correct path that I need to put it in Pkg.develop(path="") based on the below to make it clear for me"

julia> isdir("C:\\Users\\amroa\\OneDrive\\Desktop\\Test\\Classes")
true
julia> Pkg.develop(path="C:\\Users\\amroa\\OneDrive\\Desktop\\Test\\Classes\\ModuleClasses")


develop will not make the directory for you.

isdir("C:\\Users\\amroa\\OneDrive\\Desktop\\Test\\Classes\\ModuleClasses")


In Julia, a package is a folder, with a specific folder structure, not a file. Please read these docs to better understand. Your file ModuleClasses.jl needs to be in the src sub-folder of a folder titled ModuleClasses.

Looks like you didn’t do everything yet.

Take a look at Pkg.generate or PkgTemplates.jl for more detailed advice on making packages with the right structure.

1 Like

This error:

ERROR: Did not find a git repository at C:\Users\amroa\OneDrive - polymtl.ca\AmroAlsabbagh\Code\Julia\Tests and Notes\16- Create Package\ModuleClasses


Is because Pkg.add looks for a git repository. If you do Pkg.develop instead, it will not do this and use the path supplied to the keyword argument.

Please try the below and see if it works!

Pkg.develop(path="C:\\Users\\amroa\\OneDrive - polymtl.ca\\AmroAlsabbagh\\Code\\Julia\\Tests and Notes\\16- Create Package\\ModuleClasses")
`
1 Like