realpython / realpython/materials

Mac Mojave and Python 3.8 working branch

Offen
#108 8 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Jupyter Notebook
Sterne
5.2k
Forks
5.3k
Ø Merge
4 T. 10 Std.
Gemergte PRs (30 T.)
10

Beschreibung

Hi, I have a branch to push to you with a working version of the python binding module
with Mac Mojave and Python 3.8 using python.org version of python, (not brew)

Cheers Dave.

Notes here;

help on python c binding

dependencies

install python3.8 from python.org

pip3 install pybind11
pip3 install invoke
pip3 install Cython

security block

mac mojave blocks relative pathed libraries, here is the fix

install_name_tool

def install_name_tool(dependent=None, depends=[]):
    '''
    make the lib full path to get around security blocking relative paths
    '''
    for dependson in depends:
        full_path = os.path.abspath(dependson)
        shell_str='install_name_tool -change {0} {1} {2}'.format(dependson, full_path, dependent)
        print('    install_name_tool: {0}'.format(dependson))
        invoke.run(shell_str)

mac G++ missing symbols

mac compile gets upset about missing symbols

ignore missing symbols on a mac

On Mac OS: the build command is almost the same but it also requires passing the -undefined dynamic_lookup flag so as to ignore missing symbols when building the module:

in task.py

def compile_python_module(cpp_name, extension_name):
    invoke.run(
        "g++ -O3 -Wall -Werror -shared -std=c++11 -fPIC "
        "`python3.8-config --includes` "
        "`python3 -m pybind11 --includes` "
        "-undefined dynamic_lookup "
        "-I . "
        "{0} "
        "-o {1}`python3.8-config --extension-suffix` "
        "-L. -lcppmult -Wl,-rpath,.".format(cpp_name, extension_name)
    )

compile and test

here is the output from a good compile and test run

$ invoke all
==================================================
= Building C Library 
* Complete
==================================================
= Testing ctypes Module 
    In cmult : int: 6 float 2.3 returning  13.8
    In Python: int: 6 float 2.3 return val 48.0

    In cmult : int: 6 float 2.3 returning  13.8
    In Python: int: 6 float 2.3 return val 13.8
==================================================
= Building CFFI Module 
    install_name_tool: libcmult.so
* Complete
==================================================
= Testing CFFI Module 
    In cmult : int: 6 float 2.3 returning  13.8
    In Python: int: 6 float 2.3 return val 13.8
==================================================
= Building C++ Library 
    install_name_tool: libcmult.so
    install_name_tool: cffi_example.cpython-38-darwin.so
* Complete
==================================================
= Building PyBind11 Module 
    install_name_tool: libcmult.so
    install_name_tool: cffi_example.cpython-38-darwin.so
    install_name_tool: libcppmult.so
* Complete
==================================================
= Testing PyBind11 Module 
    In cppmul: int: 6 float 2.3 returning  13.8
    In Python: int: 6 float 2.3 return val 13.8
==================================================
= Building Cython Module 
    install_name_tool: libcmult.so
    install_name_tool: cffi_example.cpython-38-darwin.so
    install_name_tool: libcppmult.so
* Complete
==================================================
= Testing Cython Module 
    In cppmul: int: 6 float 2.3 returning  13.8
    In Python: int: 6 float 2.3 return val 13.8

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie mit task.py und dem dokumentierten invoke all-Workflow; prüfen Sie anschließend, wie die C-, C++-, CFFI-, PyBind11- und Cython-Module erstellt und getestet werden. Reproduzieren Sie das gemeldete Python-3.8- und Mac-Mojave-Setup; abgeschlossen ist die Aufgabe, wenn der angeforderte Branch oder die dokumentierten Änderungen integriert sind und alle aufgeführten Modul-Builds und -Tests erfolgreich durchlaufen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
cpp, python
Bereich
build-system, devtools
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
28/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.