Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open_database error #39

Open
BjoerndalM opened this issue Jun 5, 2024 · 26 comments
Open

open_database error #39

BjoerndalM opened this issue Jun 5, 2024 · 26 comments
Assignees
Labels
bug Something isn't working

Comments

@BjoerndalM
Copy link

When trying to open a database i get the error:
SQLiteException: code = Error (1), message = System.Data.SQLite.SQLiteException (0x800007BF): SQL logic error
Det angivne modul blev ikke fundet.
ved DHI.Amelia.DataModule.Services.DataSource.DataSourceSpatiaLite.OpenDatabaseCore()
ved DHI.Amelia.DataModule.Services.DataSource.BaseDataSource.OpenDatabase()

the code look like this:
from mikeplus import DataTableAccess
from pathlib import Path

sti_db = Path('C:\Users......\Test.sqlite')
db = DataTableAccess(sti_db)

db_open = db.open_database()

The database has been made in a 2024 version of the mike+ program.

@wuwwen
Copy link
Collaborator

wuwwen commented Jun 6, 2024

Dear @BjoerndalM , can you tell us the steps before you run the code? What install steps are you using and what's the python package version. Maybe also include the windows OS version. Thanks.

@BjoerndalM
Copy link
Author

I am using the Spyder IDE, and running Python 3.9.7.
Like i said, the MIKE+ installation is the 2024 version, but i have both the 2021 and 2023 version installed as well. (Could this be the issue?).
My windows os is Windows 10.0.

The mikeplys libary was installed using the link: https://github.com/DHI/mikepluspy/archive/refs/tags/v2024.0-latest.zip

@BjoerndalM
Copy link
Author

BjoerndalM commented Jun 6, 2024

I have tried uninstalling both the 2021 version and 2023 version of MIKE+, meaning i now only have the MIKE Urban 2020 version and MIKE+ 2024 version installed.
The result, when trying to open the db, is the same, sadly.

When trying to use other functions from the mikepluspy libary i get errors as well, such as this one when i am trying to run the 1d Engine:
RuntimeError: Failed to initialize Python.Runtime.dll

Failed to initialize pythonnet: System.InvalidOperationException: This property must be set before runtime is initialized
ved Python.Runtime.Runtime.set_PythonDLL(String value)
ved Python.Runtime.Loader.Initialize(IntPtr data, Int32 size)
ved Python.Runtime.Runtime.set_PythonDLL(String value)
ved Python.Runtime.Loader.Initialize(IntPtr data, Int32 size)Failed to initialize pythonnet: System.InvalidOperationException: This property must be set before runtime is initialized
ved Python.Runtime.Runtime.set_PythonDLL(String value)
ved Python.Runtime.Loader.Initialize(IntPtr data, Int32 size)
ved Python.Runtime.Runtime.set_PythonDLL(String value)
ved Python.Runtime.Loader.Initialize(IntPtr data, Int32 size)Failed to initialize pythonnet: System.InvalidOperationException: This property must be set before runtime is initialized
ved Python.Runtime.Runtime.set_PythonDLL(String value)
ved Python.Runtime.Loader.Initialize(IntPtr data, Int32 size)
ved Python.Runtime.Runtime.set_PythonDLL(String value)
ved Python.Runtime.Loader.Initialize(IntPtr data, Int32 size)Failed to initialize pythonnet: System.InvalidOperationException: This property must be set before runtime is initialized
ved Python.Runtime.Runtime.set_PythonDLL(String value)
ved Python.Runtime.Loader.Initialize(IntPtr data, Int32 size)
ved Python.Runtime.Runtime.set_PythonDLL(String value)
ved Python.Runtime.Loader.Initialize(IntPtr data, Int32 size)

@wuwwen
Copy link
Collaborator

wuwwen commented Jun 11, 2024

@BjoerndalM I think the latest runtime error is not related to mikepluspy package. Please check this link as a reference. https://stackoverflow.com/questions/76214672/failed-to-initialize-python-runtime-dll#:~:text=To%20resolve%20this%2C%20go%20to%20the%20virtual%20environment,the%20python%20code%20again%20to%20see%20its%20working%21
About the first database problem, we will try hard to reproduce it. We have no success to reproduce for the time being.

@BjoerndalM
Copy link
Author

Thank you wuwwen, i will check out the stackoverflow link.
Regarding the first problem, the database problem, i have noticed that i cant find the dll files for the DHI.Amelia.DataModule.Services, i only have the following:
Skærmbillede 2024-06-11 123931
The files are located at: C:\Program Files (x86)\DHI\MIKE+\2024\bin\x64

@BjoerndalM
Copy link
Author

@wuwwen I tried following the stackoverflow link that you send me.
I still get the runtime error, but not before i run the script second time.
The first time i run the scrip i get the following error message:
image

@wuwwen
Copy link
Collaborator

wuwwen commented Jun 17, 2024

@BjoerndalM i think you are using the wrong version.
If you installed MIKE+ 2024, please use this command to install mikepluspy:
pip install https://github.com/DHI/mikepluspy/archive/refs/tags/v2024.0-latest.zip

If you installed MIKE+ 2024 update 1, please use below way to install mikepluspy:
pip install https://github.com/DHI/mikepluspy/archive/refs/tags/v2024.1-latest.zip

Based on the error message, i think you have MIKE+ 2024 software installed, but used mikepluspy of 2024 update 1 version.

