GrotjahnLab / surface_morphometrics

Morphometrics for Membrane Surfaces Segmented from Cryo-ET or other volumetric imaging.
GNU General Public License v3.0
18 stars 9 forks source link

m1 mac support #8

Open bbarad opened 2 years ago

bbarad commented 2 years ago

Pymeshlab fails to run on m1 macs, as builds are only being tested on x86_64. We should evaluate workarounds but I don't have an m1 mac so I can't do much testing...

bbarad commented 2 years ago

https://github.com/cnr-isti-vclab/PyMeshLab/issues/167 - Associated pymeshlab issue with ongoing work being done

GenevieveBuckley commented 2 years ago

FYI: My work laptop is an M1 Mac, I'd be very happy to help you test stuff out.,

I saw https://github.com/cnr-isti-vclab/PyMeshLab/issues/167 but wasn't able to figure out how to build or install pymeshlab when I tried it yesterday. Perhaps with a bit more effort, it might work.

If you ever want to do some pair programming, that could work. It looks like your institution is the Scripps Research Institute, located in California. Late afternoon there should overlap with mornings here in Melbourne Australia. Screen sharing and/or VSCode live share works pretty well for remote collaboration.

bbarad commented 2 years ago

I hadn't seen that there is a working build for m1 now! I was planning to solve this with #10 but have been sidetracked with feature additions for response to review (mostly new statistics tools)!

