# Importing package into Main conflicts with an existing identifier

**URL:** <https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804>\
**Category:** New to Julia\
**Tags:** package, module\
**Created:** [November 8, 2020, 10:02pm UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804 "2020-11-08T22:02:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aje12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aje12/32/18950_2.png) [@Aje12](https://discourse.julialang.org/u/Aje12)\
**Post date:** [November 8, 2020, 10:02pm UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/1 "2020-11-08T22:02:10Z")

</div>

Hi all,

When trying the code below I get the error “importing HV04 into Main conflicts with an existing identifier”. Is there a way to resolve this? I’m quite new to Julia so could be making rookie errors.

When I restart julia and try using Pkg, using HV04, HV04.greet() is says “greet is not defined”.

Any help would be much appreciated.

```julia
module HV04

# Write your package code here.
export greet
greet() = print("Hello World!")

end

```

```julia
import HV04
HV04.greet()

```

---

<div class="post-metadata">

**Author:** ![josePereiro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josepereiro/32/17322_2.png) [@josePereiro](https://discourse.julialang.org/u/josePereiro)\
**Post date:** [November 8, 2020, 10:51pm UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/2 "2020-11-08T22:51:39Z")

</div>

> [@Aje12](#):
>
> When I restart julia and try using Pkg, using HV04, HV04.greet() is says “greet is not defined”.

Hi @Aje12, maybe you are loading an older (or different) version of the `HV04` module. You can check which package version you are loading using `import Pkg; Pkg.status()`. Also you can check the path of the loaded module using `import HV04; pathof(HV04)`. You can provide us this information for further help.

You can check at the documentation for how to [develop](https://julialang.github.io/Pkg.jl/v1/managing-packages/#developing-1) packages.

---

<div class="post-metadata">

**Author:** ![Aje12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aje12/32/18950_2.png) [@Aje12](https://discourse.julialang.org/u/Aje12)\
**Post date:** [November 9, 2020, 12:36pm UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/3 "2020-11-09T12:36:57Z")

</div>

@josePereiro

Hi thanks for your reply. I’ve tried what you suggested and this is what I get

```julia
Status `C:\Users\aaron\.julia\environments\v1.5\Project.toml`
  [c52e3926] Atom v0.12.24
  [6e4b80f9] BenchmarkTools v0.5.0
  [336ed68f] CSV v0.7.7
  [aaaa29a8] Clustering v0.14.1
  [a93c6f00] DataFrames v0.21.7
  [38e38edf] GLM v1.3.10
  [28b8d3ca] GR v0.52.0
  [a2cc645c] GraphPlot v0.4.3
  [6049f220] HV04 v0.1.0 `C:\Users\aaron\~\code\HV04`
  [7073ff75] IJulia v1.21.4
  [b9914132] JSONTables v1.0.0
  [e5e0dc1b] Juno v0.8.4
  [093fc24a] LightGraphs v1.3.0
  [2f5eb75a] LightGraphsFlows v0.4.1
  [6f286f6a] MultivariateStats v0.7.0
  [14b8a8f1] PkgTemplates v0.7.13
  [91a5bcdd] Plots v1.6.9
  [d330b81b] PyPlot v2.9.0
  [ce6b1742] RDatasets v0.6.10
  [fc66bc1b] SNAPDatasets v0.1.0
  [bd369af6] Tables v1.1.0
  [b8865327] UnicodePlots v1.3.0
  [37e2e46d] LinearAlgebra
  [9a3f8284] Random
  [9e88b42a] Serialization
  [10745b16] Statistics

```

I tried pathof but nothing came up

```julia

julia> import HV04
ERROR: importing HV04 into Main conflicts with an existing identifier

julia> pathof(HV04)

```

I created the package HV04 in a different directory, would that be the problem? Its in “C:\Users\aaron~\code\HV04” and im working in “C:\Users\aaron\hv04”

---

<div class="post-metadata">

**Author:** ![josePereiro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josepereiro/32/17322_2.png) [@josePereiro](https://discourse.julialang.org/u/josePereiro)\
**Post date:** [November 9, 2020, 1:10pm UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/4 "2020-11-09T13:10:44Z")

</div>

Umm, Try `cd` to `C:\Users\aaron\~\code\HV04` and run `julia --startup-file=no --project -e "import HV04; println(pathof(HV04))"`.

What it does:  
1- `--startup-file=no` won’t load `~/.julia/config/startup.jl` (this is the default path, it may be different) file so anything you are defining there will not interfere.  
2- `--project` will tell julia to use the package [environment](https://julialang.github.io/Pkg.jl/v1.1/environments/), not the global.  
3- `-e "import HV04; println(pathof(HV04))"` will execute this lines.

---

<div class="post-metadata">

**Author:** ![Aje12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aje12/32/18950_2.png) [@Aje12](https://discourse.julialang.org/u/Aje12)\
**Post date:** [November 9, 2020, 1:25pm UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/5 "2020-11-09T13:25:56Z")

</div>

Do I run that in the Julia terminal or a git bash one? I’ve tried both and it didn’t work, I’m definitely doing it wrong though.

---

<div class="post-metadata">

**Author:** ![josePereiro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josepereiro/32/17322_2.png) [@josePereiro](https://discourse.julialang.org/u/josePereiro)\
**Post date:** [November 9, 2020, 1:36pm UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/6 "2020-11-09T13:36:41Z")

</div>

Umm, you are using Windows! You probably should find a way to include julia in your path, but that is a different issue, see here.

> [@Path Environments](https://discourse.julialang.org/t/path-environments/49555):
>
> I would like to add Maxima.jl, but in order to run Maxima I need to add a directory to the Path environment, so Julia can find it. On Windows you will also need to add the directory containing the maxima.bat executable to your PATH environment variable so that Julia can find it. How do I do this?

Anyway, a version you can run from a julia repl:

```julia
cmd = `$(Base.julia_cmd()) --startup-file=no --project='C:\Users\aaron\~\code\HV04' -e "import HV04; println(pathof(HV04))"`
run(cmd)

```

It is calling a julia process from a julia process with the same parameters than before.

---

<div class="post-metadata">

**Author:** ![Aje12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aje12/32/18950_2.png) [@Aje12](https://discourse.julialang.org/u/Aje12)\
**Post date:** [November 9, 2020, 6:25pm UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/7 "2020-11-09T18:25:13Z")

</div>

Thanks for all the help so far 🙂 I ran that command and this came up.

C:\Users\aaron~\code\HV04\src\HV04.jl Process(`'C:\Users\aaron\AppData\Local\Programs\Julia 1.5.2\bin\julia.exe' -Cnative '-JC:\Users\aaron\AppData\Local\Programs\Julia 1.5.2\lib\julia\sys.dll' -g1 --startup-file=no '--project=C:\Users\aaron\~\code\HV04' -e 'import HV04; println(pathof(HV04))'`, ProcessExited(0))

---

<div class="post-metadata">

**Author:** ![josePereiro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josepereiro/32/17322_2.png) [@josePereiro](https://discourse.julialang.org/u/josePereiro)\
**Post date:** [November 10, 2020, 3:10pm UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/8 "2020-11-10T15:10:26Z")

</div>

Ok, `ProcessExited(0)` means that all was ok and julia was able to load your package. Also as you can see the path `C:\Users\aaron~\code\HV04\src\HV04.jl` is consistent with the one given by `Pkg.status()` for this package `C:\Users\aaron\~\code\HV04`, so the environment is ok too.  
That suggest that the problem could be that you (or something else) are defining other `HV04` in the `startup.jl` file. For testing it just run the previous command without the `--startup-file=no` flag, or check your `startup.jl` file.

---

<div class="post-metadata">

**Author:** ![Aje12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aje12/32/18950_2.png) [@Aje12](https://discourse.julialang.org/u/Aje12)\
**Post date:** [November 10, 2020, 7:03pm UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/9 "2020-11-10T19:03:11Z")

</div>

I ran the command without the startup flag and got:

```julia
julia> run(cmd)
C:\Users\aaron\~\code\HV04\src\HV04.jl
Process(`'C:\Users\aaron\AppData\Local\Programs\Julia 1.5.2\bin\julia.exe' -Cnative '-JC:\Users\aaron\AppData\Local\Programs\Julia 1.5.2\lib\julia\sys.dll' --depwarn=yes -g1 --color=yes '--project=C:\Users\aaron\~\code\HV04' -e 'import HV04; println(pathof(HV04))'`, ProcessExited(0))

```

---

<div class="post-metadata">

**Author:** ![josePereiro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josepereiro/32/17322_2.png) [@josePereiro](https://discourse.julialang.org/u/josePereiro)\
**Post date:** [November 10, 2020, 8:07pm UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/10 "2020-11-10T20:07:16Z")

</div>

Well, another thing you can try is `@which HV04` in a fresh julia session (without importing HV04). That will give you info about the already defined HV04

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [November 10, 2020, 9:21pm UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/11 "2020-11-10T21:21:27Z")

</div>

> [@josePereiro](#):
>
> ```julia
> cmd = `$(Base.julia_cmd()) --startup-file=no --project='C:\Users\aaron\~\code\HV04' -e "import HV04; println(pathof(HV04))"`
> run(cmd)
> 
> ```

Yeah, I got Maxima working in the REPL a week ago, only thing is it won’t load in Julia Markdown.

---

<div class="post-metadata">

**Author:** ![Aje12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aje12/32/18950_2.png) [@Aje12](https://discourse.julialang.org/u/Aje12)\
**Post date:** [November 10, 2020, 9:38pm UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/12 "2020-11-10T21:38:43Z")

</div>

Got ‘Main’ when running this. Thank you again for all the help on this issue!

---

<div class="post-metadata">

**Author:** ![josePereiro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josepereiro/32/17322_2.png) [@josePereiro](https://discourse.julialang.org/u/josePereiro)\
**Post date:** [November 10, 2020, 9:56pm UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/13 "2020-11-10T21:56:54Z")

</div>

Umm, somehow something is defining `HV04` in Main, it can only (I think (In a fresh session)) occur in your `startup.jl` file.

Another tests

Test1

```julia
cmd = `$(Base.julia_cmd()) --startup-file=no -e "println(@isdefined HV04)"`
run(cmd);

```

It should print `false`, which means that julia std library do not define any `HV04`.

Test2

```julia
cmd = `$(Base.julia_cmd()) --startup-file=yes -e "println(@isdefined HV04)"`
run(cmd);

```

Now, if the problem is that you somehow declare `HV04` in the `startup.jl` file it must return `true`. But, if it returns `false` then something else is happening and I will need more info for trying to solve it

---

<div class="post-metadata">

**Author:** ![Aje12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aje12/32/18950_2.png) [@Aje12](https://discourse.julialang.org/u/Aje12)\
**Post date:** [November 11, 2020, 11:09am UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/14 "2020-11-11T11:09:51Z")

</div>

Both tests returned false

```julia
julia> run(cmd)
false
Process(`'C:\Users\aaron\AppData\Local\Programs\Julia 1.5.2\bin\julia.exe' -Cnative '-JC:\Users\aaron\AppData\Local\Programs\Julia 1.5.2\lib\julia\sys.dll' --depwarn=yes -g1 --color=yes --startup-file=no -e 'println(@isdefined HV04)'`, ProcessExited(0))

```

```julia
julia> run(cmd)
false
Process(`'C:\Users\aaron\AppData\Local\Programs\Julia 1.5.2\bin\julia.exe' -Cnative '-JC:\Users\aaron\AppData\Local\Programs\Julia 1.5.2\lib\julia\sys.dll' --depwarn=yes -g1 --color=yes --startup-file=yes -e 'println(@isdefined HV04)'`, ProcessExited(0))

```

What extra info do you need?

---

<div class="post-metadata">

**Author:** ![josePereiro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josepereiro/32/17322_2.png) [@josePereiro](https://discourse.julialang.org/u/josePereiro)\
**Post date:** [November 12, 2020, 2:03am UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/15 "2020-11-12T02:03:39Z")

</div>

Well I’m running out of ideas 😉 Its seams that if you start a fresh julia process (using `run(`$(julia_cmd())...`)`) you are able to import the package with no problem independent of the `startup.jl`. But somehow when you use julia the ‘other way’ in a fresh session you have already defined `HV04` in `Main` so it conflict with an `import` call. So, could you describe, as precise as possible, how do you run julia in the cases that the `import` error occur?

---

<div class="post-metadata">

**Author:** ![Aje12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aje12/32/18950_2.png) [@Aje12](https://discourse.julialang.org/u/Aje12)\
**Post date:** [November 23, 2020, 5:35pm UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/16 "2020-11-23T17:35:51Z")

</div>

Sure thing! When I open atom and start a new Julia session and do import HV04 followed by HV04.greet() I get the error “greet is not defined”.

If I run HV04.jl then type using HV04 i get the error “ERROR: importing HV04 into Main conflicts with an existing identifier”. Same thing if I import HV04.

However after running HV04.jl and typing HV04.greet() works.

---

<div class="post-metadata">

**Author:** ![josePereiro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josepereiro/32/17322_2.png) [@josePereiro](https://discourse.julialang.org/u/josePereiro)\
**Post date:** [November 24, 2020, 3:02am UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/17 "2020-11-24T03:02:06Z")

</div>

> [@Aje12](#):
>
> If I run HV04.jl

What do you mean by that?

---

<div class="post-metadata">

**Author:** ![Aje12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aje12/32/18950_2.png) [@Aje12](https://discourse.julialang.org/u/Aje12)\
**Post date:** [November 24, 2020, 11:30am UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/18 "2020-11-24T11:30:45Z")

</div>

Its the main file for my project. Ill paste it below 🙂

```julia
module HV04

export my_PageRank
export g_bfs, g_dijkstra, g_bellman, g_page_rank
export PageRank

include("GraphAlgorithms.jl")
include("PageRank.jl")
end

```

So if I hit run for this file in Atom and type ‘using HV04’ into the console I get the conflicts error.

---

<div class="post-metadata">

**Author:** ![josePereiro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josepereiro/32/17322_2.png) [@josePereiro](https://discourse.julialang.org/u/josePereiro)\
**Post date:** [November 25, 2020, 4:44am UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/19 "2020-11-25T04:44:21Z")

</div>

> [@Aje12](#):
>
> So if I hit run for this file in Atom and type ‘using HV04’ into the console I get the conflicts error.

Well in this case I think is understandable, I never used Atom but I believe when you run a file it just `include` it in the current session, so you are defining a new module in `Main` called `HV04`. `using MyPkg` means that you want to load a package from the environment and include it in the `Main` module. In your case the package exist in the environment but you can’t include it in `Main` due to the name conflict.

For instance, this is another scenario:

```julia
module A
    export funA
    funA() = println("Hi from A")
end
using A
# ERROR: ArgumentError: Package A not found in current path:
# - Run `import Pkg; Pkg.add("A")` to install the A package.
funA()

```

In this case the `using` statement fails because no module/package `A` was listed in the active environment. But I can do `using .A` (note the dot, which mean current Module) to tell the load system you want the `Main` version not the version listed in any environment. In this case all works and `funA` is exported to `Main`.

```julia
module A
    export funA
    funA() = println("Hi from A")
end
using .A
funA()
# Hi from A

```

> [@Aje12](#):
>
> Sure thing! When I open atom and start a new Julia session and do import HV04 followed by HV04.greet() I get the error “greet is not defined”.

Now that I see your code, I don’t see the definition of a function `greet`, so the call error could be also expected.

---

<div class="post-metadata">

**Author:** ![Aje12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aje12/32/18950_2.png) [@Aje12](https://discourse.julialang.org/u/Aje12)\
**Post date:** [November 25, 2020, 11:02am UTC](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804/20 "2020-11-25T11:02:56Z")

</div>

Ah that makes sense and works! Thank you very much for all your help 🙂

[Next page](https://discourse.julialang.org/t/importing-package-into-main-conflicts-with-an-existing-identifier/49804.md?page=2)
