Build Dummy Example Failed in MacOS M1 · Issue #318 · go-python/gopy · GitHub
Skip to content

Build Dummy Example Failed in MacOS M1 #318

Open

Description

@dusty-cjh

ENV

MacOS 2020 M1 chip

python3.9 (system)

Replication

# prepare
mkdir dummy && cd dummy
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
go env -w GOBIN="/usr/local/go/bin/"

# init project and install as python package
go mod init dummy.com/dum
go get github.com/go-python/gopy/_examples/hi

# error happened here
gopy build -output=out -vm=python3 github.com/go-python/gopy/_examples/hi

Output:

--- Processing package: github.com/go-python/gopy/_examples/hi ---

--- building package ---
gopy build -output=out -vm=python3 github.com/go-python/gopy/_examples/hi
goimports -w hi.go
go build -mod=mod -buildmode=c-shared -o hi_go.so .
cmd had error: exit status 1  output:
# dummy.com/dum/out
/usr/local/go/pkg/tool/darwin_arm64/link: running clang failed: exit status 1
ld: warning: directory not found for option '-L/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib'
ld: library not found for -lpython3.9
clang: error: linker command failed with exit code 1 (use -v to see invocation)


2023/03/19 13:35:14 error dispatching command: exit status 1

Questions

The path /App****/Python3.framework/Versions/3.9/lib actually doesn't exist in my PC, so I think maybe it's because somewhere point to a wrong $PATH.

I found where the true python lib path is, and added it to $PATH, since this error seems due to lib not in the path:

sudo find /Library -name "python*"

# so here I got the python3 lib path in my PC
export PATH=/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib:$PATH

# re-run
gopy build -output=out -vm=python3 github.com/go-python/gopy/_examples/hi

# still the error output
--- Processing package: github.com/go-python/gopy/_examples/hi ---

--- building package ---
gopy build -output=out -vm=python3 github.com/go-python/gopy/_examples/hi
goimports -w hi.go
go build -mod=mod -buildmode=c-shared -o hi_go.so .
cmd had error: exit status 1  output:
# dummy.com/dum/out
/usr/local/go/pkg/tool/darwin_arm64/link: running clang failed: exit status 1
ld: warning: directory not found for option '-L/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib'
ld: library not found for -lpython3.9
clang: error: linker command failed with exit code 1 (use -v to see invocation)


2023/03/19 13:49:54 error dispatching command: exit status 1

Am I doing any step wrong? could you give me some advice, thanks! 😊

Activity

  1. jieya907 commented on May 25, 2023

    @jieya907

    I got around this by passing the absolute path for the python binary to the -vm flag

  2. jieya907 commented on May 25, 2023

    @jieya907

    But the error I'm seeing is

    ld: warning: ignoring file /Users/somename/miniconda3/lib/libpython3.10.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
    Undefined symbols for architecture x86_64:
      "_PyComplex_AsCComplex", referenced from:
          __cgo_19fe0cd99635_Cfunc_PyComplex_AsCComplex in 000001.o
         (maybe you meant: __cgo_19fe0cd99635_Cfunc_PyComplex_AsCComplex)
      "_PyComplex_FromDoubles", referenced from:
          __cgo_19fe0cd99635_Cfunc_PyComplex_FromDoubles in 000001.o
         (maybe you meant: __cgo_19fe0cd99635_Cfunc_PyComplex_FromDoubles)
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)```
    
    Should we maybe pass in some flags specifically for arm?
    
  3. saurav-orca commented on Sep 26, 2024

    @saurav-orca

    Can you try setting the env variable - ARCHFLAGS=-arch arm64?
    Also try GOARCH=arm64 and GOOS=darwin

  4. b-long commented on Apr 2, 2025

    @b-long
    Member

    Hi all 👋

    Something that may help, is a cookiecutter for gopy. I've created one (it isn't perfect, but it is essentially the same code that I'm using for two projects).

    Here's the cookiecutter I built:

    macOS and M1 (ARM64)

    Currently, this cookiecutter is cross-platform for macOS and Linux. The build, test, and publishing all works and you can see real examples in the projects below.

    The builds for ARM64 work just fine 👍 🙂

    Projects based on this structure

    My two projects (published to pypi.org) based on the above project structure are here:

    They are only pushing python 3.11 and 3.12 wheels, but since I'm using Github's matrix style builds, it only takes a line or two change to experiment.

    Please feel free to open PRs or experiment with any of the above and please share any experimenting that you do publicly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions