#-------------------------------------------------------------------------------
#  [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.13
   $ brew install libgit2

#---------------------------------------------------------------------------------------------------
#  [2] Installation process of different Python modules using 'pip':
#
#    This DMG is built with Homebrew python@3.13, 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.13/bin/pip3

$ pip3 list
Package Version
------- -------
pip     25.1.1
wheel   0.45.1

$ python3 -m venv $HOME/opt/HBPy313

$ source $HOME/opt/HBPy313/bin/activate

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

((HBPy313) ) $ pip3 list

Package           Version
----------------- ------------
contourpy         1.3.3
cycler            0.12.1
fonttools         4.60.1
kiwisolver        1.4.9
klayout           0.30.4.post1
lxml              6.0.2
matplotlib        3.10.7
numpy             2.3.4
packaging         25.0
pandas            2.3.3
pillow            12.0.0
pip               25.3
pyparsing         3.2.5
PyPDF2            3.0.1
python-dateutil   2.9.0.post0
python-pptx       1.0.2
pytz              2025.2
PyYAML            6.0.3
scipy             1.16.3
setuptools        80.9.0
six               1.17.0
typing_extensions 4.15.0
tzdata            2025.2
unoconv           0.9.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
#------------------
