Skip to content

spa_c_files don't build with VC14 (Python 3.5) #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mikofski opened this issue May 13, 2016 · 13 comments · Fixed by #576
Closed

spa_c_files don't build with VC14 (Python 3.5) #168

mikofski opened this issue May 13, 2016 · 13 comments · Fixed by #576
Labels
Milestone

Comments

@mikofski
Copy link
Member

windows 7 amd64
Cython (0.24)
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32

if I try to build spa_c for Python-3.5 I get the following:

$ py -3.5 setup.py build_ext --inplace
running build_ext
building 'spa_py' extension
creating build
creating build\temp.win-amd64-3.5
creating build\temp.win-amd64-3.5\Release
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Python35\include -IC:\Python35\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\\winrt" /Tcspa_py.c /Fobuild\temp.win-amd64-3.5\Release\spa_py.obj
spa_py.c
c:\users\mmikofski\documents\projects\pvlib-python\pvlib\spa_c_files\spa.h(88): error C2032: '__timezone': function cannot be member of struct '<unnamed-tag>'
spa_py.c(854): error C2059: syntax error: '('
spa_py.c(1700): error C2059: syntax error: '('
spa_py.c(1702): error C2275: 'PyObject': illegal use of this type as an expression
c:\python35\include\object.h(110): note: see declaration of 'PyObject'
spa_py.c(1702): error C2059: syntax error: ')'
spa_py.c(1702): error C2223: left of '->ob_refcnt' must point to struct/union
spa_py.c(1702): error C2065: '_py_decref_tmp': undeclared identifier
spa_py.c(1702): warning C4312: 'type cast': conversion from 'int' to 'PyObject *' of greater size
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\amd64\\cl.exe' failed with exit status 2
@wholmgren
Copy link
Member

It's been a long time since I used spa_c, and I don't have any experience with Visual Studio, so I don't have any hints for you there. However, I'll point out that the benchmarks in #48 show that spa_python+numpy and spa_c are essentially the same speed, and spa_python+numba is significantly faster than spa_c. As with many benchmarks, your mileage may vary.

@wholmgren
Copy link
Member

wholmgren commented Sep 12, 2018

@mikofski ok to close this? while it may still be a bug with pvlib it may now be irrelevant after 2 years of default tooling changes

@mikofski
Copy link
Member Author

No I'm still looking into it, I just ran it again in a fresh Python-3.7 environment, and I still get the exact same error, so no I don't think we should close it just yet, b/c we need to consider if we want to include spa-c-files at all, if we close this issue, then we should remove the folder, and be done. Maybe this can become a standalone project, perhaps I can add it to SolarUtils and try using ctypes instead of cython?

One thing, we can definitely delete the spa_py.c file from the repository, as this is a cython generated file, and was probably committed by accident.

@wholmgren
Copy link
Member

Thanks for checking Mark. I'd be happy to see it move to another repository. We could still keep the wrapper option in pvlib.solarposition.py just like we do for pyephem.

I believe we include spa_py.c because it allows people to compile the package with only a c compiler and not cython.

@mikofski
Copy link
Member Author

mikofski commented Sep 12, 2018

I don't think that works, that file spa_py.c is generated by cython and requires cython to compile. Anyway, it doesn't work.

I just compiled spa.c, spa.h, and spa_tester.c to spa_tester.exe using visual studio 2015 (which AFAIK is used on Windows for Python >3.5) and it really does work,

>cl /Fobuild\ /Febuild\spa_tester.exe spa.c spa_tester.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.15.26726 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

spa.c
spa_tester.c
Generating Code...
Microsoft (R) Incremental Linker Version 14.15.26726.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:build\spa_tester.exe
build\spa.obj
build\spa_tester.obj



>build\spa_tester.exe
Julian Day:    2452930.312847
L:             2.401826e+01 degrees
B:             -1.011219e-04 degrees
R:             0.996542 AU
H:             11.105902 degrees
Delta Psi:     -3.998404e-03 degrees
Delta Epsilon: 1.666568e-03 degrees
Epsilon:       23.440465 degrees
Zenith:        50.111622 degrees
Azimuth:       194.340241 degrees
Incidence:     25.187000 degrees
Sunrise:       06:12:43 Local Time
Sunset:        17:20:19 Local Time

