Installing from source code for Mac silicon

Hi,
I was able to install psi4 through the psi4conda installer command. However when I tried to install it from the source code following this docs & tools for building psi4 (status and survey) · Issue #2965 · psi4/psi4 · GitHub along side with Compiling and Installing from Source I was able to run cmake -S. -Bobjdir without any issues.

After compiling, I tried testing it with ctest -jgetconf _NPROCESSORS_ONLN and make pytest, but all the tests fails. I thought there was a conflict between the newly compiled code and the previously installed psi4 through the installer commands so I went ahead and uninstalled psi4 using conda uninstall psi4 and tried to build it again but when I try to configure it again with cmake -S. -Bobjdir I’m getting the error message:

CMake Error at /Users/alexyang/psi4conda/envs/baseenv/share/cmake-3.27/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Python (missing: Python_NumPy_INCLUDE_DIRS NumPy) (found
suitable version “3.9.18”, minimum required is “3.8”)
Call Stack (most recent call first):
/Users/alexyang/psi4conda/envs/baseenv/share/cmake-3.27/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
/Users/alexyang/psi4conda/envs/baseenv/share/cmake-3.27/Modules/FindPython/Support.cmake:3824 (find_package_handle_standard_args)
/Users/alexyang/psi4conda/envs/baseenv/share/cmake-3.27/Modules/FindPython.cmake:574 (include)
CMakeLists.txt:209 (find_package)

When I run python --version I get the version 3.10.13 and numpy 1.26.0 shows up when I run conda list.

Any help would be greatly appreciated.
Thank you

Excellent work trying to follow the directions. They’re sparse at the moment, and in fact build guides are what I’ve been working on today.

As you suspected, having a psi4 conda package and a from-source psi4 are going to be hard to disentangle. Usually what one does is have a miniconda installation and put all psi4’s dependencies into an environment (non-base), activate it, clone the psi4 source and compile the source against that conda env. I suspect that the complication you ran into is that building from src requires more dependencies than are going to be in the psi4conda installation (that only has things psi4 needs at runtime).

env_p4dev_silicon.yaml

name: p4dev_silicon
channels:
  - conda-forge
  - nodefaults
dependencies:
    # build
  - c-compiler
  - cmake
  - cxx-compiler
  #- dpcpp_linux-64            # opt'l with cxx-compiler
  - ninja
    # non-qc buildtime required
  - blas-devel                # req'd with libblas
  - eigen                     # req'd with libint
  - libblas=*=*accelerate
  - libboost-headers          # req'd with libint
  - llvm-openmp
  - numpy
  - pip                       # req'd with python; Package installer not strictly needed but needs to be tied to this python if used.
  - pybind11>=2.10.*
  - python
    # qc buildtime required
  - gau2grid
  - conda-forge/label/libint_dev::libint==2.7.3dev1
  #- psi4/label/testing::libint2  # opt'l with libint; Optionally for linux-64, an AM=7 build is available here.
  - libxc-c
  - optking
  - qcelemental
  - qcengine
    # runtime required
  - msgpack-python            # req'd with qcelemental
  - networkx                  # req'd with qcelemental
  - scipy
  - pydantic=1
    # test
  - memory_profiler
  - pytest
  - pytest-xdist              # req'd with pytest; Parallel runner not strictly needed but very handy.

so the above is an env spec file. Then

conda env create -n p4dev_silicon -f /path/to/env_p4dev_silicon.yaml --solver libmamba && conda activate p4dev_silicon

that creates and activates the environment in your miniconda. then go to the psi4 src clone.

cmake -S. -Bobjdir_p4dev_silicon -GNinja

that configures psi4 against your activated conda env.

cd objdir_p4dev_silicon && cmake --build .

that moves into the build dir and builds

stage/bin/psi4 --psiapi

that prints some paths that you should execute in the current window (assumes bash)

psi4 ../tests/tu1-h2o-energy/input.dat 
    SCF energy............................................................................PASSED

then run a test.

I just tried this, so it should work. lmk if it gives trouble.

Thank you for your reply and providing detailed steps.

I am getting an error regarding einsums in the cmake file when I get to the build step.
I noticed that those changes are in the most recent commits so I commented out all the references to those and the build no longer gave errors.

However, after setting the paths, when I try to run a test in the test directory or running

psi4 --test 

I get the following error:

