Error while importing Python/PythonKit in colab

72 views
Skip to first unread message

Kshitij Patil

unread,
Mar 11, 2020, 3:27:31 PM3/11/20
to Swift for TensorFlow
I was exploring the tutorial notebooks and while working on Python Interoperability notebook, the very first block of code to import Python caused following error:

```
error: <Cell 4>:2:1: error: unexpected conditional compilation block terminator #else ^ error: <Cell 4>:4:1: error: unexpected conditional compilation block terminator #endif ^
```

I don't how this worked but I literally typed the same code in a new block
#if canImport(PythonKit)
 
import PythonKit
#else
 
import Python
#endif
print(Python.version)

and it worked. I'm guessing there might be some indentation issue.

I'm new here. So please let me know whether this is the right place to share code errors and should I create new topic when any relevant discussion is not found?


emat...@google.com

unread,
Mar 12, 2020, 12:54:45 AM3/12/20
to Swift for TensorFlow, kshitij...@gmail.com
Hi,

I can reproduce your issue.  It seems to be fixed if you add "import TensorFlow" at the beginning of the block but I'm not quite sure yet why that is required.

Sending an email to this list is ok but filing a Github issue at https://github.com/tensorflow/swift/issues.  I filed one for you here: https://github.com/tensorflow/swift/issues/405.

Thank you for reporting this!

Ewa
Reply all
Reply to author
Forward
0 new messages