I cloned LEAN repo and went through the steps required to build the solution locally. I'm able to run BasicTemplateFrameworkAlgorithm via Launcher so things seem to be working fine.
What I'm struggling with is the Tests project: there seem to be 2 different issues:
- Errors like "LocalDiskMapFileProvider.GetMapFileResolver(sgx): The specified directory does not exist: ../../../Data/equity/sgx/map_files"
- And exception “GIL must always be released”
Tried looking for the solution, but couldn't find any documentation on setting up the data source for the tests (generating data via lean data generate didn't help), and the Python related GIL error is somewhat too generic.
Full log below:
========== Test discovery aborted: 0 Tests found in 17.9 sec ==========
Building Test Projects
Starting test discovery for requested test run
========== Starting test discovery ==========
NUnit Adapter 4.6.0.0: Test discovery starting
20250614 22:51:03.187 TRACE:: Config.Get(): Configuration key not found. Key: plugin-directory - Using default value:
20250614 22:51:03.196 TRACE:: Config.Get(): Configuration key not found. Key: composer-dll-directory - Using default value:
20250614 22:51:03.197 TRACE:: Composer(): Loading Assemblies from D:\Projects\Lean\Tests\bin\Debug\
20250614 22:51:03.287 TRACE:: Config.GetValue(): zip-data-cache-provider - Using default value: 10
20250614 22:51:03.291 TRACE:: Config.Get(): Configuration key not found. Key: databases-refresh-period - Using default value: 1.00:00:00
20250614 22:51:03.307 TRACE:: Config.Get(): Configuration key not found. Key: version-id - Using default value:
20250614 22:51:03.307 TRACE:: Config.Get(): Configuration key not found. Key: cache-location - Using default value:
20250614 22:51:03.309 TRACE:: Config.GetValue(): project-id - Using default value: 0
20250614 22:51:03.309 TRACE:: Config.Get(): Configuration key not found. Key: api-url - Using default value: https://www.quantconnect.com/api/v2/
20250614 22:51:03.309 TRACE:: Config.Get(): Configuration key not found. Key: results-destination-folder - Using default value: D:\Projects\Lean\Tests\bin\Debug
20250614 22:51:03.309 TRACE:: Config.Get(): Configuration key not found. Key: version-id - Using default value:
20250614 22:51:03.309 TRACE:: Config.Get(): Configuration key not found. Key: cache-location - Using default value:
20250614 22:51:03.309 TRACE:: Config.GetValue(): project-id - Using default value: 0
20250614 22:51:03.309 TRACE:: Config.Get(): Configuration key not found. Key: api-url - Using default value: https://www.quantconnect.com/api/v2/
20250614 22:51:03.309 TRACE:: Config.Get(): Configuration key not found. Key: results-destination-folder - Using default value: D:\Projects\Lean\Tests\bin\Debug
20250614 22:51:03.309 TRACE:: Config.GetValue(): debug-mode - Using default value: False
20250614 22:51:03.309 TRACE:: Config.Get(): Configuration key not found. Key: python-venv - Using default value:
20250614 22:51:03.310 TRACE:: PythonInitializer.Initialize(): start...
20250614 22:51:03.431 TRACE:: Config.GetValue(): downloader-data-update-period - Using default value: 7
20250614 22:51:04.299 TRACE:: PythonInitializer.Initialize(): start...
20250614 22:51:04.327 TRACE:: Extensions.IsDirectoryEmpty(): directory '../../../Data/equity/sgx/map_files' not found or empty
20250614 22:51:04.328 ERROR:: LocalDiskMapFileProvider.GetMapFileResolver(sgx): The specified directory does not exist: ../../../Data/equity/sgx/map_files
Unhandled exception. System.InvalidOperationException: GIL must always be released, and it must be released from the same thread that acquired it.
at Python.Runtime.Py.GILState.Finalize()
at System.GC.RunFinalizers()
The active test discovery was aborted. Reason: Test host process crashed : 20250614 22:51:04.328 ERROR:: LocalDiskMapFileProvider.GetMapFileResolver(sgx): The specified directory does not exist: ../../../Data/equity/sgx/map_files
Unhandled exception. System.InvalidOperationException: GIL must always be released, and it must be released from the same thread that acquired it.
at Python.Runtime.Py.GILState.Finalize()
at System.GC.RunFinalizers()
Mia Alissi
Here's how "Val" can resolve the two issues seen when running the LEAN Tests project:
1. Error: Map File Directory Not Found (
sgx/map_files
)Reason:
LEAN's unit/integration tests expect equity map files to exist at a relative path from the test project's working directory, typically:
../../../Data/equity/sgx/map_files
Solution:
Data/equity/sgx/map_files
(matching casing)..csv
or.zip
files as placeholder content for SGX securities, or copy them from QuantConnect's data repo if available.SGX123.csv
is sufficient.2. Python GIL Exception During Test Discovery
Reason:
This error typically appears when:
Solution:
Many test runners support a
--no-parallel
or equivalent option.Example (NUnit):
Ensure your local Python version is compatible with the pythonnet version in the LEAN repo.
python-venv
is required, set inconfig.json
or activate before test discovery.After resolving missing data errors, clean/rebuild the solution and restart the test runner.
Checklist
Lean/Data/equity/sgx/map_files
exists, with at least one CSV file (even empty).pythonnet
are compatible with LEAN's requirements—activate any relevant venv before testing.References
If You Continue to See GIL Errors
/Data
is found).Summary:
Fixing the missing directory and file should eliminate the initial error and, by avoiding interruption of Python's initialization, also resolve the GIL crash. Disabling test parallelism circumvents thread/GIL issues inherent to Python and .NET interop during testing.
If you need more help, let me know which test runner and OS you're using and I can provide more targeted commands!
Sources: Results - QuantConnect.com
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Val Solo
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!