SDK and Python 3, errors and improvements

3 posts / 0 new
Last post
solarjoe
SDK and Python 3, errors and improvements

Hello Paul,

I came across the same issue mentioned in this post, also using Python 3.3 in Win7-64bit.
https://sam.nrel.gov/content/sscdll-python-error

OSError: [WinError 126] The specified module could not be found.

I tried several approachs, none except placing the script and the
dll in the same folder worked.

Checking for the files is True both times:

print(os.path.isfile("C:/temp/sam-sdk-2014-11-24/win64/ssc.dll"))
True

print(os.path.isfile("../../win64/ssc.dll"))
True

Loading the CDLL fails both times:

self.pdll = CDLL("../../win64/ssc.dll")
OSError: [WinError 126] The specified module could not be found.

self.pdll = CDLL("C:/temp/sam-sdk-2014-11-24/win64/ssc.dll")
OSError: [WinError 126] The specified module could not be found.

putting the py script in the same directory as the dll and using
self.pdll = cdll.LoadLibrary("ssc.dll")
works.

Also does changing Python's current working directory to the folder with the ssc.dll

Still strange...

After this was working I started porting the script to Python 3:

- replacing print with print()
- convert value to bytes: c_char_p(value) with c_char_p(value.encode()), due to the bytes-string-issue
- convert returned c_char_p to strings, e.g. t.decode('utf-8')

Step by step the script started working,
but there is an invalid character (no UTF-8) somewhere.

Using the simtest() fails while listing the input variable 'inv_snl_paco':

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x91 in position 19: invalid start byte

e.g. for 'inv_snl_c3' the printed result is

Input: 'inv_snl_c3' type(2) Empirical coefficient allowing Co to vary linearly with dc-voltage input, default value is zero, (1/V) (xxx)

It is not urgent, but if you could look into this and I get the script to work I could provide it to you.
I guess Python 3 will be the future, no matter what the 2.7 people tell :)

Another thing that should be fixed is the use of the variable name "type"

type = c_int()

in the script, which is a Python keyword.

Kind regards,
Joe

Paul Gilman

Hi Joe,

Thanks for this. We will look into it.

Best regards,
Paul.

Paul Gilman

Hi Joe,

Your solution for the location of the DLL file should help others trying to use the SDK with Python 3. For now, the SDK supports Python 2.7, but we may change that in a future version.

We searched for unicode characters in source code and other files and did not find any. Would you mind sending us a copy of your script for troubleshooting? You can either attach it to your original post above, or email it to me at sam dot support at nrel dot gov.

We did update the Python wrapper to not use the "type" keyword. If you download the SDK now, it should have the updated wrapper. (We are not updating SDK version numbers for these relatively minor fixes, so the SDK .zip file name is the same as it was before.)

Best regards,
Paul.

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer