LaTeX-OCR
LaTeX-OCR copied to clipboard
M1 Mac Instructions Needed
Are there any detailed instructions on how to install this for an M1 mac?
For me worked:
-
Install miniconda For miniconda: https://docs.conda.io/en/latest/miniconda.html Instructions: https://conda.io/projects/conda/en/stable/user-guide/install/macos.html
-
create an env with python
conda create -n pix2tex python=3.8 -
Open the env and install the pix2tex package
conda activate pix2texpip install pix2tex -
Run pix2tex
pix2tex latexocr -
Screenshot an image (Shift+Command+4) and copy it (click on the pop up, now click on the image and then click on copy or use any other method to copy the image to clipboard)
-
Now press enter and you should get the LaTeX code
I got to step 4 until getting this error:
RuntimeError: Failed to import transformers.tokenization_utils_fast because of the following error (look up to see its traceback): dlopen(/Users/xxx/miniconda3/envs/pix2tex/lib/python3.8/site-packages/tokenizers/tokenizers.cpython-38-darwin.so, 0x0002): tried: '/Users/xxx/miniconda3/envs/pix2tex/lib/python3.8/site-packages/tokenizers/tokenizers.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))
Can you post the packages in your environment?
conda activate pix2tex
conda list
This error means that the "wrong" tokenizer package is installed, m1 is arm based and the package is x86_64 based. The problem seems to be that the packages were installed for the wrong architecture.
Which miniconda did you install, there is a x86_64 and a m1 version? I am not totally sure if the x86_64 version would run, but it could be that through rosetta this version also runs and maybe then x_86_64 packages will be installed instead of the arm ones. Just run:
conda info
And see if platform : osx-arm64 or not.
If it ist x86_64 then deinstall miniconda and install the arm version, then it should work with the steps from above.
At the moment I am using miniforge instead of minicoda, but if they are the arm versions it should not matter, some weeks ago I got latexocr to run on "normal" miniconda.
If all this still does not work, then you could try to follow those steps: https://www.mrdbourke.com/setup-apple-m1-pro-and-m1-max-for-machine-learning-and-data-science/
This is the exact setup I use at the moment to use machine learning on my m1 and it runs with that setup with the steps from above, but it should work with the arm miniconda version.
I also run into problems with installing the right packages for the m1 and sometimes I get errors that I can only resolve through completely removing miniconda/miniforge and reinstalling them with this method. https://www.delftstack.com/howto/python/uninstall-miniconda/#uninstall-miniconda-from-macos
My steps on M1:
pip install "pix2tex[gui]"the modulebrew install pyqt@5the GUI dependencysudo cp -r /opt/homebrew/Cellar/pyqt@5/5.15.7_2/lib/python3.9/site-packages/* /Users/rey/miniconda3/lib/python3.9/site-packages/* since you cannot find a compatible version on the official forge of pip or condapip install pynput screeninforequired by the packageconda install pytorch torchvisionconda will try to install a better version of pytorch on arm 64
Details in my blog post, and in Chinese(详情参见我的博客)。
@finn200102 's recommendation
conda list
# packages in environment at /Users/XXXXX/miniconda3/envs/pix2tex:
#
# Name Version Build Channel
ca-certificates 2023.01.10 hca03da5_0
certifi 2022.12.7 py38hca03da5_0
libcxx 14.0.6 h848a8c0_0
libffi 3.4.2 hca03da5_6
ncurses 6.4 h313beb8_0
openssl 1.1.1t h1a28f6b_0
pip 23.0.1 py38hca03da5_0
python 3.8.16 hc0d8a6c_3
readline 8.2 h1a28f6b_0
setuptools 65.6.3 py38hca03da5_0
sqlite 3.40.1 h7a7dc30_0
tk 8.6.12 hb8d0fd4_0
wheel 0.38.4 py38hca03da5_0
xz 5.2.10 h80987f9_1
zlib 1.2.13 h5a0b063_0
Conda info shows osx-arm64.
@finn200102 's solution step 3 part 2
pip install pix2tex
...[successful parts]...
Preparing metadata (pyproject.toml) ... error
error: subprocess-exited-with-error
× Preparing metadata (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [29 lines of output]
Traceback (most recent call last):
File "/Users/XXXXX/miniconda3/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 144, in prepare_metadata_for_build_wheel
hook = backend.prepare_metadata_for_build_wheel
AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/XXXXX/miniconda3/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 351, in <module>
main()
File "/Users/XXXXX/miniconda3/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 333, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/Users/XXXXX/miniconda3/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 148, in prepare_metadata_for_build_wheel
whl_basename = backend.build_wheel(metadata_directory, config_settings)
File "/private/var/folders/jg/k3zgqw6n03z_knw_kyq5jmqh0000gn/T/pip-build-env-tswhkwtx/overlay/lib/python3.10/site-packages/sipbuild/api.py", line 46, in build_wheel
project = AbstractProject.bootstrap('wheel',
File "/private/var/folders/jg/k3zgqw6n03z_knw_kyq5jmqh0000gn/T/pip-build-env-tswhkwtx/overlay/lib/python3.10/site-packages/sipbuild/abstract_project.py", line 87, in bootstrap
project.setup(pyproject, tool, tool_description)
File "/private/var/folders/jg/k3zgqw6n03z_knw_kyq5jmqh0000gn/T/pip-build-env-tswhkwtx/overlay/lib/python3.10/site-packages/sipbuild/project.py", line 585, in setup
self.apply_user_defaults(tool)
File "/private/var/folders/jg/k3zgqw6n03z_knw_kyq5jmqh0000gn/T/pip-install-nytym8_7/pyqt5_0745ce0f66ec412eaec738418c5ffce4/project.py", line 68, in apply_user_defaults
super().apply_user_defaults(tool)
File "/private/var/folders/jg/k3zgqw6n03z_knw_kyq5jmqh0000gn/T/pip-build-env-tswhkwtx/overlay/lib/python3.10/site-packages/pyqtbuild/project.py", line 70, in apply_user_defaults
super().apply_user_defaults(tool)
File "/private/var/folders/jg/k3zgqw6n03z_knw_kyq5jmqh0000gn/T/pip-build-env-tswhkwtx/overlay/lib/python3.10/site-packages/sipbuild/project.py", line 236, in apply_user_defaults
self.builder.apply_user_defaults(tool)
File "/private/var/folders/jg/k3zgqw6n03z_knw_kyq5jmqh0000gn/T/pip-build-env-tswhkwtx/overlay/lib/python3.10/site-packages/pyqtbuild/builder.py", line 69, in apply_user_defaults
raise PyProjectOptionException('qmake',
sipbuild.pyproject.PyProjectOptionException
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
@reycn 's solution part 1
pip install "pix2tex[gui]"
[successful parts]...
Preparing metadata (pyproject.toml) ... error
error: subprocess-exited-with-error
× Preparing metadata (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [27 lines of output]
Traceback (most recent call last):
File "/Users/XXXXX/miniconda3/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 144, in prepare_metadata_for_build_wheel
hook = backend.prepare_metadata_for_build_wheel
AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/XXXXX/miniconda3/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 351, in <module>
main()
File "/Users/XXXXX/miniconda3/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 333, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/Users/XXXXX/miniconda3/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 148, in prepare_metadata_for_build_wheel
whl_basename = backend.build_wheel(metadata_directory, config_settings)
File "/private/var/folders/jg/k3zgqw6n03z_knw_kyq5jmqh0000gn/T/pip-build-env-y1jqbxho/overlay/lib/python3.10/site-packages/sipbuild/api.py", line 46, in build_wheel
project = AbstractProject.bootstrap('wheel',
File "/private/var/folders/jg/k3zgqw6n03z_knw_kyq5jmqh0000gn/T/pip-build-env-y1jqbxho/overlay/lib/python3.10/site-packages/sipbuild/abstract_project.py", line 87, in bootstrap
project.setup(pyproject, tool, tool_description)
File "/private/var/folders/jg/k3zgqw6n03z_knw_kyq5jmqh0000gn/T/pip-build-env-y1jqbxho/overlay/lib/python3.10/site-packages/sipbuild/project.py", line 585, in setup
self.apply_user_defaults(tool)
File "/private/var/folders/jg/k3zgqw6n03z_knw_kyq5jmqh0000gn/T/pip-build-env-y1jqbxho/overlay/lib/python3.10/site-packages/pyqtbuild/project.py", line 70, in apply_user_defaults
super().apply_user_defaults(tool)
File "/private/var/folders/jg/k3zgqw6n03z_knw_kyq5jmqh0000gn/T/pip-build-env-y1jqbxho/overlay/lib/python3.10/site-packages/sipbuild/project.py", line 236, in apply_user_defaults
self.builder.apply_user_defaults(tool)
File "/private/var/folders/jg/k3zgqw6n03z_knw_kyq5jmqh0000gn/T/pip-build-env-y1jqbxho/overlay/lib/python3.10/site-packages/pyqtbuild/builder.py", line 69, in apply_user_defaults
raise PyProjectOptionException('qmake',
sipbuild.pyproject.PyProjectOptionException
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.