@BjoerndalM
Copy link
Author

@wuwwen You were right about the mix up of versions, but using the correct version (MIKE+ 2024), means that i am back to the problem that i originally posted, regarding the missing DHI.Amelia.Services

@BjoerndalM
Copy link
Author

@wuwwen I asked a colleague to tried to run the code, and he got the excact same error, about the missing files.
image

Like i said earlier, i dont have any files named DHI.Amelia.DataModule.Services.dll, neither does my colleague.
I dont know if i am supposed to have that ?

@bemaDHI
Copy link

bemaDHI commented Aug 20, 2024

Hi @wuwwen, I encountered the same issue when trying to open the database.

Interestingly, I found that this issue only occurs if mikeio is also installed at the same time as mikepluspy and imported into the script. Removing the import mikeio from the script allows the database connection to open successfully.

Here are the details of my environment:

  • Windows 11
  • Python 3.12.3
  • mikepluspy v2024.1-latest
  • mikeio v2.0.1

Please let me know if you would like more details. Thanks!

@ecomodeller
Copy link
Member

@bemaDHI Try to import mikecore instead of mikeio. I would assume that creates the same problem, but then at least we have narrowed down where this problem comes from.

@BjoerndalM
Copy link
Author

@ecomodeller I managed to run the the open database function and run the model when not importing MIKEIO,
if i then import MIKEIO the missing file exception reoccurs. The same is true when i import MIKECORE.
So basicly i can run the model and manipulate the database, as long as i do not import MIKEIO or MIKECORE, which of course isnt ideal.

I dont know if this help you narrow it down further.

@ecomodeller
Copy link
Member

Thanks @BjoerndalM, this is clearly not ideal.

@JesperGr any thoughts on why this interference is happening?

@JesperGr
Copy link

mikecore-python and mikepluspy are both based on some common files. If they provide the same files in different versions, that can produce compatibility issues.

@BjoerndalM
Copy link
Author

@ecomodeller Knowing the cause the issue is the first step.
Is this something DHI will look into, or is it something i can fix on my own behalf or is it something i will just have to work around some way or another ?

@ecomodeller
Copy link
Member

@BjoerndalM Not sure I will be of much help, since this problem is not really caused by Python, but conflicts of binary dependencies.

But if you describe the use case, where you need both mikeio and mikepluspy in the same script, I might be able to figure out a workaround🤔

@JesperGr
Copy link

@BjoerndalM Can you try a thing: Find where the mikecore-python package is installed on your computer. You can find where the packages are installed in general with the command

python -m site

Then find the mikecore package and its bin folder, mine is something like:

Lib\site-packages\mikecore\bin\windows

There should be 15 files there.

Then go to the installation folder of MIKE+, ususally something like:

C:\Program Files (x86)\DHI\MIKE+\2024\bin\x64

find the same 15 files and copy them to the mikecore-python folder. Do remember to take a backup before copying, just in case.

That might solve your issue.

@BjoerndalM
Copy link
Author

@ecomodeller sure thing, we can give it a go !
Basicly the flow will be something along the lines of:

  • Run simulation by using mikepluspy
  • Read resultfile from simulation mikeio
  • Make changes to sqlite fil, based on simulation result
  • repeat until a certain criteria for the results are satisfied

So basicly the loop is: simulating (mikepluspy), reading results (mikeio) and changing the sqlite file (mikepluspy).

@JesperGr
Copy link

@BjoerndalM Just making sure: You are using mikeio only, and not mikeio1d for reading results? Because mikeio1d has a similar, larger, set of binary files.

@BjoerndalM
Copy link
Author

@JesperGr I just tried coping the 15 files from the mike+ folder to the mikecore folder.
This didnt help, and i am still not able to use the mikepluspy open_database function when i import either mikecore or mikeio.

That being said, if i run the code with mikeio1d imported, the simulation is successfull.
On account of the fact that my resultfile from mike+ is a res1d file, i dont see any issues in using mikeio1d instead of either mikecore or mikeio ?

@JesperGr
Copy link

For res1d files you will need mikeio1d. The mikeio and mikecore will not help there, as they are for the other dfs0+1+2+3+u result files.

So, that means that you are up and running now then?

@BjoerndalM
Copy link
Author

@JesperGr Yeah i dont think i necessarily need to manipulate any of the dfsX files. Or i can atleast work around that.
So yeah i would say that i am up and running !

Thanks

@JesperGr
Copy link

@BjoerndalM Thanks for followup up.

@wuwwen We still need to investigate what causes the incompatibility with the mikecore-Python package and how to work around it, do you agree?

@wuwwen
Copy link
Collaborator

wuwwen commented Aug 27, 2024

@JesperGr yes, I agree. I can have a look. But at least we should have a release version which all the DHI python package with the same version.

@JesperGr
Copy link

@wuwwen the mikeio1d package is able to pick up the required libraries from an external folder, e.g. you can point to a MIKE+ installation, and then it will use the files from there. That would work out for mikecore-python as well, I would guess.

@wuwwen
Copy link
Collaborator

wuwwen commented Aug 28, 2024

@JesperGr mikepluspy already pointed into the installation. It has used MikeImport.Setup() method to point to the correct version installation location. Did latest mikeio1d using the mike update 1 binaries? If it is, it must can work with latest mikepluspy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants