Skip to content

Commit d659253

Browse files
authored
Merge pull request #910 from compas-dev/blender-install
Simplify Blender installation
2 parents be2eaf6 + 72a6155 commit d659253

File tree

4 files changed

+119
-14
lines changed

4 files changed

+119
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
* Added `draw_node_labels` and `draw_edgelabels` to `compas_blender.artists.NetworkArtist`.
1919
* Added `compas_blender.artists.RobotModelArtist.clear`.
2020
* Added `compas_blender.geometry.booleans` as plugin for boolean pluggables.
21+
* Added version-based installation for Blender.
2122

2223
### Changed
2324

docs/gettingstarted/blender.rst

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ the version of the bundled Python is 3.7, and for 2.93 LTS it is 3.9.
2222
Installation
2323
============
2424

25-
These instructions are for the latest Blender 2.83 LTS which ships with Python 3.7
26-
If you don't have an environment yet with Python 3.7 and COMPAS you can create one with ``conda``.
25+
These instructions are for the latest Blender 2.93 LTS which ships with Python 3.9
26+
If you don't have an environment yet with Python 3.9 and COMPAS you can create one with ``conda``.
2727

2828
.. code-block:: bash
2929
3030
conda config --add channels conda-forge
31-
conda create -n blender python=3.7 COMPAS --yes
31+
conda create -n blender python=3.9 COMPAS --yes
3232
3333
Configuring Blender to use the newly installed environment is slightly different per OS.
3434

@@ -58,9 +58,9 @@ Configuring Blender to use the newly installed environment is slightly different
5858
.. code-block:: bash
5959
6060
conda activate blender
61-
python -m compas_blender.install "%PROGRAMFILES%\\Blender Foundation\\Blender 2.83\\2.83"
61+
python -m compas_blender.install "%PROGRAMFILES%\\Blender Foundation\\Blender 2.93\\2.93"
6262
63-
Note that the path ``%PROGRAMFILES%\\Blender Foundation\\Blender 2.83\\2.83`` might be different on your system.
63+
Note that the path ``%PROGRAMFILES%\\Blender Foundation\\Blender 2.93\\2.93`` might be different on your system.
6464
Check your Blender installation and change the path accordingly.
6565

6666
.. raw:: html
@@ -71,9 +71,9 @@ Check your Blender installation and change the path accordingly.
7171
.. code-block:: bash
7272
7373
conda activate blender
74-
python -m compas_blender.install /Applications/blender.app/Contents/Resources/2.83
74+
python -m compas_blender.install /Applications/blender.app/Contents/Resources/2.93
7575
76-
Note that the path ``/Applications/blender.app/Contents/Resources/2.83`` might be different on your system.
76+
Note that the path ``/Applications/blender.app/Contents/Resources/2.93`` might be different on your system.
7777
Check your Blender installation and change the path accordingly.
7878

7979
.. raw:: html
@@ -84,9 +84,9 @@ Check your Blender installation and change the path accordingly.
8484
.. code-block:: bash
8585
8686
conda activate blender
87-
python -m compas_blender.install ~/Blender/2.83
87+
python -m compas_blender.install ~/Blender/2.93
8888
89-
Note that the path ``~/Blender/2.83`` might be different on your system.
89+
Note that the path ``~/Blender/2.93`` might be different on your system.
9090
Check your Blender installation and change the path accordingly.
9191

9292
.. raw:: html
@@ -99,6 +99,14 @@ Check your Blender installation and change the path accordingly.
9999
</div>
100100
</div>
101101

102+
On Windows and OSX, if Blender is installed in the default location, you can simply provide the version number.
103+
104+
.. code-block:: bash
105+
106+
conda activate blender
107+
python -m compas_blender.install -v 2.93
108+
109+
102110
Add-ons
103111
=======
104112

@@ -287,3 +295,30 @@ Artists are currently only available for data structures and robots.
287295

288296
There is also no official system yet for making custom COMPAS tools in Blender.
289297
Therefore, COMPAS Blender development is somewhat limited to individual scripts.
298+
299+
Known Issues
300+
============
301+
302+
On Windows, Blender sometimes has issues with finding NumPy libraries.
303+
If this is the case, the problem can usually be solved by reinstalling NumPy in your environment using ``pip``.
304+
However, to avoid issues with other packages that were already installed and depend on a specific version of NumPy,
305+
you should install the same version as the one installed originally by ``conda``.
306+
307+
.. code-block:: bash
308+
309+
python -c "import numpy; print(numpy.__version__)"
310+
311+
If the above is, for example, ``1.20.3``
312+
313+
.. code-block:: bash
314+
315+
pip install --force-reinstall numpy==1.20.3
316+
317+
Alternatively, you can create a new environment and simply install entire COMPAS using ``pip``.
318+
319+
.. code-block:: bash
320+
321+
conda create -n blender python=3.9 cython planarity --yes
322+
conda activate blender
323+
pip install compas
324+
python -m compas_blender.install

