BradyAJohnston / MolecularNodes

Toolbox for molecular animations in Blender, powered by Geometry Nodes.
https://bradyajohnston.github.io/MolecularNodes/
GNU General Public License v3.0
912 stars 85 forks source link

Apple silicon/ Blender 3.4.0 / MolNodes 2.0.2 package installation failure #108

Closed PlethoraChutney closed 10 months ago

PlethoraChutney commented 1 year ago

Hi Brady! Excited to play with the new features, and maybe finally dip my toes into contributing!

Unfortunately, trying to install the required packages using this button in blender:

image

results in an error message reading:

Failed to install required packages. Please check /Users/posert/Library/Application Support/Blender/3.4/scripts/addons/MolecularNodes/logs/side-packages-install.log

The contents of that log file are:

$ cat ~/Library/Application\ Support/Blender/3.4/scripts/addons/MolecularNodes/logs/side-packages-install.log
-----------------------------------
Installer Started: 2022-12-13 08:18:36.297157
-----------------------------------
###################################
Installer finished: 2022-12-13 08:19:05.242502
###################################

System Info

Steps already taken

YaoYinYing commented 1 year ago

@PlethoraChutney Well if you already have a global Python3.10, whether it was installed via brew or conda, you may create any new directory and run pip wheel into it.

The wheel file shall be downloaded and built.

I guess gcc is still required for running a wheel buiding from source code contains C files.

mkdir MN_wheels;
cd MN_wheels;
pip3.10 wheel MDAnalysis==2.2.0 --cache-dir .

Then all the wheels will be appeared.

PlethoraChutney commented 1 year ago

OK, got that installed. I also had to install cython or the build would fail, so here's the steps to recreate:

conda create -n wheel-builder python=3.10 cython
conda activate wheel-builder
python -m pip wheel MDAnalysis==2.2.0 --cache-dir .

Now, sorry to be a little computer baby, but how do I convince blender to use this wheel?

YaoYinYing commented 1 year ago

@PlethoraChutney Great, then you can walk down to the Blender-bundled-python directory, generally it would be like /Applications/Blender.app/Contents/Resources/3.4/python/bin, and run pip install ./python3.10 -m pip install <wheel> .

I am not sure whether the wheel is required by this pip install or not.

BradyAJohnston commented 1 year ago

If this is works, we can maybe ship the wheel built on your ARM machine as an apple M1 / M2 specific install. At least until the next release of MDAnalysis which might also fix the issue with supplying wheels on PyPi.

YaoYinYing commented 1 year ago

Await is all we need. 🤣 It should be fine to just pin the version as 2.5.0 after it's released.

evanbunnage commented 1 year ago

