Unable to install PyCall on MacOS outside Julia shell

Hi,

MacOS 10.15, Julia 1.6.5

I installed Julia using jill.
Then I’m trying to install PyCall using script:

using Pkg;

@info "Python executable used for PyCall: $(ARGS[1])"
ENV["PYTHON"] = ARGS[1]
Pkg.add("PyCall")
Pkg.build("PyCall")

and run it with (current dir is /Users/kerim/Documents/Colada/r/Julia-1.6.app/Contents/Resources/julia/bin):

./julia myscript.jl /path/to/python

the output:

[ Info: Python EXE from Julia: /Users/kerim/Documents/Colada/r/python-install/bin/PythonSlicer
    Updating registry at `~/.julia/registries/General`
   Resolving package versions...
  No Changes to `~/.julia/environments/v1.6/Project.toml`
  No Changes to `~/.julia/environments/v1.6/Manifest.toml`
    Building Conda ─→ `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/6e47d11ea2776bc5627421d59cdcc1296c058071/build.log`
    Building PyCall → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/1fc929f47d7c151c839c5fc1375929766fb8edcc/build.log`
ERROR: LoadError: Error building `PyCall`: 
dyld: lazy symbol binding failed: Symbol not found: __dyld_shared_cache_contains_path
  Referenced from: /Users/kerim/Documents/Colada/r/python-install/lib/libpython3.9.dylib (which was built for Mac OS X 11.1)
  Expected in: /usr/lib/libSystem.B.dylib

dyld: Symbol not found: __dyld_shared_cache_contains_path
  Referenced from: /Users/kerim/Documents/Colada/r/python-install/lib/libpython3.9.dylib (which was built for Mac OS X 11.1)
  Expected in: /usr/lib/libSystem.B.dylib

error: [/Users/kerim/Documents/Colada/r/python-install/bin/./python] exit abnormally - Report the problem.
ERROR: LoadError: failed process: Process(setenv(`/Users/kerim/Documents/Colada/r/python-install/bin/PythonSlicer /Users/kerim/.julia/packages/PyCall/7a7w0/deps/find_libpython.py --list-all`,["XPC_FLAGS=0x0", "PYTHON=/Users/kerim/Documents/Colada/r/python-install/bin/PythonSlicer", "PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/kerim/bin:/Library/Apple/usr/bin", "PWD=/Users/kerim/Documents/Colada/r/Julia-1.6.app/Contents/Resources/julia/bin", "XPC_SERVICE_NAME=0", "TERM_PROGRAM=Apple_Terminal", "SHELL=/bin/zsh", "__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0", "SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk", "TMPDIR=/var/folders/fj/h23b9p213z99g2ljyt792vbr0000gn/T/"  …  "OLDPWD=/Users/kerim/Documents/Colada/r/Julia-1.6.app/Contents/Resources/julia", "JULIA_LOAD_PATH=@:/var/folders/fj/h23b9p213z99g2ljyt792vbr0000gn/T/jl_xpy1qi", "_=/Users/kerim/Documents/Colada/r/Julia-1.6.app/Contents/Resources/julia/bin/./julia", "USER=kerim", "SECURITYSESSIONID=186a6", "TERM=xterm-256color", "HOME=/Users/kerim", "TERM_PROGRAM_VERSION=433", "OPENBLAS_MAIN_FREE=1", "PYTHONIOENCODING=UTF-8"]), ProcessExited(1)) [1]

This happens only on MacOS.
On Windows 11 and many Linux distros there is no such error.

Also if I run Julia shell and then execute the PyCall add and build commands then installation passes successfully:

./julia
>>> ENV["PYTHON"] = /path/to/python
>>> Pkg.add("PyCall")
>>> Pkg.build("PyCall")