Embedding Python & GoLang Codes Each Other

Embedding Python in GoLang

Introducing CGO

Embedding CPython


// #cgo pkg-config: python-2.7
package main

// #cgo pkg-config: python-2.7
import (
python "github.com/sbinet/go-python"

func main() {
python.PyRun_SimpleString("print 'hello, world!'")
package mainimport "github.com/DataDog/go-python3"

func main() {
defer python3.Py_Finalize()
python3.PyRun_SimpleString("print('hello world')")

Embedding GoLang in Python

Build Go package as C shared library or object

go build -o main.so -buildmode=c-shared main.go

Some Notes About Shared Objects

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/batur/lib




DevOps & Software & Architect & Linux Geek — http://baturorkun.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Free C++ Programming In Ubuntu Certification Course

We Need Python

CS371p Fall 2021: Xuefei Zhao

The use of Strategy Design Pattern when developing a payment system in Laravel

Make your UI tests green again

CORS is not your nightmare! But …

GNOME Software 3.32: Mission Failed ..and this is why

Confessions of a dependable coder: The Dark Art Of Regular Expressions

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Batur Orkun

Batur Orkun

DevOps & Software & Architect & Linux Geek — http://baturorkun.com

More from Medium

Combine many series in a DataFrame in GoLang.

Python vs Go: Which One Is Better For You In 2022?

Variables in Python and GO.

How to Remove EXIF Data from an Image in Go