WARNING: using x.x in module Main conflicts with an existing identifier

Hi,
this is basically my first day with Julia. I know that this question came up a few times in different context, but I did not really think the answers there where helpful.

I tried to get random program and run it. I tried this with two different programs and got a similar error. My plan was to get code and learn from it.

My choice (but the topic of the code doesnt matter, this one is just one I should understand and the README is super easy… so I thought):

I startet with “] activate .” and then “instantiate”.
Pkg.add(“PowerModels” ) did not work, what would be the first step, I used ] and then “add PowerModels” (correct way?)
After that add Ipopt.
After that, section: # # Basic usage; I used “using PowerModels” and the error in the title came up :frowning:

Same thing with the second Program, activate and instantiate work fine, I would than like to run a file in the src folder and it doesnt work. In that case it is a program in the “examples” folder of the following structure:
Main (containing also Projekt and Manifest), containing scr and examples.

What is my mistake?
Do you have good videos to start out.

PS: I would just like to run a normal file, maybe with some modules, should I not go in the file and run it?

Here a resource that could be useful… scroll on top of the page for the video.

The activate/instantiate will work only if in the directory where you are (on in the global environment, e.g. @v1.7) there is a Project/Makefile file that defines all the packages you need, otherwise you need to add them “manually” by:

using Pkg
Pkg.add("Foo")

Put attention to the difference between the working directory and the environment directory, they can be the same but also not. You pick up the first one with cd([DIR]), e.g. cd(@__DIR__) that automatically set the working directory to those of the .jl file where the command is run, while you set the second one by Pkg.activate([DIR]), e.g. Pkg.Activate(".") to set the environment directory to the current working directory.

You’ll see that message if you are using two different packages that export different functions with the same name:

julia> module A
         export f
         f() = println("hello from module A")
       end
Main.A

julia> module B
         export f
         f() = println("hello from module B")
       end
Main.B

julia> using .A

julia> using .B

julia> f()
WARNING: both B and A export "f"; uses of it in module Main must be qualified

Julia doesn’t know if you want the f() from module A or from module B, so you have to be explicit:

julia> A.f()
hello from module A

julia> B.f()
hello from module B

In your case, that might mean doing something like: PowerModules.function_you_want_to_call(...) instead of just function_you_want_to_call(...).

If you don’t want to have to explicitly write PowerModules. a bunch of times, you can instead tell Julia which exact functions or types you want:

(in a new Julia session)

using PowerModels: function_you_want_to_call
using IPopt: some_other_function
1 Like

Hello,

first of all: thank you for your answer.
I am a little smarter right now, but the videos did not help to solve the specific problem.
The multi-dispatch explanation confused me more, since this error should occur then, even if things are loaded twice.
The video: Modules, packages and environments (20:56), was more helpful, but still did not solve the problem.

All I wanted is to run a Julia file, thats it. I posted the example I tried, it does have a Project and Manifest file. I am in the right path, I guess, and I did activate and instantiated (what I think is the current folder with those files).

So to back up to the absolut beginning in VS Code: “File” → “Open Folder” and my Terminal Commant line shows PS D:\Daten\Julia\PowerModels.jl-master>
(… the cd(“D:\Daten\Julia\PowerModels.jl-master”) command then does nothing, right? But I should be in the working directory) I can change the environment in the left corner of VSCode and chose “C:\users\myName.julia\environments\v1.7”, but that doesnt help … and typing in “using Pkg” doesnt work in any case.
Runing one line of Code by Ctrl+enter in a file in that folder starts Julia and I can type in using Pkg and then activate and so on…

That cant be the way, right?
But that is also another problem due to inexperience, I hope.

I still dont know how to solve the original problem.

Hey,

that helps a little, I actually just want to run that file and it includes “using PowerModels”. This is not the first time I had this problem in my short time with VSCode and Julia (that I maybe skip since Matlab actually runs a Code :sweat_smile: :smiling_face_with_tear:) . I assume the Code I use as en axample is correct, since the error occurs also in other examples I downloaded and tried to run.
So the question becomes: How do I run this file.

I just want to run the Code, shown in the read me:

Basic Usage

Once PowerModels is installed, Ipopt is installed, and a network data file (e.g. “nesta_case3_lmbd.m”) has been acquired, an AC Optimal Power Flow can be executed with,

using PowerModels
using Ipopt
run_ac_opf(“nesta_case3_lmbd.m”, IpoptSolver())

I am very sorry I don’t understand what you want to do and can’t do.
Do you have a Julia file (*.jl) with some code, this is displayed in your VSCode and you want to run (evaluate) the whole file as script instead of running it line by line (or by group of lines) ?
If that’s is the case it is just CTRL+F5, at least on my setup

(By the way to run that SPECIFIC code you need to have the data file given in the example. If the problem is more general, just start with a println("Hello world!"))

wait, to use a Julia package you don’t need to clone the package.
If you want to use PowerModels package, why you have what it seems its master branch ?

Ahh… I may start to getting what you did and why u got the error using x.x conflicts bla blba bla…
You both added and used the PowerModels package using the package manager and cloned it directly from github and try to run its code, right ?

When you open VS Code the REPL does not open directly. This is the normal behaviour.

You can do it, like you did, by running one line in a .jl file with crtl+enter.
or
You hold „alt“ pushed and push „j“ and „o“
This starts the REPL directly

You can find all this commands and shortcuts in the „julia extension“