[Tutorial] How to compile IfcOpenShell-python for OSX/macOS

This forum section is only for IFC-related issues
User avatar
pablogil
Posts: 882
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

[Tutorial] How to compile IfcOpenShell-python for OSX/macOS

Post by pablogil »

It was a such a hard investigation on how to get a working copy of IfcOpenShell-python on OSX/macOS in order to import/export IFC files that I'm sharing this tutorial in case it helps more people.
My system is OSX 10.11.6, 64bits with Python 2.7.11, it might work for you if you have also OSX as they are often 64bits but may differ from mine. The procedure might be very similar if you run Linux or Windows but it probably have some differences.

Let's start:
1. Download or clone the full GitHub project at https://github.com/IfcOpenShell/IfcOpenShell (it's the newest version)

2. From a terminal go to /nix/ folder and launch the script. In OSX it is ran with:

Code: Select all

./build-all.sh
It will take from 30 up to 120 minutes to compile everything. It's not the smarter way of compiling IfcOpenShell but this simple script will compile all dependencies, Python versions, etc.

3. Once it finishes (I don't remember now but it will be printed something like "Built IfcOpenShell..." and it will return to your prompt) you will have a new folder /IfcOpenShell/build/ full of files and folders. From my personal experience, two weeks ago the nix "build-all.sh" script didn't finished successfully but after trying it yesterday with the newest updates it worked fine so I guess you might experience something similar in case the development goes further...
So now you have everything you need but you have to do some manual work in order to get it working:

4. Open FreeCAD and open the Python console and Report view. Then write into the Python console the following:

Code: Select all

import sys
print sys.path
You will get a looong line with all the paths that FreeCAD reads. You may be able to install ifcopenshell in any of them but I suggest you to place it inside one where you find a /site-packages/ after a /Python/ or /python-something/. In my case it was /Library/Python/2.7/site-packages. (you will find paths inside your app directory but I suggest you to not use them because then IfcOpenShell will only be available for this app)

5. So, once located where you want/have to install it, go there with your file browser (Finder in OSX). That is, go inside /site-packages/ folder

6. Open a new file browser window and navigate to your downloaded GitHub project: /IfcOpenShell/src/ifcopenshell-python/ and copy the full folder /ifcopenshell/

7. Paste it inside /site-packages/ folder. Now you should have something like:

Code: Select all

/site-packages/ifcopenshell/__init__.py
/site-packages/ifcopenshell/entity_instance.py
/site-packages/ifcopenshell/file.py
/site-packages/ifcopenshell/geom/app.py
/site-packages/ifcopenshell/geom/main.py
/site-packages/ifcopenshell/geom/occ_utils.py
/site-packages/ifcopenshell/geom/__init__.py
/site-packages/ifcopenshell/guid.py
8. Now we have to pick to files inside the /build/ folder, they are:

Code: Select all

_ifcopenshell_wrapper.so
ifcopenshell_wrapper.py
but as we have compiled everything you will have to pick the one that matches with your FreeCAD Python version. Check it easily reading the first line inside your FreeCAD Python console view. In my case it was Python 2.7.11.

9. Now go let's copy the files inside the place it corresponds to your Python version. In my case it was:

Code: Select all

/IfcOpenShell/build/Darwin/x86_64/build/ifcopenshell/[b]python-2.7[/b].10/ifcwrap/
10. Paste them inside /site-packages/ifcopenshell/

11. Check everything is in place:

Code: Select all

/site-packages/ifcopenshell/__init__.py                  (1)
/site-packages/ifcopenshell/entity_instance.py           (1)
/site-packages/ifcopenshell/_ifcopenshell_wrapper.so     (2)
/site-packages/ifcopenshell/file.py                      (1)
/site-packages/ifcopenshell/geom/__init__.py             (1)
/site-packages/ifcopenshell/geom/app.py                  (1)
/site-packages/ifcopenshell/geom/main.py                 (1)
/site-packages/ifcopenshell/geom/occ_utils.py            (1)
/site-packages/ifcopenshell/guid.py                      (1)
/site-packages/ifcopenshell/ifcopenshell_wrapper.py      (2)

(1) from GitHub project
(2) from /build/ folder
12. Close and reopen FreeCAD and test if everything is working:

12.1 in the Python console write:

Code: Select all

import ifcopenshell
from ifcopenshell import geom
if it doesn't throw any error it means it may be correctly installed

12.2 Go to Yorik's FreeCAD manual, navigate to the lower part of the page and download the following files to test:

Code: Select all

house.FCStd
house.ifc
12.3 Open house.FCStd, select the root "Building" object and export it (File/export/) setting the File type to "Industry Foundation Classes (*.ifc)". Press "save" and if it works and it doesn't throw an error in the Report view then it's working

12.4 Final test, import house.ifc into a new file so open a new file and import that file... it will take a while.

13. Enjoy BIM with FreeCAD!

My opinion is that FreeCAD itself should have precompiled versions of IfcOpenShell bundled with the distribution because building it by yourself is a total pain and average user won't do it (they don't know how to compile, manage GitHub, etc), but well, maybe in the future.

I hope it helps you :)
Cheers

EDIT: Before you ask for them, here you have a temporal download link for binaries for some Python versions. I have packed them so that you could straightaway download and install them without having to compile anything. I guess, FreeCAD developers may want to download them and make them available somewhere over the official site or even start thinking about including it inside FreeCAD.
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: [Tutorial] How to compile IfcOpenShell-python for OSX/macOS

Post by yorik »

