There’s no longer a need for any workaround. Swift-Colab, the successor to google/swift-jupyter, fully supports Google Drive integration. The easiest way to mount is in the same cell that installs Swift-Colab.
!curl "https://raw.githubusercontent.com/philipturner/swift-colab/release/latest/install_swift.sh" --output "install_swift.sh"
!bash "install_swift.sh" "5.6.1" #// Replace 5.6.1 with newest Swift version
#// After this command finishes, go to Runtime > Restart runtime.
#// Your code that was appended to this cell:
from google.colab import drive
drive.mount("/content/drive")
This works because you’re still running the built-in Python kernel. Thus, we can bypass the fact that the Swift kernel doesn’t support Google Drive integration. Once you restart the runtime, it switches to the JIT-compiled Swift kernel. If you restarted it prematurely, you’re covered as well. Just switch back to Python mode and mount the drive:
// Run this cell in Swift mode
%system echo "python" > "/opt/swift/runtime"
// Then restart the runtime
#// Run this cell in Python mode
from google.colab import drive
drive.mount("/content/drive")
!echo "swift" > "/opt/swift/runtime"
#// The restart the runtime
Regarding the first post on this thread, I haven’t identified whether the root cause involves pexpect
. I switched to using that library in Swift-Colab v2.1, and it allows much better I/O. But I did not create a mechanism for sending input to a process.
If anyone’s willing to investigate further, here’s the crash from attempting to install Google Drive while in Swift mode.
P.S. If anyone here would like to see SwiftAI active again, I’m trying to reach out to the FastAI organization: Swift for tensorflow seems dead · Issue #22 · fastai/swiftai · GitHub