src/compas_blender/__init__.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
compas_blender.utilities
1515
1616
"""
17+
import os
18+
import compas
19+
1720
try:
1821
import bpy # noqa: F401
1922
except ImportError:
@@ -44,6 +47,42 @@ def clear():
4447
__version__ = '1.8.1'
4548

4649

50+
def _check_blender_version(version):
51+
supported_versions = ['2.83', '2.93']
52+
53+
if not version:
54+
return '2.93'
55+
56+
if version not in supported_versions:
57+
raise Exception('Unsupported Blender version: {}'.format(version))
58+
59+
return version
60+
61+
62+
def _get_default_blender_installation_path(version):
63+
version = _check_blender_version(version)
64+
65+
if compas.OSX:
66+
path = _get_default_blender_installation_path_mac(version)
67+
elif compas.WINDOWS:
68+
path = _get_default_blender_installation_path_windows(version)
69+
else:
70+
raise Exception('Unsupported platform.')
71+
72+
if not os.path.exists(path):
73+
raise Exception("The default installation folder for Blender {} doesn't exist.".format(version))
74+
75+
return path
76+
77+
78+
def _get_default_blender_installation_path_mac(version):
79+
return '/Applications/Blender.app/Contents/Resources/{}'.format(version)
80+
81+
82+
def _get_default_blender_installation_path_windows(version):
83+
return os.path.expandvars('%PROGRAMFILES%/Blender Foundation/Blender {}/{}'.format(version, version))
84+
85+
4786
__all__ = [name for name in dir() if not name.startswith('_')]
4887
__all_plugins__ = [
4988
'compas_blender.geometry.booleans',

src/compas_blender/install.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import sys
33
import tempfile
44

5+
import compas
6+
import compas_blender
7+
58
from compas._os import copy
69
from compas._os import create_symlinks
710
from compas._os import remove
@@ -41,27 +44,52 @@ def unregister():
4144
"""
4245

4346

44-
def install(blender_path):
47+
def install(blender_path, version=None):
4548
"""Install COMPAS for Blender.
4649
4750
Parameters
4851
----------
4952
blender_path : str
5053
The path to the folder with the version number of Blender.
5154
For example, on Mac: ``'/Applications/Blender.app/Contents/Resources/2.83'``.
52-
On Windows: ``'%PROGRAMFILES%\\Blender Foundation\\Blender\\2.83'``.
55+
On Windows: ``'%PROGRAMFILES%/Blender Foundation/Blender 2.83/2.83'``.
56+
version : {'2.83', '2.93'}, optional
57+
The version number of Blender.
58+
Default is ``'2.93'``.
5359
5460
Examples
5561
--------
5662
.. code-block:: bash
5763
58-
$ python -m compas_blender.install /Applications/Blender.app/Contents/Resources/2.83
64+
$ python -m compas_blender.install
65+
66+
.. code-block:: bash
67+
68+
$ python -m compas_blender.install -v 2.93
69+
70+
.. code-block:: bash
71+
72+
$ python -m compas_blender.install /Applications/Blender.app/Contents/Resources/2.93
5973
6074
"""
6175
if not os.environ.get('CONDA_PREFIX'):
6276
print('Conda environment not found. The installation into Blender requires an active conda environment with a matching Python version to continue.')
6377
sys.exit(-1)
6478

79+
if not version and not blender_path:
80+
version = '2.93'
81+
82+
if version and blender_path:
83+
print('Both options cannot be provided simultaneously. Provide the full installation path, or the version with flag -v.')
84+
sys.exit(-1)
85+
86+
if version:
87+
if compas.LINUX:
88+
print('Version-based installs are currently not supported for Linux. Please provide the full installation path with the -p option.')
89+
sys.exit(-1)
90+
91+
blender_path = compas_blender._get_default_blender_installation_path(version)
92+
6593
if not os.path.exists(blender_path):
6694
raise FileNotFoundError('Blender version folder not found.')
6795

@@ -122,7 +150,9 @@ def install(blender_path):
122150

123151
parser = argparse.ArgumentParser()
124152

125-
parser.add_argument('versionpath', help="The path to the folder with the version number of Blender.")
153+
parser.add_argument('blenderpath', nargs='?', help="The path to the folder with the version number of Blender.")
154+
parser.add_argument('-v', '--version', choices=['2.83', '2.93'], help="The version of Blender to install COMPAS in.")
155+
126156
args = parser.parse_args()
127157

128-
install(args.versionpath)
158+
install(args.blenderpath, version=args.version)

0 commit comments

Comments
 (0)