MAGALA-RICHARD / apsimNGpy

ApsimNGpy is a Python library designed as an implementation of the APSIM Next Generation crop and environmental simulation model. This library is built upon the Pythonnet API, providing direct communication with the APSIM model. Notably, it offers a significant speed advantage, being twice as fast as the graphical user interface for simulations.
Apache License 2.0
15 stars 2 forks source link

name 'load_default_simulations' is not defined #14

Open elaaatif opened 1 month ago

elaaatif commented 1 month ago

[Running] python -u "k:\for apsim prog\APSIMNGPY\test1.py" Traceback (most recent call last): File "k:\for apsim prog\APSIMNGPY\test1.py", line 18, in soybean_model = load_default_simulations(crop = 'soybean') # don't worry it is not case senstive ^^^^^^^^^^^^^^^^^^^^^^^^ NameError: name 'load_default_simulations' is not defined


'we installed the requirements except building the APSIM from its source code , we have considered using the https://www.apsim.info/documentation/model-documentation/developer-documentation/building-apsim-from-source/ but we tried to run the usage code first but it is not working so far , we don't know if it is related to the paths or is it necessary to build the APSIM ? thank you .

MAGALA-RICHARD commented 1 month ago

Hello, which operating system are you using? Did you install .Net core?

elaaatif commented 1 month ago

hello, I'm using windows 10 version 22H2 , and yes we installed the .Net SDK as mentioned in the readme file , and we are using two different machines and we have the same error on both . I'd like to mention that we couldn't find the bin file for the APSIM image as shown in the picture above , the only bin file found is the one in the TClLink folder

MAGALA-RICHARD commented 1 month ago

Please remember the following information:

You can add the APSIM binary folder to the system path or use the config module to change the APSIM binary folder path. You don't need to build from source. All you need to do is install APSIM and then add the path to the Python environment.

if you open the edit system environment variables and you can see APSIM or Models in there Please do the following:

# search for the program binary installation path and add to os.environ as follows
import os
# A more intuitive way is to use apsimNGpy config Module
from apsimNGpy.config import Config
# now set the path to ASPIMX binaries
Config.set_aPSim_bin_path(path = r'path/toyourapsimbinaryfolder/bin)
# in the pythonnet_config module, priority is first given to the user supplied binary path, we also search through the python global env using the os module,
# if that fail it searches through other sources such as the user program installation folders.
# Not sure whether this can work all the time but you can try changing through os.environ as follows:
os.environ['APSIM'] =r'path/toyourapsimbinaryfolder/bin
# or
os.environ['Models'] =r'path/toyourapsimbinaryfolder/bin