-
Notifications
You must be signed in to change notification settings - Fork 74.7k
Fix Python 3 compilation issues #764
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
Conversation
Can one of the admins verify this patch? |
@@ -16,6 +16,12 @@ limitations under the License. | |||
#ifndef TENSORFLOW_PYTHON_LIB_CORE_PY_FUNC_H_ | |||
#define TENSORFLOW_PYTHON_LIB_CORE_PY_FUNC_H_ | |||
|
|||
#if NUMPY_IMPORT_ARRAY_RETVAL == NULL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment to explain why this is necessary? Something like "The return type of import_array() changed between Python 2 and 3"
Jenkins, test this please. |
I'll merge once you add the comment, and squash the commits (or amend the existing one). |
I take that back, your other problem may well be related. The #if thing must not be in the header (since we will not know about NUMPY_IMPORT_ARRAY_RETVAL until after numpy/arrayobject.h has been included). Move it to the c file, below the includes, and you should be fine. |
I fixed it and added the comment, but it still does not build under Linux. The build breaks at the same place as it broke before the fix, and I could not figure out what happened as the error message returned by bazel only states which rule and command failed. I will test on OS X right now. |
Jenkins, test this please. |
Fortunately, the Jenkins build produced a decent enough error message -- can you see if that's related to your failure or even the same? |
Yes, it seems to be the same issue. |
Error is enlightening: tensorflow/python/lib/core/py_func.cc:29:31: error: operator '==' has no left operand Checking for empty defines is nasty business, look at this: http://stackoverflow.com/questions/3781520/how-to-test-if-preprocessor-symbol-is-defined-but-has-no-value |
I was expecting the error message to be below the red "ERROR" message, not above it. Now it's clear! Would it be acceptable to use PY_MAJOR_VERSION for the comparison instead of NUMPY_IMPORT_ARRAY_RETVAL, just to avoid adding macro black magic just for this? I think it will make the code clearer. |
I fixed this by using PY_MAJOR_VERSION (as mentioned above), but now there's another build error that is not related to this code:
|
Can you fix it in tf_session the same way it's fixed in base.i? I think that's the right thing to do. Might as well make this PR "Fix Python 3 compilation issues" since we're almost there already. |
This is now fixed but the build is still breaking with the same error:
Since I have both Python 2 and 3 installed, is there a chance bazel is passing the wrong includes/libs to GCC? I tried cleaning and reconfiguring the build to no avail. |
Jenkins, test this please. |
Just making another log for myself. :) |
I guess the problem was having both Python 2 and 3, since tests passed on Linux and Android but not Mac? I don't know how the environment used by Jenkins looks like, but I'm on Ubuntu 14.04 with python-dev and python3-dev installed. |
The Mac build is broken right now, unrelated to this. :/ It's strange because the compiler shouldn't even see the PyString_ version any more. Can you remove the ifdef altogether (and keep only the Py3 branch) and see if that works compiling with Python3? Those two are the only occurrences of this function, so I feel like for some reason the ifdef doesn't work as expected (maybe because it's evaluated by swig, and we need a %{ %} around it). |
Removing the Python 2 only branches works. According to the docs SWIG should not mess with C preprocessor stuff, but it seems that's wrong :) I think |
To add to the weirdness of this issue: something (maybe SWIG?) adds the following macros to pywrap_tensorflow.cc:
These should be defined and avoid the issue without any other workarounds but that never happens, which probably means both PY_VERSION_HEX and PY_MAJOR_VERSION are not defined correctly. The script in |
I see that this list conspicuously does not include Maybe this is a swig problem? What version of swig is this, and does On Wed, Jan 13, 2016 at 3:08 PM João Felipe Santos notifications@github.com
|
I guess I was too tired and did not see My Linux box is on Ubuntu 14.04, which ships SWIG 2.0.11, but with SWIG 3.0.8 on my Mac I got the same auto-generated macros. However, SWIG's at fault: if you check line 208 on Code in
Code in
Turns out SWIG was preprocessing the |
Splendid. Can you squash, please? |
Jenkins, test this please. |
Using PY_MAJOR_VERSION instead of NUMPY_IMPORT_ARRAY_RETVAL Fixed SWIG interface for Python 3 support Make SWIG forward preprocessor directives to generated code
Done! |
Jenkins, test this please. |
Merged |
…pstream-deven-switch-to-rocm30 Switching from ROCm 2.8 to ROCm 3.0
This fixes the build error when using Python 3 as the return types for import array operations are int in Python 3 and void in Python 2 (as discussed in #733).