Excellent! Thanks for writing this!
You didn't have to change the python version? I thought by default IfcOpenShell would compile with python3...
User avatar
pablogil
Posts: 882
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: [Tutorial] How to compile IfcOpenShell-python for OSX/macOS

Post by pablogil »

yorik wrote:Excellent! Thanks for writing this!
You didn't have to change the python version? I thought by default IfcOpenShell would compile with python3...
No, I had no problems with Python versions, maybe it was the nix script that dealt with it... I'm not sure
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
drei
Posts: 479
Joined: Sun May 11, 2014 7:47 pm
Location: Mexico
Contact:

Re: [Tutorial] How to compile IfcOpenShell-python for OSX/macOS

Post by drei »

@pablogil

Would you be wiling to add this post to the FreeCAD wiki?
Need help? Feel free to ask, but please read the guidelines first
User avatar
pablogil
Posts: 882
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: [Tutorial] How to compile IfcOpenShell-python for OSX/macOS

Post by pablogil »

drei wrote:@pablogil

Would you be wiling to add this post to the FreeCAD wiki?
I can try... I'll let you know in case I have any difficulty, OK?
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: [Tutorial] How to compile IfcOpenShell-python for OSX/macOS

Post by sgrogan »

pablogil wrote:EDIT: Before you ask for them, here you have a temporal download link for binaries for some Python versions. I have packed them so that you could straightaway download and install them without having to compile anything. I guess, FreeCAD developers may want to download them and make them available somewhere over the official site or even start thinking about including it inside FreeCAD.
Very cool work pablogil! Would you mind if I create a release on my IfcOpenSell fork? If you don't mind, what is the commit hash of your build so I can properly tag it?
yorik wrote:You didn't have to change the python version? I thought by default IfcOpenShell would compile with python3...
The build all script builds 5 versions, Line 39 could probably be edited to build only the python 2.7.x version for FreeCAD.
I'll contact @bblacey in the next days to see if this can be incororated into the OSX dev-builds.
"fight the good fight"
User avatar
pablogil
Posts: 882
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: [Tutorial] How to compile IfcOpenShell-python for OSX/macOS

Post by pablogil »

drei wrote:@pablogil

Would you be wiling to add this post to the FreeCAD wiki?
It's online, tell me if you find it correctly uploaded: http://www.freecadweb.org/wiki/index.ph ... cOpenShell

Thanks
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
User avatar
pablogil
Posts: 882
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: [Tutorial] How to compile IfcOpenShell-python for OSX/macOS

Post by pablogil »

sgrogan wrote:
pablogil wrote:EDIT: Before you ask for them, here you have a temporal download link for binaries for some Python versions. I have packed them so that you could straightaway download and install them without having to compile anything. I guess, FreeCAD developers may want to download them and make them available somewhere over the official site or even start thinking about including it inside FreeCAD.
Very cool work pablogil! Would you mind if I create a release on my IfcOpenSell fork? If you don't mind, what is the commit hash of your build so I can properly tag it?
Of course I don't mind, actually I encourage you to do it :D
Do you mean you want me to tell you the GitHub IfcOpenShell project commit hash from where I built it? if this is what you meant, the commit hash is 7ed9886.
sgrogan wrote:
yorik wrote:You didn't have to change the python version? I thought by default IfcOpenShell would compile with python3...
The build all script builds 5 versions, Line 39 could probably be edited to build only the python 2.7.x version for FreeCAD.
I'll contact @bblacey in the next days to see if this can be incororated into the OSX dev-builds.
Nice to hear, next time I feel like building it I will just compile for python 2.7.x version... so, FreeCAD always use this version or it's just my computer configuration?
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: [Tutorial] How to compile IfcOpenShell-python for OSX/macOS

Post by sgrogan »

pablogil wrote:Of course I don't mind, actually I encourage you to do it :D
Do you mean you want me to tell you the GitHub IfcOpenShell project commit hash from where I built it? if this is what you meant, the commit hash is 7ed9886.
Great, this is exactly what I meant. IfcOpenShell doesn't have built in minor versioning so I want to tag the release with this in case of problems in the future. Mac version is much newer than Windows version now ;)
pablogil wrote: Nice to hear, next time I feel like building it I will just compile for python 2.7.x version... so, FreeCAD always use this version or it's just my computer configuration?
FreeCAD doesn't support Python3 yet so almost all platforms/Distros are Python 2.7.x, although I think FreeCAD still support Python 2.6.x. mixing 2.7.10 and 2.7.11 shouldn't cause any problems.
"fight the good fight"
User avatar
pablogil
Posts: 882
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: [Tutorial] How to compile IfcOpenShell-python for OSX/macOS

Post by pablogil »

sgrogan wrote:
pablogil wrote:Of course I don't mind, actually I encourage you to do it :D
Do you mean you want me to tell you the GitHub IfcOpenShell project commit hash from where I built it? if this is what you meant, the commit hash is 7ed9886.
Great, this is exactly what I meant. IfcOpenShell doesn't have built in minor versioning so I want to tag the release with this in case of problems in the future. Mac version is much newer than Windows version now ;)
pablogil wrote: Nice to hear, next time I feel like building it I will just compile for python 2.7.x version... so, FreeCAD always use this version or it's just my computer configuration?
FreeCAD doesn't support Python3 yet so almost all platforms/Distros are Python 2.7.x, although I think FreeCAD still support Python 2.6.x. mixing 2.7.10 and 2.7.11 shouldn't cause any problems.
Cool then :D
So, are you thinking about including it into the FreeCAD build?
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
Post Reply