After failing to get MolecularNodes installed on my M1 machine (symptom was that blender wouldn't open after symlinking a conda env with biotite & MDA) I came to this thread.

Can confirm rebuilding the wheels worked for me!

mkdir ~/biotite-wheel
conda create -n wheel-builder python=3.10 cython
conda activate wheel-builder
python -m pip wheel biotite==0.35.0 --cache-dir .
conda deactivate

cd /Applications/Blender.app/Contents/Resources/3.4/python/bin
./python3.10 -m pip install biotite --cache-dir ~/biotite-wheel

I did the same thing for MDA but I haven't tested it, but can confirm biotite works and I can import structures.

evanbunnage commented 1 year ago

I just tried the Covid spike protein example and I can confirm that MDA works using the same procedure.

BradyAJohnston commented 1 year ago

@evanbunnage thanks so much for the details! Exciting that this is working. This seems like it will be a more robust fix for the time being. I'll try and update the docs soon for installation instructions.

YaoYinYing commented 1 year ago

Great! I'm sure customized wheel building should work better bcs of higher compatibility with one's own machine. Before the 2.5.0 official wheel release of MDA, this can be a solid fix. BTW, biotite has an official wheel at 0.36.0 so we can set it in requirements.txt for the fix too.

oscarbiesanz commented 1 year ago

I was still having issues with Blender finding python.h after trying the current proposed solution, but I'm not at all knowledgeable about computer science, so I thought I would ask GPT4 to help so that I could provide more than a problem, and I actually found a working solution. Let me know if this works for anyone else still having issues.

Everything seemed to resolve on the attempt where GPT4 suggested this command cd /Applications/Blender.app/Contents/Resources/3.4/python/include/python3.10 ln -s ../../Python.framework/Versions/3.10/Headers/ Python.h after building the wheels. Again, I know almost nothing about how these things work, just throwing this out there in case it could save someone's career.

It also took me an embarrassing amount of time to realize I had to add the --user option to the final install command.

Let me know if this helps anyone!

danpf commented 1 year ago

FWIW, I just cloned the master branch, zipped up the MolecularNodes folder, installed it, closed out of blender, opened blender, clicked install biotite, waited, closed out of blender, and opened it again and it appears to work fine.

Edit: M1 mac, not using any MD related stuff. Edit2: Installed blender 3.5, was able to install MolecularNodes ezpz no closing of Blender needed.

ErikPoppleton commented 1 year ago

The method from @evanbunnage which is also in the documentation didn't work for me because of the Python.h issue for MDAnalysis. I resolved it by getting the header libraries from the official Python page for the version of Python which ships with Blender (3.10.9, for Blender 3.5). Unfortunately, if Blender is installed in either /Applications or $HOME/Applications/, Apple's System Integrity Protection prevents you from copying the contents of the Include directory from the downloaded version of Python, so you have to copy the whole Blender directory somewhere else, copy the include directory, then move Blender back.

I can then install MDA from the cached wheel and import it from Blender's internal Python console, but Molecular Nodes cannot see MDA and says its not installed.

I'm on an M1 Mac running Blender 3.5.

image

BradyAJohnston commented 1 year ago

Hi @ErikPoppleton this is an interesting one. It might be that there is a version mismatch for MDAnalysis. If you can import it via the python console inside of Blender then it should be available to MolecularNodes. What version do you get with the below. MolecularNodes is currently expecting 2.2.0 exactly.

MDA.__version__
ErikPoppleton commented 1 year ago

Yes! The version was 2.4.3. Downloading and caching specifically 2.2.0 fixed the problem and Molecular Nodes now sees MDA as installed. Thanks!

BradyAJohnston commented 1 year ago

MDAnalysis has just released 2.5.0 which includes pre-built .whl for M1 / M2 macs, which should HOPEFULLY fix the installation error that has been plaguing us for so long. It should now just be a single-button click from inside of Blender like all of the other packages rather than the complicated install using conda environments.

I don't have an apple silicon machine to test. I have created a potential new release which requests the new MDAnalysis. Can people please try this out? If possible on a fresh installation of Blender. If not a fresh installation, please ensure you restart Blender after clicking 'install' button.

https://github.com/BradyAJohnston/MolecularNodes/releases/tag/v2.7.1_beta

Luc1100 commented 1 year ago

@BradyAJohnston I tried the new MolecularNodes install with a fresh blender install. I get the following error when I try the MDAnalysis install.

bpy.ops.mol.install_package(package="MDAnalysis", version="2.5.0", description="Install required python package: MDAnalysis")
Error installing package. Please check the log files in '/Users/lucasmorley/Library/Application Support/Blender/3.5/scripts/addons/MolecularNodes/logs'.

Some of the stuff in side-packages-install.log is:

INFO:root:Running Pip: '['/Applications/Blender.app/Contents/Resources/3.5/python/bin/python3.10', '-m', 'pip', 'install', 'MDAnalysis==2.5.0']'
ERROR:root:Command failed: ['/Applications/Blender.app/Contents/Resources/3.5/python/bin/python3.10', '-m', 'pip', 'install', 'MDAnalysis==2.5.0']
ERROR:root:stdout: Collecting MDAnalysis==2.5.0
  Using cached MDAnalysis-2.5.0-cp310-cp310-macosx_11_0_arm64.whl (3.3 MB)

...

gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Users/brecht/dev/build_darwin/deps/Release/sqlite/include -I/Users/brecht/dev/build_darwin/deps/Release/bzip2/include -I/Users/brecht/dev/build_darwin/deps/Release/lzma/include -I/Users/brecht/dev/build_darwin/deps/Release/zlib/include -mmacosx-version-min=11.00 -arch arm64 -mmacosx-version-min=11.00 -arch arm64 -I/Applications/Blender.app/Contents/Resources/3.5/python/include/p
ython3.10 -c Bio/Align/_aligners.c -o build/temp.macosx-11.00-arm64-cpython-310/Bio/Align/_aligners.o
      Bio/Align/_aligners.c:11:10: fatal error: 'Python.h' file not found
      #include "Python.h"
               ^~~~~~~~~~
      1 error generated.
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for biopython
ERROR: Could not build wheels for biopython, which is required to install pyproject.toml-based projects

These look like the same errors as before, but I am pretty confident I did it correctly.

(To be fair, the previous caching solution also never worked for me and I had the same error so maybe something on my end)

BradyAJohnston commented 1 year ago

Thanks @Luc1100 for the details. Yours works otherwise by creating and linking the conda environment still?

BradyAJohnston commented 1 year ago

Actually @Luc1100 it seems that the error is with the biopython install itself. I just had a look at the biopython pypi page and it looks like there isn't a MacOS ARM build.... looks like we will have the same issue 🫠

Luc1100 commented 1 year ago

@BradyAJohnston much sadness :( and my linking of the conda environment broke when I updated to MacOS 13 because there are some weird permissions I cannot figure out.

mhbokhari commented 1 year ago

Any solution to fixing the biopython install?

BradyAJohnston commented 1 year ago

@mhbokhari using the workaround that is currently in the documentation should still work (docs) as it is basically the same issue as it was previously unfortunately

mhbokhari commented 1 year ago

@BradyAJohnston I still get the following error message when I try out the workaround in the documentation;

note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for biopython
Failed to build biopython
ERROR: Could not build wheels for biopython, which is required to install pyproject.toml-based projects

Im using M1 with 12.5 Montrey

BradyAJohnston commented 1 year ago

@mhbokhari I would need more of the earlier part of the error message to help try and debug at all, the final part that you've given doesn't provide much information to work with. There are a number of other potential fixes in this thread that seem to work / not work for various people on various machines.

I would suggest trying some of those, and if it still isn't working include more of the error messages in another comment. You can include code formatted text by doing three backticks and it will format it more nicely

error message goes here

BradyAJohnston commented 1 year ago

The biopython devs are happy to add a .whl so this should hopefully fix another dependency issue.

As I don't have an M1/2 mac I can't check for myself, is anyone able to try and see if any of the other dependencies are also lacking a .whl that we can try and get one for? Might be getting close to it finally working 🥹

mhbokhari commented 1 year ago

Here is an optimized solution of MN package installation for Mac on M1/M2 Apple Silicon :

  1. Make sure your Blender is built on apple silicon version and MN has already installed.
  2. Check if you have already install python@3.10 via conda or homebrew: which python3.10 or brew list python@3.10. If yes, go to step 6.
  3. Install miniconda or anaconda on ARM version.
  4. Create a new conda env containing python3.10: conda create -n py310 python=3.10 -y
  5. Activate it: conda activate py310
  6. walk to the build-in python binary dir of blender: cd /Applications/Blender.app/Contents/Resources/3.4/python/bin
  7. run pip with a CPATH anoucement:

    CPATH=$CPATH:$(python3.10-config --include | sed  -E 's/ ?-I/:/g') ./pip3.10 install MDAnalysis==2.2.0

    To install the exactly pinned version of required packages in requirements.txt, please use the following instead:

    CPATH=$CPATH:$(python3.10-config --include | sed  -E 's/ ?-I/:/g') ./pip3.10 install -r "/Users/$(whoami)/Library/Application Support/Blender/3.4/scripts/addons/MolecularNodes/requirements.txt"
image

This worked for me!

Luc1100 commented 1 year ago

Thanks @mhbokhari , just had to copy/paste that last line and everything is working perfectly!

Aseamann commented 1 year ago

Attempted to follow steps for @mhbokhari , however, pip3.10 does not seem to be in that directory with blender 3.5.1. When I move into the directory of "/Applications/Blender.app/Contents/Resources/3.5/python/bin", pip310 is not there. Only see "python3.10" in that directory. I have the conda env created and activated but CPATH step is getting an error saying "zsh: no such file or directory: ./pip3.10".

I previously had MolNodes working in a python env with conda but updated and broke what I was doing.

Aseamann commented 1 year ago

I didn't have to do the above step with Blender 3.5.0 and MolNodes 2.7.4. Happy to continue to help, have a bit more time this summer. Excited for the Ribbon structure update @BradyAJohnston

BradyAJohnston commented 1 year ago

@Aseamann does your last message mean that it is now working in Blender 3.5.0 / MN 2.7.4? Happy for any help you would like to offer. Feel free to open separate issues / PRs to discuss particular topics.

Aseamann commented 1 year ago

@BradyAJohnston Correct, with 3.5.0 I didn't have to mess with the python environment at all. However, I attempted with Blender 3.5.1 and it did not, I was unable to see the properties title in the "add-ons" menu under MN to install the packages.

BradyAJohnston commented 1 year ago

@Aseamann upgrading can be weird sometimes. I would uninstall MN from 3.5.0, uninstall and reinstall 3.5.1, then reinstall MN and see if that helps.

YaoYinYing commented 1 year ago

Attempted to follow steps for @mhbokhari , however, pip3.10 does not seem to be in that directory with blender 3.5.1. When I move into the directory of "/Applications/Blender.app/Contents/Resources/3.5/python/bin", pip310 is not there. Only see "python3.10" in that directory. I have the conda env created and activated but CPATH step is getting an error saying "zsh: no such file or directory: ./pip3.10".

I previously had MolNodes working in a python env with conda but updated and broke what I was doing.

./pip3.10 will be created only after the ./python3.10 -m ensurepip and ./python3.10 -m pip install pip --upgrade commands are executed. WOW that is weird! I installed latest Blender and MN and ./pip3.10 just disapears! you may use ./python3.10 -m pip instead.

For a detailed implementation, you may see this outdated installer script hahaha: https://github.com/YaoYinYing/MolecularNodes/blob/ARM-mac-installer/MolecularNodes/troubleshoot/InstallDependencies_M1.sh

However, please note that using this script may potentially cause issues with your Python/pip linking. So proceed with caution and make sure to handle it carefully.

m-a-r-i-u-s commented 1 year ago

Hi all, I had some issues to install MolecularNodes 2.7.4 under Blender3.6.0 on a MacBook Pro M1. I found a workaround and I wanted to share my workflow here, in case somebody else has similar troubles:

  1. Followed the instructions on: https://bradyajohnston.github.io/MolecularNodes/installation.html. However I added in front of "python -m pip wheel MDAnalysis==2.5.0 --cache-dir ." the flag: ARCHFLAGS="-arch arm64".
  2. This step "./python3.10 -m pip install MDAnalysis --cache-dir ~/MDAnalysis-wheel" raised an error saying it cannot install Biopython due to missing Python.h header file. So, I downloaded the missing header files from the Python3.10.12 distribution (https://www.python.org/downloads/source/).
  3. Under macOS (Ventura 13.4) I could not simply copy the header files to Blender's Python distribution. Hence I did the following:

    • cd /Applications/Blender.app/Contents/Resources/3.6/python/include
    • mv python3.10 python3.10.bk
    • cp -r ~/Downloads/Python-3.10.12/Include .
    • mv Include python3.10
    • cp python3.10.bk/pyconfig.h python3.10/
    • cd /Applications/Blender.app/Contents/Resources/3.6/python/bin
  4. I installed then the missing packages with: "ARCHFLAGS="-arch arm64" ./python3.10 -m pip install MDAnalysis --cache-dir ~/Documents/mdanalysis_wheel/". The reason is that Biopython's Bio.Align will raise an error if a trajectory is loaded complaining about the wrong architecture (-86x_64 instead of arm64).
  5. MacOS's security settings will tell you that the modified Blender application is damaged and should be moved to the bin. Under Settings>Privacy & Security>Developer Tools you can add Blender to the list. I was then able to successfully start Blender from the Terminal and load a xtc trajectory.

I am happy to get your feedback about my suggestions and I hope I can help somebody! Cheers, Marius

BradyAJohnston commented 1 year ago

Hi @m-a-r-i-u-s, thanks for the details! Good to have more examples of things that work for different people. I'm still not sure why the ./python3.10 -m pip install MDAnalysis --cache-dir ~/MDAnalysis-wheel would complain about missing headers. It should not be trying to use Blender's python, it should be using the conda environment's python which should have the required headers, but that error seems to say that it is attempting to use Blender's python.

Another solution should be just ensuring that you are definitely using the newly created python environoment. If you are definitely using the conda environment & it's installed python, but still getting the header error, then that is a problem with the conda environment.

gbayarri commented 1 year ago

Hi, I'm using M1 Monterey 12.4 with Blender 3.6.1 and I had the same problem. In my case, after doing the @mhbokhari workaround the problem persisted, so I installed directly MDAnalysis (not the cached .whl):

./python3.10 -m pip install MDAnalysis

And it works, I'm not sure why, and probably it's not the best practice.

MarcoVando commented 1 year ago

Hi I've followed the installation guide for M1/M2 installing from pip doesn't return any errors. I can also import MDA from the builtin python in Blender started from the terminal but not from the console run from Scripting tab!

From the molecular node add-in in preferences the button is styll deactivated and seems that it doesn't detect the installation. Is this a known issue?

When I try to import a .cif file from the molecularnode tab I obtain

image
BradyAJohnston commented 1 year ago

Hi @MarcoVando, it seems there are two different issues here.

BradyAJohnston commented 1 year ago

For those who have been having trouble with the installation instructions on the website, I have realised that it might be because the last step that installs from the cache doesn't specify the version to install, which sometimes seems to install the more recent versions from pip which are higher and it's not detected when installed. I will update the documentation, but specifying the specific version may also help with installation issues.

Old Instructions

./python3.10 -m pip install MDAnalysis --cache-dir ~/MDAnalysis-wheel

New Instructions

./python3.10 -m pip install MDAnalysis==2.5.0 --cache-dir ~/MDAnalysis-wheel
MarcoVando commented 1 year ago

This solved my installation problem. Now also blender recognize MDA package as installed. I can also import structure form pdb databse

BradyAJohnston commented 10 months ago

There should now be a version that is no longer problematic to install on macOS ARM machines. If people in this thread could please try it out by downloading it from the PR #400 and try it out installing.

If others report back that it's working, then I can move it into main and this saga can finally come to an end.

Luc1100 commented 10 months ago

Hi @BradyAJohnston,

I was able to download MDAnalysis through the plugin page successfully. However, when I try to load a trajectory I get the following error:

Python: Traceback (most recent call last):
  File "/Users/lmorley/Library/Application Support/Blender/3.6/scripts/addons/molecularnodes/io/md.py", line 131, in execute
    mol, universe = load(
  File "/Users/lmorley/Library/Application Support/Blender/3.6/scripts/addons/molecularnodes/io/md.py", line 99, in load
    mol = session.show(atoms=universe,
  File "/Users/lmorley/Library/Application Support/Blender/3.6/scripts/addons/molecularnodes/io/mda.py", line 534, in show
    mol_object = self._process_atomgroup(
  File "/Users/lmorley/Library/Application Support/Blender/3.6/scripts/addons/molecularnodes/io/mda.py", line 774, in _process_atomgroup
    nodes.create_starting_node_tree(
  File "/Users/lmorley/Library/Application Support/Blender/3.6/scripts/addons/molecularnodes/blender/nodes.py", line 388, in create_starting_node_tree
    group = new_group(name)
  File "/Users/lmorley/Library/Application Support/Blender/3.6/scripts/addons/molecularnodes/blender/nodes.py", line 229, in new_group
    group.interface.new_socket('Geometry', in_out='INPUT', socket_type='NodeSocketGeometry')
AttributeError: 'GeometryNodeTree' object has no attribute 'interface'
BradyAJohnston commented 10 months ago

@Luc1100 that looks like you might be on a 3.X version of Blender, but the latest MN requires 4.0+.

Luc1100 commented 10 months ago

@BradyAJohnston oops my bad. New error though, unsure if it something I am doing:

Python: Traceback (most recent call last):
  File "/Users/lmorley/Library/Application Support/Blender/4.0/scripts/addons/molecularnodes/io/md.py", line 131, in execute
    mol, universe = load(
  File "/Users/lmorley/Library/Application Support/Blender/4.0/scripts/addons/molecularnodes/io/md.py", line 89, in load
    universe = mda.Universe(top, traj)
TypeError: MockUniverse() takes no arguments
BradyAJohnston commented 10 months ago

@Luc1100 after install try restarting Blender and see if that error goes away.

Luc1100 commented 10 months ago

@BradyAJohnston that fixed it 🙌