psi4 --test
Traceback (most recent call last):
  File "/Users/alexyang/Documents/Projects/psi4-src-test/psi4/objdir_p4dev_silicon/stage/bin/psi4", line 220, in <module>
    import psi4  # isort:skip
    ^^^^^^^^^^^
  File "/Users/alexyang/Documents/Projects/psi4-src-test/psi4/objdir_p4dev_silicon/stage/lib/psi4/__init__.py", line 93, in <module>
    from .driver import endorsed_plugins
  File "/Users/alexyang/Documents/Projects/psi4-src-test/psi4/objdir_p4dev_silicon/stage/lib/psi4/driver/__init__.py", line 34, in <module>
    from . import aliases, diatomic, frac, gaussian_n
  File "/Users/alexyang/Documents/Projects/psi4-src-test/psi4/objdir_p4dev_silicon/stage/lib/psi4/driver/diatomic.py", line 41, in <module>
    from .p4util.exceptions import *
  File "/Users/alexyang/Documents/Projects/psi4-src-test/psi4/objdir_p4dev_silicon/stage/lib/psi4/driver/p4util/__init__.py", line 33, in <module>
    from .exceptions import *
  File "/Users/alexyang/Documents/Projects/psi4-src-test/psi4/objdir_p4dev_silicon/stage/lib/psi4/driver/p4util/exceptions.py", line 49, in <module>
    from psi4 import core, extras
  File "/Users/alexyang/Documents/Projects/psi4-src-test/psi4/objdir_p4dev_silicon/stage/lib/psi4/extras.py", line 39, in <module>
    from .header import print_header as _print_header
  File "/Users/alexyang/Documents/Projects/psi4-src-test/psi4/objdir_p4dev_silicon/stage/lib/psi4/header.py", line 37, in <module>
    raise TypeError(
TypeError: Using custom build without tags. Please pull git tags with `git pull origin master --tags`. If building from source, `git fetch upstream "refs/tags/*:refs/tags/*"` and re-make.

When trying test psi4 running as python module following Compiling and Installing from Source, I also get the same error

python sample.py
Traceback (most recent call last):
  File "/Users/alexyang/Documents/Projects/psi4-src-test/sample.py", line 1, in <module>
    import psi4
  File "/Users/alexyang/Documents/Projects/psi4-src-test/psi4/objdir_p4dev_silicon/stage/lib/psi4/__init__.py", line 93, in <module>
    from .driver import endorsed_plugins
  File "/Users/alexyang/Documents/Projects/psi4-src-test/psi4/objdir_p4dev_silicon/stage/lib/psi4/driver/__init__.py", line 34, in <module>
    from . import aliases, diatomic, frac, gaussian_n
  File "/Users/alexyang/Documents/Projects/psi4-src-test/psi4/objdir_p4dev_silicon/stage/lib/psi4/driver/diatomic.py", line 41, in <module>
    from .p4util.exceptions import *
  File "/Users/alexyang/Documents/Projects/psi4-src-test/psi4/objdir_p4dev_silicon/stage/lib/psi4/driver/p4util/__init__.py", line 33, in <module>
    from .exceptions import *
  File "/Users/alexyang/Documents/Projects/psi4-src-test/psi4/objdir_p4dev_silicon/stage/lib/psi4/driver/p4util/exceptions.py", line 49, in <module>
    from psi4 import core, extras
  File "/Users/alexyang/Documents/Projects/psi4-src-test/psi4/objdir_p4dev_silicon/stage/lib/psi4/extras.py", line 39, in <module>
    from .header import print_header as _print_header
  File "/Users/alexyang/Documents/Projects/psi4-src-test/psi4/objdir_p4dev_silicon/stage/lib/psi4/header.py", line 37, in <module>
    raise TypeError(
TypeError: Using custom build without tags. Please pull git tags with `git pull origin master --tags`. If building from source, `git fetch upstream "refs/tags/*:refs/tags/*"` and re-make

I have figured out the problem, the tags weren’t showing and it was fine after I recloned the repo

For what it’s worth, you could also have obtained the tags via git fetch upstream "refs/tags/*:refs/tags/*", as the error message said.

When I try to import psi4 as a python module I’m getting an error.

python sample.py
Traceback (most recent call last):
  File "/Users/alexyang/Documents/Projects/UBC-C3/psi4/sample.py", line 1, in <module>
    import psi4
  File "/Users/alexyang/Documents/Projects/UBC-C3/psi4/psi4/__init__.py", line 71, in <module>
    from . import core
ImportError: cannot import name 'core' from partially initialized module 'psi4' (most likely due to a circular import) (/Users/alexyang/Documents/Projects/UBC-C3/psi4/psi4/__init__.py)

The python file I’m trying to run.

import psi4

psi4.set_memory('500 MB')

h2o = psi4.geometry("""
O
H 1 0.96
H 1 0.96 2 104.5
""")

psi4.energy('scf/cc-pvdz')

I set the paths that were printed out from

stage/bin/psi4 --psiapi