Issues running apsimNGpy on Windows #35
Replies: 7 comments 11 replies
-
|
Hello Spencer, from apsimNGpy.core.config import apsim_bin_context
with apsim_bin_context(apsim_bin_path=r'APSIM2025.8.7844.0/bin'):
# now import apsimNGpy model
from apsimNGpy.core.apsim import ApsimModel
# after importing, you can exit the with block
model = ApsimModel('Wheat')# loading default files is easy by specifying just the plant or file name, without .apsimx extension,
model.run()
model.results |
Beta Was this translation helpful? Give feedback.
-
|
Does this occur while you are running older APSIM versions; if yes I have
tried to fix the file structure bugs with the newer version: you may try it
out via GitHub. Let me investigate this NameError shortly
…On Fri, Dec 5, 2025 at 12:36 PM spencercole6-ops ***@***.***> wrote:
Hi Dr. Magala,
Thanks so much for the prompt reply! Before reverting to an older APSIM
version I just wanted to check that first line since I haven't been able to
import anything related to apsimNGpy on any version since I apparently
polluted my env. Just from trying that first line of code from
apsimNGpy.core.config import apsim_bin_context I am still getting that
Windows path error. Below is the full traceback. I am not very experienced
with manually editing and tracking Windows path variables since most of the
packages I've worked with have automatically added them, but do you think I
need to modify my path outside of python first? Could my issues be related
to the fact that my python packages are managed through conda? I'm hoping
to get past this error before reverting APSIM versions since I have some
model files I need to do testing on that aren't compatible with the older
version.
from apsimNGpy.core.config import apsim_bin_context
NameError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from apsimNGpy.core.config import apsim_bin_context
File ~\miniconda3\Lib\site-packages\apsimNGpy_*init*_.py:1
----> 1 from apsimNGpy.core.config import set_apsim_bin_path,
get_apsim_bin_path, locate_model_bin_path
3 *all* = [set_apsim_bin_path, get_apsim_bin_path, locate_model_bin_path]
5 CURRENT_BIN = get_apsim_bin_path()
File ~\miniconda3\Lib\site-packages\apsimNGpy\core\config.py:379
373 logger.info(f"APSIM binary path set to '{validated_bin}'.")
375 return True
378 @cache
--> 379 def apsim_version(bin_path=get_apsim_bin_path(), release_number:
bool = False, verbose: bool = False):
380 """
381 Display version information of the APSIM model currently
382 in the apsimNGpy config environment. runs externally through
subprocess module
(...) 399 '2025.8.7844.0'
400 """
401 try:
File ~\miniconda3\Lib\site-packages\apsimNGpy\core\config.py:270, in
get_apsim_bin_path()
267 pass # we are not interested in raising at this point
268 return apsim_bin_path
--> 270 return _get_bin()
File ~\miniconda3\Lib\site-packages\apsimNGpy\core\config.py:260, in
get_apsim_bin_path.._get_bin()
258 if not exists(apsim_bin_path):
259 auto_path = auto_detect_apsim_bin_path()
--> 260 create_config(CONFIG_PATH, apsim_path=auto_path)
261 return auto_path
262 if apsim_bin_path:
263 # make sure it has the required binaries
File ~\miniconda3\Lib\site-packages\apsimNGpy\settings.py:23, in
create_config(config_path, apsim_path)
22 def create_config(config_path, apsim_path=""):
---> 23 _CONFIG = create_bin_paths_used(config_path, apsim_path)
24 _CONFIG['Paths'] = {'APSIM_LOCATION': apsim_path}
25 with open(config_path, 'w') as configured_file:
File ~\miniconda3\Lib\site-packages\apsimNGpy\settings.py:36, in
create_bin_paths_used(config_path, apsim_path)
34 pp = _CONFIG['PreviousPaths']
35 prev = pp.get('BINS', "[]")
---> 36 binS = set(eval(prev))
37 BINS = [i for i in binS if os.path.exists(i)]
38 BINS = list(dict.fromkeys(BINS))
File :1
NameError: name 'WindowsPath' is not defined
—
Reply to this email directly, view it on GitHub
<#35 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZHIYYDMKMMXVBNRKMVDOL34AHGEXAVCNFSM6AAAAACOC2NYC6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTKMJXGU3DMMQ>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
|
Is there an alternative of pip cache purge with anaconda, it always clear
env caches for me.
…On Fri, Dec 5, 2025 at 1:47 PM spencercole6-ops ***@***.***> wrote:
When I initially tried with the newer APSIM version I was able to run the
models but was getting that other error when trying to edit things (AttributeError:
'Simulations' object has no attribute 'FindAllDescendants'). So
originally I didn't get the path error, but I attempted to revert to an
older APSIM version and started getting this new path error. After
returning to the newer APSIM version I still get the path error when trying
to load anything related to apsimNGpy.
I'll try reinstalling my apsimNGpy to get the new version now.
Thank you!
—
Reply to this email directly, view it on GitHub
<#35 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZHIYYHOUL5YBFGTQWZRNK34AHONTAVCNFSM6AAAAACOC2NYC6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTKMJXGYYDINY>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
|
Can you please share your folder structure where you are running the
software
…On Fri, Dec 5, 2025 at 2:04 PM spencercole6-ops ***@***.***> wrote:
I tried using a fresh install of apsimNGpy and received the same path
error. There is a cache purge alternative for conda, conda clean which I
just tried. Didn't seem to fix my issue.
—
Reply to this email directly, view it on GitHub
<#35 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZHIYYEW2OK5WZ65VNMIPBT4AHQOXAVCNFSM6AAAAACOC2NYC6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTKMJXGYYTIOA>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
|
Try to create a new virtual environment away from your current working
directory
…On Fri, Dec 5, 2025 at 2:21 PM spencercole6-ops ***@***.***> wrote:
Do you mean where my apsimNGpy package is located?
My apsimNGpy package is located here:
C:\Users\spenc\miniconda3\Lib\site-packages\apsimNGpy
My actual APSIM model is located here: C:\Program Files\APSIM2025.11.7937.0
I also made sure to manually add C:\Program Files\APSIM2025.11.7937.0\bin
to my environment variables path but that did not solve my issue either.
—
Reply to this email directly, view it on GitHub
<#35 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZHIYYG77N2UQOA2GHCJUE34AHSN7AVCNFSM6AAAAACOC2NYC6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTKMJXGYZDONA>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
|
After reviewing your traceback carefully, here’s what I recommend:
from apsimNGpy.settings import CONFIG_PATH
import os
os.startfile(CONFIG_PATH)
This will clear any outdated APSIM paths that may be causing the issue. |
Beta Was this translation helpful? Give feedback.
-
|
You're welcome!
…On Mon, Dec 8, 2025 at 1:40 PM spencercole6-ops ***@***.***> wrote:
Great that works, thank you!
—
Reply to this email directly, view it on GitHub
<#35 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZHIYYBY2WA3LHUOTFYWTCL4AXH4DAVCNFSM6AAAAACOC2NYC6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTKMRQGE3DANI>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Dr. Magala,
I am new to the APSIM scene and have been running into several issues trying to run apsimNGpy on Windows. I am hoping you may be able to help me troubleshoot the issues I am encountering. So far I have not had any issues running the APSIM model itself from the GUI, just problems interfacing with the python package. I've tried two main methods for getting apsimNGpy to work with different results and errors as I'll explain below.
Part 1:
First, I retained the more recent version of APSIM (v2025.11.7929.0) that I had been running through the GUI and tried to run apsimNGpy. I manage my python packages through conda but since apsimNGpy is not available through conda channels I installed it via git in the command line using
pip install git+https://github.com/MAGALA-RICHARD/apsimNGpy.git. After installing, I tried loading and running an example wheat model using the following:from apsimNGpy.core.apsim import ApsimModel import pandas as pd import numpy as np wheat_example_path = "C:/Users/user/Downloads/Examples/Wheat.apsimx" model = ApsimModel(model=wheat_example_path) model.run(report_name='Report', verbose=True) results = model.resultsAnd the model ran without issue and I was able to view the results. However, when I started trying to modify or inspect the model following your tutorial pages online I started receiving an error. I tried several commands, including
model.inspect_model('Models.Manager', fullpath=True)and each time I got an error statingAttributeError: 'Simulations' object has no attribute 'FindAllDescendants'. This error seemed to occur when I tried doing anything other than loading and running the model. Unfortunately, because of the issue I'll explain in part 2 below I cannot currently reproduce the full traceback for the errors. If I recall correctly when troubleshooting I had also tried using an earlier release apsimNGpy but that didn't solve the issue either.Part 2:
Through trying to determine what was going on with my errors in part 1 I read that there were recent changes to the structure of APSIM that could interface poorly with apsimNGpy and had the idea of reverting to an earlier APSIM version (v2025.08.7842.0 - I saw in another discussion with here a Mac user that this version passed all tests) to see if that might solve the issue. I uninstalled my previous APSIM model and reinstalled the older version. Then upon trying to run
from apsimNGpy.core.apsim import ApsimModelI received a new errorNameError: name 'WindowsPath' is not defined. Here is the full traceback:from apsimNGpy.core.apsim import ApsimModel
NameError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from apsimNGpy.core.apsim import ApsimModel
File ~\miniconda3\Lib\site-packages\apsimNGpy_init_.py:1
----> 1 from apsimNGpy.core.config import set_apsim_bin_path, get_apsim_bin_path, locate_model_bin_path
3 all = [set_apsim_bin_path, get_apsim_bin_path, locate_model_bin_path]
5 CURRENT_BIN = get_apsim_bin_path()
File ~\miniconda3\Lib\site-packages\apsimNGpy\core\config.py:379
373 logger.info(f"APSIM binary path set to '{validated_bin}'.")
375 return True
378 @cache
--> 379 def apsim_version(bin_path=get_apsim_bin_path(), release_number: bool = False, verbose: bool = False):
380 """
381 Display version information of the APSIM model currently
382 in the apsimNGpy config environment. runs externally through subprocess module
(...) 399 '2025.8.7844.0'
400 """
401 try:
File ~\miniconda3\Lib\site-packages\apsimNGpy\core\config.py:270, in get_apsim_bin_path()
267 pass # we are not interested in raising at this point
268 return apsim_bin_path
--> 270 return _get_bin()
File ~\miniconda3\Lib\site-packages\apsimNGpy\core\config.py:260, in get_apsim_bin_path.._get_bin()
258 if not exists(apsim_bin_path):
259 auto_path = auto_detect_apsim_bin_path()
--> 260 create_config(CONFIG_PATH, apsim_path=auto_path)
261 return auto_path
262 if apsim_bin_path:
263 # make sure it has the required binaries
File ~\miniconda3\Lib\site-packages\apsimNGpy\settings.py:23, in create_config(config_path, apsim_path)
22 def create_config(config_path, apsim_path=""):
---> 23 _CONFIG = create_bin_paths_used(config_path, apsim_path)
24 _CONFIG['Paths'] = {'APSIM_LOCATION': apsim_path}
25 with open(config_path, 'w') as configured_file:
File ~\miniconda3\Lib\site-packages\apsimNGpy\settings.py:36, in create_bin_paths_used(config_path, apsim_path)
34 pp = _CONFIG['PreviousPaths']
35 prev = pp.get('BINS', "[]")
---> 36 binS = set(eval(prev))
37 BINS = [i for i in binS if os.path.exists(i)]
38 BINS = list(dict.fromkeys(BINS))
File :1
NameError: name 'WindowsPath' is not defined
I then tried to revert back to the newer version of APSIM again to deal with my initial error and upon doing so I am continuing to encounter this one
(NameError: name 'WindowsPath' is not defined). If you can share any thoughts you might have on how I might solve these issues I would really appreciate it!Thank you very much,
Spencer
Beta Was this translation helpful? Give feedback.
All reactions