Running Python script from idle in Dynamo

Morning everyone,

I have a question regarding to running my script which runs with no problem in my installed idle. However, I can’t run it inside dynamo, I tried python script from string node with no luck.

python code:

"from rectpack import newPacker

rectangles = [(100, 30), (40, 60), (30, 30),(70, 70), (100, 50), (30, 30)]

bins = [(300, 450), (80, 40), (200, 150)]

packer = newPacker()

Add the rectangles to packing queue

for r in rectangles:

packer.add_rect(*r)

Add the bins where the rectangles will be placed

for b in bins:

packer.add_bin(*b)

Start packing

packer.pack()

nbins = len(packer)

OUT= nbins
";

It is also worth mentioning, that my code has an imported library, which can’t be identified in dynamo, please see the attachement for more details. any ideas on how to run this script?

Yesterday i had the same issue:

This was my fix:
image

This code basicly refers to the path where your .py file is

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

Many thanks @Schasfoortyoeri

I hope this will help me import all modules with no errors :sweat_smile:

I still have the problem–please have a look at the picture below. any ideas on why i am having this now after changing the sys.path directory?
script%20not%20running3

my question is how do I import these module library in ironPython Consolo ?

I run ironPython Consolo seprately and i coudn’t import the rectpack library there. But the library is already installed in my system as i run it smoothly from my IDLE?

This method is to import libraries that are already on your computer in the folder IronPython2.7/Lib.

Is the package you need in the folder? It should be a .py file.

If not, just copy and paste it in that folder, or specify a different path

If yes, what’s the error message saying?

2 Likes

@lucamanzoni

Thanks, a lot for your comment, you guided me to the answer but I still couldn’t figure it out and here is why:
For example, I was willing to import pip, so what I did was I looked it up in cmd to see where it was installed or to find their path so I found two files with py extention. I copied them in C:\Program Files (x86)\IronPython 2.7\Lib. however still couldn’t import it, because I couldn’t find the name of the module that i was looking for inside the py.

I much appreciated if you can have a look at the module in the link below which contain a library i need called rectpack, do you have an idea how to get it imported in pythonscript node?

If you download the module you can do 2 things. like @lucamanzoni explained.

1: Place the .py file in this folder: C:\Program Files (x86)\IronPython 2.7\Lib
and use this code:

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

2: Place it somehwere else, a folder called Rectpack on my desktop for example: C:\Users\yoeri\Desktop\Rectpack
Use this code:

import sys
sys.path.append('C:\Users\yoeri\Desktop\Rectpack')
from rectpack import newPacker

@Schasfoortyoeri

Many thanks, but i still have the same problem. I tried your steps twice and I failed to make the node work. The problem is rectpack is not identified in ironpython but it is identified in my idle.
So I approached it through following the your steps as : 1-First i went to located where rectpack mdules are installed and placed as you can see here:

you can see i successfully installed it through using anaconda prompt. all looks fine here

2- Then i went to the module where rectpack folder is located and i copied the folder with its py files as you can see here:
location%20of%20rectpack

3-
I copied its content to desktop file and also tried the ironpython lib location with no luck:

kindly, can you advise on how to overcome this issue?

i dont see any .py file called rectpack…

try some of these files that are actualy inside the folder:

from enclose import *
from packer_algo import *
from packer import *

the “*” means import everything from the .py file

1 Like

Many Thanks @Schasfoortyoeri

I will try your method and report back :slight_smile:

it might be that you actualy do need a python file called rectpack. but if you dont have it you cant import from it :confused:

@Schasfoortyoeri

it didn’t work, Please have a look below:

Can you have a look at the actual github Link here:


maybe there is something i am missing

Why is it too hard to get a python code from Github and simply just get it work inside python script node?

you forgot a space after import

you did:
from geometry import*

has to be:
from geometry import *

ill have a look and get back here :slight_smile:

did you install like the owner of the repo described on his github?


I tried import with space as you mentioned with same problem.

I don’t know how to install it through the describtion he mentioned. How do you install it through:

python setup.py install

Do i do that through the CMD after downloading the setup.py file?

I install it instead through anaconda prompot by typing:

pip install rectpack

i just did the same. i ll have a look
image

thanks, I am relying on you now :sweat_smile:

i m not sure if this is possible to import?

2019-01-21_13h38_49 2019-01-21_13h38_30

i copy’d packer from rectpack into the same location as decimal (which i’ve used before) as you can see decimal doesnt give any errors, packer does.

i m not sure what to do now. Maybe someone more experienced can help?

Thank you @Schasfoortyoeri, I appreciate you taking the time to make it work. But as you said will wait and see if someone can provide us with the right solution?

1 Like

I copied the folder rectpack in the IronPython2.7 folder and it seems to work.
Also you probably need to write a r before your path:

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

4 Likes