관리 메뉴

솜씨좋은장씨

[Python] M1 Mac PyMuPDF 설치 방법 ( feat. brew ) 본문

Programming/Python

[Python] M1 Mac PyMuPDF 설치 방법 ( feat. brew )

솜씨좋은장씨 2022. 10. 29. 10:58
728x90
반응형

M1 Mac 을 구매하면서 가장 걱정되었던 부분이

기존에 내가 작업하면서 사용하던 파이썬 라이브러리들이 설치가 잘 될까? 였습니다. 

 

다행히 지난 M1 맥북에어가 출시된 이후 

상당히 많은 시간이 흘러 많은 부분들이 아주 잘 설치가 되었습니다.

 

그러다 며칠 전! PyMuPDf 라이브러리를 설치하기 위해서 

% pip install pymupdf

명령어를 실행하였는데! 아래와 같은 기다란 에러메세지가 출력되었습니다.

Collecting pymupdf
  Using cached PyMuPDF-1.20.2.tar.gz (90.4 MB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: pymupdf
  Building wheel for pymupdf (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [59 lines of output]
      PyMuPDF/setup.py: sys.argv: ['/private/var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/pip-install-ppiyk6rf/pymupdf_46d23f44b526447aa2775abe2b723d38/setup.py', 'bdist_wheel', '-d', '/private/var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/pip-wheel-djebepdw']
      PyMuPDF/setup.py: os.getcwd(): /private/var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/pip-install-ppiyk6rf/pymupdf_46d23f44b526447aa2775abe2b723d38
      PyMuPDF/setup.py: __file__: /private/var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/pip-install-ppiyk6rf/pymupdf_46d23f44b526447aa2775abe2b723d38/setup.py
      PyMuPDF/setup.py: $PYTHON_ARCH: None
      PyMuPDF/setup.py: os.environ (40):
      PyMuPDF/setup.py:     __CFBundleIdentifier: com.apple.Terminal
      PyMuPDF/setup.py:     TMPDIR: /var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/
      PyMuPDF/setup.py:     XPC_FLAGS: 0x0
      PyMuPDF/setup.py:     LaunchInstanceID: FF65ACCF-B782-4D50-A664-3562966E05F3
      PyMuPDF/setup.py:     TERM: xterm-256color
      PyMuPDF/setup.py:     SSH_AUTH_SOCK: /private/tmp/com.apple.launchd.17J4RcymFf/Listeners
      PyMuPDF/setup.py:     SECURITYSESSIONID: 186a5
      PyMuPDF/setup.py:     XPC_SERVICE_NAME: 0
      PyMuPDF/setup.py:     TERM_PROGRAM: Apple_Terminal
      PyMuPDF/setup.py:     TERM_PROGRAM_VERSION: 447
      PyMuPDF/setup.py:     TERM_SESSION_ID: B53B90EA-1022-489B-957B-40307B7E8A6D
      PyMuPDF/setup.py:     SHELL: /bin/zsh
      PyMuPDF/setup.py:     HOME: /Users/somjang
      PyMuPDF/setup.py:     LOGNAME: somjang
      PyMuPDF/setup.py:     USER: somjang
      PyMuPDF/setup.py:     PATH: /Users/somjang/PythonHome/venvs/etl_bnk_venv/bin:/opt/anaconda3/bin:/opt/anaconda3/condabin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin
      PyMuPDF/setup.py:     SHLVL: 1
      PyMuPDF/setup.py:     PWD: /Users/somjang
      PyMuPDF/setup.py:     OLDPWD: /Users/somjang
      PyMuPDF/setup.py:     HOMEBREW_PREFIX: /opt/homebrew
      PyMuPDF/setup.py:     HOMEBREW_CELLAR: /opt/homebrew/Cellar
      PyMuPDF/setup.py:     HOMEBREW_REPOSITORY: /opt/homebrew
      PyMuPDF/setup.py:     MANPATH: /opt/homebrew/share/man::
      PyMuPDF/setup.py:     INFOPATH: /opt/homebrew/share/info:
      PyMuPDF/setup.py:     CONDA_EXE: /opt/anaconda3/bin/conda
      PyMuPDF/setup.py:     _CE_M:
      PyMuPDF/setup.py:     _CE_CONDA:
      PyMuPDF/setup.py:     CONDA_PYTHON_EXE: /opt/anaconda3/bin/python
      PyMuPDF/setup.py:     CONDA_SHLVL: 1
      PyMuPDF/setup.py:     CONDA_PREFIX: /opt/anaconda3
      PyMuPDF/setup.py:     CONDA_DEFAULT_ENV: base
      PyMuPDF/setup.py:     CONDA_PROMPT_MODIFIER: (base)
      PyMuPDF/setup.py:     NVM_DIR: /Users/somjang/.nvm
      PyMuPDF/setup.py:     NVM_CD_FLAGS: -q
      PyMuPDF/setup.py:     NVM_RC_VERSION:
      PyMuPDF/setup.py:     VIRTUAL_ENV: /Users/somjang/PythonHome/venvs/etl_bnk_venv
      PyMuPDF/setup.py:     PS1: (etl_bnk_venv) (base) %n@%m %1~ %#
      PyMuPDF/setup.py:     LANG: ko_KR.UTF-8
      PyMuPDF/setup.py:     _: /Users/somjang/PythonHome/venvs/etl_bnk_venv/bin/pip
      PyMuPDF/setup.py:     PIP_BUILD_TRACKER: /private/var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/pip-build-tracker-st5cl7sk
      PyMuPDF/setup.py: mupdf_tgz already exists: /private/var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/pip-install-ppiyk6rf/pymupdf_46d23f44b526447aa2775abe2b723d38/mupdf.tgz
      PyMuPDF/setup.py: Extracting /private/var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/pip-install-ppiyk6rf/pymupdf_46d23f44b526447aa2775abe2b723d38/mupdf.tgz
      PyMuPDF/setup.py: mupdf_local='mupdf-1.20.3-source/'
      PyMuPDF/setup.py: Building mupdf.
      PyMuPDF/setup.py: Building MuPDF by running: cd mupdf-1.20.3-source/ &&  make HAVE_X11=no HAVE_GLFW=no HAVE_GLUT=no HAVE_LEPTONICA=yes HAVE_TESSERACT=yes verbose=yes build=release && echo "build/release:" && ls -l build/release
      xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/pip-install-ppiyk6rf/pymupdf_46d23f44b526447aa2775abe2b723d38/setup.py", line 550, in <module>
          subprocess.run( command, shell=True, check=True)
        File "/opt/anaconda3/lib/python3.9/subprocess.py", line 528, in run
          raise CalledProcessError(retcode, process.args,
      subprocess.CalledProcessError: Command 'cd mupdf-1.20.3-source/ &&  make HAVE_X11=no HAVE_GLFW=no HAVE_GLUT=no HAVE_LEPTONICA=yes HAVE_TESSERACT=yes verbose=yes build=release && echo "build/release:" && ls -l build/release' returned non-zero exit status 1.
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pymupdf
  Running setup.py clean for pymupdf
Failed to build pymupdf
Installing collected packages: pymupdf
  Running setup.py install for pymupdf ... error
  error: subprocess-exited-with-error
  
  × Running setup.py install for pymupdf did not run successfully.
  │ exit code: 1
  ╰─> [60 lines of output]
      PyMuPDF/setup.py: sys.argv: ['/private/var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/pip-install-ppiyk6rf/pymupdf_46d23f44b526447aa2775abe2b723d38/setup.py', 'install', '--record', '/private/var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/pip-record-mwkxian5/install-record.txt', '--single-version-externally-managed', '--compile', '--install-headers', '/Users/somjang/PythonHome/venvs/etl_bnk_venv/include/site/python3.9/pymupdf']
      PyMuPDF/setup.py: os.getcwd(): /private/var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/pip-install-ppiyk6rf/pymupdf_46d23f44b526447aa2775abe2b723d38
      PyMuPDF/setup.py: __file__: /private/var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/pip-install-ppiyk6rf/pymupdf_46d23f44b526447aa2775abe2b723d38/setup.py
      PyMuPDF/setup.py: $PYTHON_ARCH: None
      PyMuPDF/setup.py: os.environ (41):
      PyMuPDF/setup.py:     __CFBundleIdentifier: com.apple.Terminal
      PyMuPDF/setup.py:     TMPDIR: /var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/
      PyMuPDF/setup.py:     XPC_FLAGS: 0x0
      PyMuPDF/setup.py:     LaunchInstanceID: FF65ACCF-B782-4D50-A664-3562966E05F3
      PyMuPDF/setup.py:     TERM: xterm-256color
      PyMuPDF/setup.py:     SSH_AUTH_SOCK: /private/tmp/com.apple.launchd.17J4RcymFf/Listeners
      PyMuPDF/setup.py:     SECURITYSESSIONID: 186a5
      PyMuPDF/setup.py:     XPC_SERVICE_NAME: 0
      PyMuPDF/setup.py:     TERM_PROGRAM: Apple_Terminal
      PyMuPDF/setup.py:     TERM_PROGRAM_VERSION: 447
      PyMuPDF/setup.py:     TERM_SESSION_ID: B53B90EA-1022-489B-957B-40307B7E8A6D
      PyMuPDF/setup.py:     SHELL: /bin/zsh
      PyMuPDF/setup.py:     HOME: /Users/somjang
      PyMuPDF/setup.py:     LOGNAME: somjang
      PyMuPDF/setup.py:     USER: somjang
      PyMuPDF/setup.py:     PATH: /Users/somjang/PythonHome/venvs/etl_bnk_venv/bin:/opt/anaconda3/bin:/opt/anaconda3/condabin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin
      PyMuPDF/setup.py:     SHLVL: 1
      PyMuPDF/setup.py:     PWD: /Users/somjang
      PyMuPDF/setup.py:     OLDPWD: /Users/somjang
      PyMuPDF/setup.py:     HOMEBREW_PREFIX: /opt/homebrew
      PyMuPDF/setup.py:     HOMEBREW_CELLAR: /opt/homebrew/Cellar
      PyMuPDF/setup.py:     HOMEBREW_REPOSITORY: /opt/homebrew
      PyMuPDF/setup.py:     MANPATH: /opt/homebrew/share/man::
      PyMuPDF/setup.py:     INFOPATH: /opt/homebrew/share/info:
      PyMuPDF/setup.py:     CONDA_EXE: /opt/anaconda3/bin/conda
      PyMuPDF/setup.py:     _CE_M:
      PyMuPDF/setup.py:     _CE_CONDA:
      PyMuPDF/setup.py:     CONDA_PYTHON_EXE: /opt/anaconda3/bin/python
      PyMuPDF/setup.py:     CONDA_SHLVL: 1
      PyMuPDF/setup.py:     CONDA_PREFIX: /opt/anaconda3
      PyMuPDF/setup.py:     CONDA_DEFAULT_ENV: base
      PyMuPDF/setup.py:     CONDA_PROMPT_MODIFIER: (base)
      PyMuPDF/setup.py:     NVM_DIR: /Users/somjang/.nvm
      PyMuPDF/setup.py:     NVM_CD_FLAGS: -q
      PyMuPDF/setup.py:     NVM_RC_VERSION:
      PyMuPDF/setup.py:     VIRTUAL_ENV: /Users/somjang/PythonHome/venvs/etl_bnk_venv
      PyMuPDF/setup.py:     PS1: (etl_bnk_venv) (base) %n@%m %1~ %#
      PyMuPDF/setup.py:     LANG: ko_KR.UTF-8
      PyMuPDF/setup.py:     _: /Users/somjang/PythonHome/venvs/etl_bnk_venv/bin/pip
      PyMuPDF/setup.py:     PIP_BUILD_TRACKER: /private/var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/pip-build-tracker-st5cl7sk
      PyMuPDF/setup.py:     PLAT: macosx-11.1-arm64
      PyMuPDF/setup.py: mupdf_tgz already exists: /private/var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/pip-install-ppiyk6rf/pymupdf_46d23f44b526447aa2775abe2b723d38/mupdf.tgz
      PyMuPDF/setup.py: Not extracting /private/var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/pip-install-ppiyk6rf/pymupdf_46d23f44b526447aa2775abe2b723d38/mupdf.tgz because already exists: mupdf-1.20.3-source/
      PyMuPDF/setup.py: mupdf_local='mupdf-1.20.3-source/'
      PyMuPDF/setup.py: Building mupdf.
      PyMuPDF/setup.py: Building MuPDF by running: cd mupdf-1.20.3-source/ &&  make HAVE_X11=no HAVE_GLFW=no HAVE_GLUT=no HAVE_LEPTONICA=yes HAVE_TESSERACT=yes verbose=yes build=release && echo "build/release:" && ls -l build/release
      xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/pip-install-ppiyk6rf/pymupdf_46d23f44b526447aa2775abe2b723d38/setup.py", line 550, in <module>
          subprocess.run( command, shell=True, check=True)
        File "/opt/anaconda3/lib/python3.9/subprocess.py", line 528, in run
          raise CalledProcessError(retcode, process.args,
      subprocess.CalledProcessError: Command 'cd mupdf-1.20.3-source/ &&  make HAVE_X11=no HAVE_GLFW=no HAVE_GLUT=no HAVE_LEPTONICA=yes HAVE_TESSERACT=yes verbose=yes build=release && echo "build/release:" && ls -l build/release' returned non-zero exit status 1.
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> pymupdf

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

아 드디어 만난건가! 싶어 M1 mac pymupdf install 과 같은 검색어로 검색해보니

GitHub Issue 에 이미 많은 분들이 겪었던 문제고 이미 해결 방법도 잘 정리되어있었습니다.

https://github.com/pymupdf/PyMuPDF/discussions/875

 

Unable to install under M1 Macintosh mode (works in x86/rosetta 2 mode) · Discussion #875 · pymupdf/PyMuPDF

I am unable to install pymupdf under Mac OS X Big Sur Native M1 (eg pip install PyMuPDF), whereas in Intel mode (Rosetta 2/aka Intel translation mode) it works without any issue. (quickbbs) benjami...

github.com

이번 글은 위의 깃헙 이슈에서 찾은 방법으로 해결한 내용을 정리해보려합니다.

🧑🏻‍💻 mupdf swig 사전 설치

pymupdf 를 설치하기 전에 mupdf 와 swig 를 설치해주어야합니다.

이 둘은 brew 명령어로 설치해주면 됩니다.

% brew update

먼저 brew update 명령어를 실행합니다.

( Error: 'git' must be installed and in your PATH! 에러 발생 시 아래를 참고해주세요. ) 

2022.10.29 - [유용한 정보/APPLE] - [macOS] brew update 시 Error: 'git' must be installed and in your PATH! 해결 방법 ( Ventura 업데이트 이후 )

 

[macOS] brew update 시 Error: 'git' must be installed and in your PATH! 해결 방법 ( Ventura 업데이트 이후 )

최근 M1 Max 맥북프로 16인치를 구매하고 나서! 회사에서 하는 작업에 필요한 라이브러리를 설치하는데 필요한 라이브러리를 설치하기 위해서는 brew 명령어로 설치를 해야하는 라이브러리가 있었

somjang.tistory.com

% brew install mupdf swig

🧑🏻‍💻 pymupdf 설치

사전에 설치가 필요한 것들을 다 설치하였다면 이제 pymupdf 를 설치하면 됩니다.

% pip install https://github.com/pymupdf/PyMuPDF/archive/master.tar.gz
Collecting https://github.com/pymupdf/PyMuPDF/archive/master.tar.gz
  Downloading https://github.com/pymupdf/PyMuPDF/archive/master.tar.gz
     | 8.6 MB 16.1 MB/s 0:00:00
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: PyMuPDF
  Building wheel for PyMuPDF (setup.py) ... done
  Created wheel for PyMuPDF: filename=PyMuPDF-1.21.0-cp39-cp39-macosx_11_0_arm64.whl size=12540864 sha256=e7aa1c4180652a5d2efe119f997b35406119a6045e408284aa10d973f0038000
  Stored in directory: /private/var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/pip-ephem-wheel-cache-_i76yxsx/wheels/51/11/07/8acc9b63ec794a5900440cb6485edab875ad81704a6c561096
Successfully built PyMuPDF
Installing collected packages: PyMuPDF
Successfully installed PyMuPDF-1.21.0
(base) somjang@DongHyunui-MacBookPro ~ % pip list | grep pymupdf
(base) somjang@DongHyunui-MacBookPro ~ % source ~/PythonHome/venvs/etl_bnk_venv/bin/activate
(etl_bnk_venv) (base) somjang@DongHyunui-MacBookPro ~ % pip install https://github.com/pymupdf/PyMuPDF/archive/master.tar.gz
Collecting https://github.com/pymupdf/PyMuPDF/archive/master.tar.gz
  Using cached https://github.com/pymupdf/PyMuPDF/archive/master.tar.gz
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: PyMuPDF
  Building wheel for PyMuPDF (setup.py) ... done
  Created wheel for PyMuPDF: filename=PyMuPDF-1.21.0-cp39-cp39-macosx_11_0_arm64.whl size=12540864 sha256=6229c225e80bac587d35c96d819ef629a3d35fd0e08b290d1499d8104f47ca03
  Stored in directory: /private/var/folders/kq/xsc4kyyj1h15v63qcnl88n040000gn/T/pip-ephem-wheel-cache-k0nl_wss/wheels/51/11/07/8acc9b63ec794a5900440cb6485edab875ad81704a6c561096
Successfully built PyMuPDF
Installing collected packages: PyMuPDF
Successfully installed PyMuPDF-1.21.0

생각보다 해결 방법이 쉬워 좋았습니다.

 

읽어주셔서 감사합니다.

Comments