# Import Shapely in python

**URL:** <https://forum.dynamobim.com/t/import-shapely-in-python/32497>\
**Category:** Developers\
**Tags:** python\
**Created:** [February 21, 2019, 9:53pm UTC](https://forum.dynamobim.com/t/import-shapely-in-python/32497 "2019-02-21T21:53:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dancleary](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dancleary/32/52179_2.png) [@dancleary](https://forum.dynamobim.com/u/dancleary)\
**Post date:** [February 21, 2019, 9:53pm UTC](https://forum.dynamobim.com/t/import-shapely-in-python/32497/1 "2019-02-21T21:53:03Z")

</div>

Hey pretty simple question.  
I want to use Shapely in my python script. Specifically LineString. I’m not sure how or if it is possible to do this. Any ideas?

I’m getting this error:  
ImportError: No module named shapely.geometry

Code:

```
from shapely.geometry import LineString

line1 = LineString([(0,0), (1,0), (1,1)])
line2 = LineString([(0,1), (1,1)])

point = (line1.intersection(line2))

OUT = point
```

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [February 21, 2019, 10:04pm UTC](https://forum.dynamobim.com/t/import-shapely-in-python/32497/2 "2019-02-21T22:04:08Z")

</div>

Have you successfully imported shapely in other IronPython scripts? It may be that IronPython 2.7 does not support shapely.

---

<div class="post-metadata">

**Author:** ![dancleary](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dancleary/32/52179_2.png) [@dancleary](https://forum.dynamobim.com/u/dancleary)\
**Post date:** [February 21, 2019, 10:06pm UTC](https://forum.dynamobim.com/t/import-shapely-in-python/32497/3 "2019-02-21T22:06:31Z")

</div>

I have not. I’m a little over my head here to be honest.

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [February 21, 2019, 10:24pm UTC](https://forum.dynamobim.com/t/import-shapely-in-python/32497/4 "2019-02-21T22:24:25Z")

</div>

I haven’t used any external modules in Dynamo so I’m not sure if this will solve your problem, but the first step you can take is to append your Lib folder to your sys.path variable:

```
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
sys.path.append('C:\Program Files\IronPython 2.7\Lib')

```

I’ve only used this to import standard modules like `csv` and `StringIO`. Theoretically you would just have to install the `shapely` module in the same folder, but Dynamo uses IronPython 2.7 so I’m not sure if you’ll end up being able to do so.

---

<div class="post-metadata">

**Author:** ![mbaicad](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@mbaicad](https://forum.dynamobim.com/u/mbaicad)\
**Post date:** [March 5, 2020, 9:35am UTC](https://forum.dynamobim.com/t/import-shapely-in-python/32497/5 "2020-03-05T09:35:16Z")

</div>

@dancleary Did this actually solve your problem?

I’m still not able to use shapely with IronPython due to the missing/not correctly available geos\_c.dll

Could you please further explain your steps to install shapely under IronPython?

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [March 5, 2020, 2:35pm UTC](https://forum.dynamobim.com/t/import-shapely-in-python/32497/6 "2020-03-05T14:35:54Z")

</div>

I’m not sure why my above response is marked as a solution, but, as the name of the .dll implies, GEOS is written in C. So, while it may work for CPython, it doesn’t look like shapely is compatible with IronPython.

---

<div class="post-metadata">

**Author:** ![mbaicad](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@mbaicad](https://forum.dynamobim.com/u/mbaicad)\
**Post date:** [March 5, 2020, 4:19pm UTC](https://forum.dynamobim.com/t/import-shapely-in-python/32497/7 "2020-03-05T16:19:28Z")

</div>

Thanks for the feedback. That’s what I thought as well.

Got confused by the “solution”

---

<div class="post-metadata">

**Author:** ![dancleary](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dancleary/32/52179_2.png) [@dancleary](https://forum.dynamobim.com/u/dancleary)\
**Post date:** [March 5, 2020, 6:03pm UTC](https://forum.dynamobim.com/t/import-shapely-in-python/32497/8 "2020-03-05T18:03:54Z")

</div>

@mbaicad Sorry about that! It did not solve my problem and I removed the solution. I have not been able to import Shapely into dynamo, I resorted to OOTB nodes and old geometry and math to get by my line intersection issue.

@cgartland mentions it may work for CPython. The only way I know how to get CPython to work with Revit is using PyRevit which allows you to write your own extensions. Might be worth looking into.

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [March 5, 2020, 6:10pm UTC](https://forum.dynamobim.com/t/import-shapely-in-python/32497/9 "2020-03-05T18:10:41Z")

</div>

@dancleary @mbaicad You both may be interested in this [thread](https://forum.dynamobim.com/t/python-sub-process/43847) from last year regarding launching a sub-process to execute a separate CPython script from within an IronPython script.