so I think the issue is in the supporting Cython code: cspa_py.pxd and spa_py.pyx, maybe I can figure out (haven't yet), but It might just be easier to drop cython and just use ctypes or cffi, if cython is the issue. Anyway, that would be a concern for what ever project then picked this up, if you decided to boot it, which I'm in favor of to expedite closure of this issue. 😉

@wholmgren
Copy link
Member

It was supposed to work like this from the cython docs.

Maybe the upcoming SSC release will make this wrapper pointless.

I say we continue to ignore it for now.

@mikofski
Copy link
Member Author

OK, I figured it out, but I'll never understand why. For some reason, Cython does not like the keyword timezone which is okay with VisualStudio but not Python.

Replacing timezone with time_zone everywhere solves the problem

@wholmgren
Copy link
Member

How did you find that???

Do you want to sneak this into 0.6.0? I'm going to let #575 sit until tomorrow.

mikofski added a commit to mikofski/pvlib-python that referenced this issue Sep 12, 2018
* closes pvlib#168
* get source and header in setup.py
* replace "timezone" with "timezone" to fix the bug
* also update readme
* also remove a lot of extra whitespace and tabs

Signed-off-by: Mark Mikofski <[email protected]>
@mikofski
Copy link
Member Author

mikofski commented Sep 12, 2018

  • Done, but how do you want to test that this actually works?
  • Also, I don't think my fix is safe for python-2.7 is that okay?

@wholmgren
Copy link
Member

Done, but how do you want to test that this actually works?

take your word on it

Also, I don't think my fix is safe for python-2.7 is that okay?

ok with me, but update the readme in that subpackage accordingly.

@mikofski
Copy link
Member Author

here's the test output, LGTM:

>>> spa_calc(year=2004, month=10, day=17, hour=12, minute=30, second=30, time_zone=-7, longitude=-105.1786, latitude=39.742476, elevation=1830.14, pressure=820, temperature=11, delta_t=67)

{'year': 2004,
 'month': 10,
 'day': 17,
 'hour': 12,
 'minute': 30,
 'second': 30.0,
 'delta_ut1': 0.0,
 'delta_t': 67.0,
 'time_zone': -7.0,
 'longitude': -105.1786,
 'latitude': 39.742476,
 'elevation': 1830.14,
 'pressure': 820.0,
 'temperature': 11.0,
 'slope': 30.0,
 'azm_rotation': -10.0,
 'atmos_refract': 0.5667,
 'function': -1984328928,
 'e0': 39.59209464796398,
 'e': 39.60858878898177,
 'zenith': 50.39141121101823,
 'azimuth_astro': 14.311961805946808,
 'azimuth': 194.3119618059468,
 'incidence': 6.95264798328736e-310,
 'suntransit': 8.648152507504e-312,
 'sunrise': 1.6578093e-316,
 'sunset': 2.67e-322}

@wholmgren wholmgren added bug and removed wontfix labels Sep 12, 2018
@wholmgren wholmgren modified the milestones: Someday, 0.6.0 Sep 12, 2018
mikofski added a commit to mikofski/pvlib-python that referenced this issue Sep 13, 2018
* git rm spa_py.c to remove it from repo
* add cython to option extra requires
* use full paths in spa_c_files for sources
* add line to bug fixes addressing pvlib#168
cwhanse pushed a commit that referenced this issue Sep 16, 2018
* BUG: ENH: update spa_files to patch timezone bug

* closes #168
* get source and header in setup.py
* replace "timezone" with "timezone" to fix the bug
* also update readme
* also remove a lot of extra whitespace and tabs

Signed-off-by: Mark Mikofski <[email protected]>

* ENH: add no Python-2.7 to spa_c_files README

* add enumeration for function type, it was reading garbage, so you
never new exacton which calculations SPA was doing, and you would get
garbage values for incidence, sunrise, transit, and sunset times
* set function SPA_ALL, and pass extra args in as optional keyword args
for slope, delta_ut1, azm_rotation, and atmos_refract
* add example file that user can run to test build

* ENH: mention test exampleg, fix azm_rotation typo

* ENH: fix link, force reader to accept license, wrap long lines, update email, (c)

* ENH: ask user for their name, fail ungracefully

* ENH: get all information to submit to DOE

* use timezone as arg, change output to timezone

* add comment about __timezone macro, use consistent API in spa_calc for args and returns

* oops accidently deleted spa_py.c

* ENH: ignore cython generated spa_py.c file

* git rm spa_py.c to remove it from repo
* add cython to option extra requires
* use full paths in spa_c_files for sources
* add line to bug fixes addressing #168

* remove autodownload, revert readme

* with the function

* respond to comments

* explain that timezone is replaced with time_zone in spa_c docstring to avoid nameclash due to Python bug 24643 
* explain why time_zone column renamed to timezone to match caller API

* Copy the comment from solarposition.py

* that explains that we replace timezone with time_zone at build

* Python>=3.5

* wrap long lines
@solarjoe
Copy link

@mikofski

I have exactly the same problem, but I don't think that Cython is to blame. I am using cffi in combination with the original spa.h and spa.c, so without Cython.

Any idea what might be the reason then?

@solarjoe
Copy link

Nevermind, found it :)

https://bugs.python.org/issue24643

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants