-
Notifications
You must be signed in to change notification settings - Fork 50
Building from Source
If this is your first time building NREL-PySAM from source, you will need to build the SAM_api libraries. In order to do this, run the SAM build steps with the following modifications:
-
When cloning repositories (step 5.2), also clone pysam (this repository) in the same directory. The cloned folder should be named pysam.
-
When setting environment variables (step 6.3), add one additional variable for pysam:
PYSAMDIR ...\sam_dev\pysam -
Build SAM_api
Create a build folder and change directory to it.
-
Windows
Run the CMake command to generate the visual studio solution:
cmake -G "Visual Studio 17 2022" -DCMAKE_CONFIGURATION_TYPES="Debug;Release" -DCMAKE_SYSTEM_VERSION=10.0 -DSAM_SKIP_TOOLS=1 -DSAM_SKIP_TESTS=1 -DSAMAPI_EXPORT=1 -DSAM_SKIP_AUTOGEN=1 -DSAMPRIVATE=0 ..
Start VS 2022 and open the system_advisor_model.sln solution file. You only need to build the SAM_api project in the Release configuration. Doing an entire build including exporting the API takes upwards of 45 minutes.
Alternatively, run the build from command line:
devenv /build Release system_advisor_model.sln /Project SAM_api
-
Linux and Mac
cmake .. -DCMAKE_BUILD_TYPE=Release -DSAMAPI_EXPORT=1 -DSAM_SKIP_AUTOGEN=1 cmake --build . --target SAM_api -j 6
-
Once the build is finished, you should have the SAM and ssc libraries relevant to your system (libssc.so
and libSAM_api.so
on Unix and ssc.dll, ssc.lib
and SAM_api.dll, SAM_api.lib
on Windows) in the folder pysam/files
Once you have completed the first time setup, you are ready to install pysam in your local Python environment.
From the pysam folder, run:
python -m pip install .
This will compile the pysam c files, and copy files from the SAM API into files/defaults. In order to test the installation, run:
pip install -r tests/requirements.txt
pytest -s tests
The shell scripts build_unix.sh
is intended to be run on a Mac with Docker installed. build_unix.sh
will build the distributions for Mac then use a manylinux1
container to run build_manylinux.sh
. The resulting .whl
files will be in pysam/dist
.
On Windows, the batch script build_win.bat
accomplishes the same.