#-------------------------------------------------------------------------------
#  [1] Homebrew initialization:
#
#      The four packages 1) Qt6, 2) Ruby, 3) Python, and 4) libgit2 are required.
#      A typical installation flow is shown below.
#-------------------------------------------------------------------------------
   $ brew install qt@6
   $ brew install ruby@3.4
   $ brew install python@3.14
   $ brew install libgit2

#---------------------------------------------------------------------------------------------------
#  [2] Installation process of different Python modules using 'pip':
#
#    This DMG is built with Homebrew python@3.14, where we cannot use the legacy "pip3" command.
#    More precisely, we will get the following errors, if we attempt.
#      $ python3 -m pip install pandas scipy matplotlib XlsxWriter openpyxl
#      error: externally-managed-environment
#
#      × This environment is externally managed
#      ╰─> To install Python packages system-wide, try brew install
#          xyz, where xyz is the package you are trying to
#          install.
#
#          If you wish to install a Python library that isn't in Homebrew,
#          use a virtual environment:
#
#          python3 -m venv path/to/venv
#          source path/to/venv/bin/activate
#          python3 -m pip install xyz
#
#          If you wish to install a Python application that isn't in Homebrew,
#          it may be easiest to use 'pipx install xyz', which will manage a
#          virtual environment for you. You can install pipx with
#
#          brew install pipx
#
#          You may restore the old behavior of pip by passing
#          the '--break-system-packages' flag to pip, or by adding
#          'break-system-packages = true' to your pip.conf file. The latter
#          will permanently disable this error.
#
#          If you disable this error, we STRONGLY recommend that you additionally
#          pass the '--user' flag to pip, or set 'user = true' in your pip.conf
#          file. Failure to do this can result in a broken Homebrew installation.
#
#          Read more about this behavior here: <https://peps.python.org/pep-0668/>
#
#      note: If you believe this is a mistake, please contact your Python installation or OS
#      distribution provider.
#      You can override this, at the risk of breaking your Python installation or OS,
#      by passing --break-system-packages.
#      hint: See PEP 668 for the detailed specification.
#
#    To avoid this error, use a virtual environment as suggested above.
#---------------------------------------------------------------------------------------------------
$ which pip3
/usr/local/opt/python@3.14/bin/pip3

$ pip3 list
Package           Version
----------------- -------
altgraph          0.17.5
delocate          0.13.0
macholib          1.16.4
ndiff             7.99
pip               26.1.2
typing_extensions 4.16.0
wheel             0.47.0

$ python3 -m venv $HOME/opt/HBPy314

$ source $HOME/opt/HBPy314/bin/activate

((HBPy314) ) $ pip3 install pandas scipy matplotlib XlsxWriter openpyxl klayout

((HBPy314) ) $ pip3 list

Package         Version
--------------- -----------
contourpy       1.3.3
cycler          0.12.1
et_xmlfile      2.0.0
fonttools       4.63.0
kiwisolver      1.5.0
klayout         0.30.9
matplotlib      3.11.1
numpy           2.5.1
openpyxl        3.1.5
packaging       26.2
pandas          3.0.5
pillow          12.3.0
pip             26.1.2
pyparsing       3.3.2
python-dateutil 2.9.0.post0
scipy           1.18.0
six             1.17.0
xlsxwriter      3.2.9

#-------------------------------------------------------------------------------
#  [3] Set the "KLAYOUT_PYTHONPATH" environment variable:
#      (Ref. https://www.klayout.de/forum/discussion/2557/)
#-------------------------------------------------------------------------------
The best approach is to create a script bundle (launching service Bash script),
as shown in "KLayoutHomebrew.app.Bash".

#-------------------------------------------------------------------------------
#  [4] Python module import test:
#
#      Run this sample python from "Macro Development" with such a sample CSV.
#-------------------------------------------------------------------------------
'''
# Enter your Python code here
import os
import numpy as np
import scipy
import matplotlib
import pandas as pd

sampleCSV = os.environ["HOME"] + "/KLayout/sampleCSV.csv"
df = pd.read_csv( sampleCSV, comment='#' )
print(df)
'''

== Output ==
      X[mm]  Y[mm]   Ratio[]
0       0.0    3.1  1.006617
1       2.7   -1.5  1.006607
2      -2.7   -1.5  1.006321
3       0.0    9.2  1.006651
4       5.9    7.0  1.006211
...     ...    ...       ...
1805  -30.3  140.7  0.994904
1806  -24.3  141.9  0.994266
1807  -18.3  142.8  0.994888
1808  -12.2  143.4  0.994146
1809   -6.1  143.8  0.993552

[1810 rows x 3 columns]

#------------------
# End of File
#------------------