I suspect you will have better judgment than me on this - do you think getting native install (for this and for #7) working is the better route than the container? If so, I'd be happy to do some pair programming next week - I don't have an m1 so I can't easily test but I am not gonna be on the microscope at all next week so its an ideal time for some programming!

GenevieveBuckley commented 2 years ago

There are two days next week that are good for me:

  1. 3pm - 5pm Tuesday 26th July PDT (which for me is 8am - 10am Wednesday 27th July AEDT), and/or
  2. 3pm - 5pm Thursday 28th July PDT (which for me is 8am - 10am Friday 29th July AEDT)

I should have your email address, you've emailed me before. I'll send you a zoom link.

I suspect you will have better judgment than me on this - do you think getting native install (for this and for https://github.com/GrotjahnLab/surface_morphometrics/issues/7) working is the better route than the container?

I do not have a sense of which way is likely to be the easiest. Perhaps we'll have a bit more of an idea after next week?

GenevieveBuckley commented 2 years ago

Email sent!

GenevieveBuckley commented 2 years ago

Ben and I got this working today. Here's a copy of the notes we made (we'll need to write these up nicely and make a PR to add them to the docs):

surface-mophometrics on M1 Mac

Surface Morphometrics Toolkit

Issue: M1 Mac installation

Tips and tricks

  1. Build the conda environment like normal, but don't pip install pymeshlab - just remove it from the pip_requirements.txt file

  2. Install pyqt into your conda environment: For M1 Macs, the andfoy conda channel has a working pyqt build:

    conda install pyqt -c andfoy
  3. Build pymeshlab https://github.com/cnr-isti-vclab/PyMeshLab/blob/main/src/README.md

brew install libomp cgal xerces-c
git clone --recursive https://github.com/cnr-isti-vclab/PyMeshLab.git
cd PyMeshLab

# Build pymeshlab
mkdir src/build
cd src/build
cmake ..
make
make install
  1. Export the KMP_DUPLICATE_LIB_OK environment variable This prevents libomp errors. You can use conda to permanently set an environment variable in the morphometrics conda environment:
    
    conda activate morphometrics
    conda env config vars set KMP_DUPLICATE_LIB_OK=TRUE

Must reactivate conda environment

conda deactivate conda activate morphometrics conda env config vars list

You should now see KMP_DUPLICATE_LIB_OK = TRUE in this list


4. Check the build worked:
```bash
python -m pip install pytest
python -m pytest --pyargs pymeshlab
  1. Install pymeshlab to the conda environment:

    pip install .
  2. You're ready to go! Try running the surface-morphometrics scripts on the example data. See the README for more details.

GenevieveBuckley commented 2 years ago

Good news! There is a pyqt build for M1 macs now available through conda-forge link.

So we can just do

conda install pyqt -c conda-forge

...instead of using -c andfoy instead of conda-forge (andfoy is a more experimental development channel, I'm given to understand)

GenevieveBuckley commented 2 years ago

Irritatingly, the conda environment file throws up a lot of conflicts (even without me editing it to try and include pyqt, etc.) It's super odd, because when I make an empty conda environment, with just python 3.9, I can install all the dependencies into that one by one. Just not all at once with the environment.yml file.

Details (click to expand): ``` (base) genevieb@192-168-1-103 surface_morphometrics % conda env create -f environment.yml Collecting package metadata (repodata.json): done Solving environment: - Found conflicts! Looking for incompatible packages. This can take several minutes. Press CTRL-C to abort. failed Solving environment: / Found conflicts! Looking for incompatible packages. This can take several minutes. Press CTRL-C to abort. failed UnsatisfiableError: The following specifications were found to be incompatible with each other: Output in format: Requested package -> Available versions Package setuptools conflicts for: conda-forge::matplotlib=3.3.3 -> matplotlib-base[version='>=3.3.3,<3.3.4.0a0'] -> setuptools conda-forge::pandas -> setuptools[version='<60.0.0'] conda-forge::graph-tool -> matplotlib-base -> setuptools pip[version='>=20.0.2'] -> setuptools python=3.9.0 -> pip -> setuptools Package bzip2 conflicts for: conda-forge::matplotlib=3.3.3 -> python[version='>=3.9,<3.10.0a0'] -> bzip2[version='>=1.0.8,<2.0a0'] pathlib -> python -> bzip2[version='>=1.0.8,<2.0a0'] pip[version='>=20.0.2'] -> python[version='>=3.7'] -> bzip2[version='>=1.0.8,<2.0a0'] conda-forge::pandas -> python[version='>=3.8,<3.9.0a0'] -> bzip2[version='>=1.0.8,<2.0a0'] conda-forge::graph-tool -> python[version='>=3.10,<3.11.0a0'] -> bzip2[version='>=1.0.8,<2.0a0'] Package packaging conflicts for: pip[version='>=20.0.2'] -> wheel -> packaging[version='>=20.2'] conda-forge::graph-tool -> matplotlib-base -> packaging[version='>=20.0'] Package numpy conflicts for: conda-forge::matplotlib=3.3.3 -> matplotlib-base[version='>=3.3.3,<3.3.4.0a0'] -> numpy[version='>=1.19.4,<2.0a0'] conda-forge::pandas -> numpy[version='>=1.19.2,<2.0a0|>=1.19.4,<2.0a0|>=1.19.5,<2.0a0|>=1.21.6,<2.0a0|>=1.21.5,<2.0a0|>=1.21.4,<2.0a0'] conda-forge::graph-tool -> graph-tool-base==2.45=py310h5b70680_2 -> numpy[version='>=1.17|>=1.21.6,<2.0a0|>=1.19.5,<2.0a0|>=1.21.4,<2.0a0|>=1.19.4,<2.0a0'] Package cycler conflicts for: conda-forge::graph-tool -> matplotlib-base -> cycler[version='>=0.10'] conda-forge::matplotlib=3.3.3 -> matplotlib-base[version='>=3.3.3,<3.3.4.0a0'] -> cycler[version='>=0.10'] Package python_abi conflicts for: pip[version='>=20.0.2'] -> setuptools -> python_abi[version='3.10.*|3.8.*|3.9.*',build='*_cp38|*_cp39|*_cp310'] conda-forge::matplotlib=3.3.3 -> python_abi[version='3.8.*|3.9.*',build='*_cp38|*_cp39'] conda-forge::pandas -> python_abi[version='3.10.*|3.8.*|3.9.*',build='*_cp38|*_cp39|*_cp310'] conda-forge::graph-tool -> python_abi[version='3.10.*|3.8.*|3.9.*',build='*_cp310|*_cp38|*_cp39'] Package pip conflicts for: conda-forge::pandas -> python[version='>=3.8,<3.9.0a0'] -> pip conda-forge::graph-tool -> python[version='>=3.10,<3.11.0a0'] -> pip python=3.9.0 -> pip pathlib -> python -> pip conda-forge::matplotlib=3.3.3 -> python[version='>=3.9,<3.10.0a0'] -> pip Package wheel conflicts for: pip[version='>=20.0.2'] -> wheel python=3.9.0 -> pip -> wheel (base) genevieb@192-168-1-103 surface_morphometrics % ```

EDIT: I've figured out that if we relax the pinning of the python version (eg: use python=3.9 instead of python=3.9.0) then that's enough to fix this problem.

GenevieveBuckley commented 2 years ago

Note: there are two build scripts for pymeshlab (as an alternative to the make commands)

We found that if you use those on an M1 mac, you should edit the file first.

Modify build script (scripts/macOS/1_build.sh) line 77, with custom qt dir and remove -DBUILD_DUMMY_BIN_MAC_DEPLOY flag.` Then you can run:

sh scripts/macOS/1_build.sh
sh scripts/macOS/2_deploy.sh
bbarad commented 2 years ago

We ended up running into segfaults with these build scripts I believe? Were you able to go back and get them working?

GenevieveBuckley commented 2 years ago

Oh yes, you're right. I remember now, the build scripts seemed like they worked, but then when we tried to import pymeshlab it would segfault. No, we didn't stop to work out why. We just moved to using the make install commands instead, since that did work.

Thanks for prompting me to include all the details, I would definitely have forgotten parts of this otherwise.

bbarad commented 2 years ago

I am inclined to leave this open until we get confirmation from 1 more user that these instructions worked, then I'll convert to a documentation file with any extra details needed and close this out.

akas0018 commented 1 year ago

I was able to get the pymesh installation done without any errors but when I run python segmentation_to_meshes.py config.yml I ger the following error :

File "/opt/homebrew/Caskroom/miniforge/base/envs/morphometrics/lib/python3.9/site-packages/pymeshlab/init.py", line 11, in from .pmeshlab import * ModuleNotFoundError: No module named 'pymeshlab.pmeshlab'

When I pytest --pyargs pymeshlab in the disturb directory I got several similar errors

____ ERROR collecting tests/test_ambient_occlusion.py ____ ImportError while importing test module '/opt/homebrew/Caskroom/miniforge/base/envs/morphometrics/lib/python3.9/site-packages/pymeshlab/tests/test_ambient_occlusion.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /opt/homebrew/Caskroom/miniforge/base/envs/morphometrics/lib/python3.9/importlib/init.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) /opt/homebrew/Caskroom/miniforge/base/envs/morphometrics/lib/python3.9/site-packages/pymeshlab/init.py:11: in from .pmeshlab import * E ModuleNotFoundError: No module named 'pymeshlab.pmeshlab'

Any help would be really appreciated. Thanks in advance

HDuyvesteyn commented 1 month ago

I am getting exactly the same error as akas0018 above with my Macbook Pro M2.

Bumping the cry for help!!! I tried trawling the internet for solutions to no avail.