# Kicost is amazing tool, but for me it didn't work!

#1

Hello

Kicost is a python script for generating part-cost spreadsheets and BOM.

But for me, under Ubuntu 15.10 don’t work.

I have this message :

python kicost -i
barriere_ir_is471f.xml
Traceback (most recent call last):

File “/usr/lib/python2.7/runpy.py”, line 162, in
_run_module_as_main
pkg_name)
File “/usr/lib/python2.7/runpy.py”, line 72,
in _run_code
exec code in run_globals
File
“/home/toto/Téléchargements/kicost-0.1.10/kicost/main.py”,
line 29, in
from .init import
version
ValueError: Attempted relative import in non-package

What it’s wrong ?

Jean-Pierre

#2

Hi. How did you install kicost? Did you install it from the github repo or by using ‘pip install kicost’? The placement of kicost under /home/toto/Telechargements’ looks strange. Python usually wants things installed under its own directory tree.

#3

You are right, I’m too stupid !

First install :

sudo easy_install kicost

Searching for kicost
Best match: kicost 0.1.10
Processing kicost-0.1.10-py2.7.egg
kicost 0.1.10 is already the active version in easy-install.pth
Installing kicost script to /usr/local/bin

First test :

python kicost -i barriere_ir_is471f.xml
python: can’t open file ‘kicost’: [Errno 2] No such file or directory

Second test :

python /usr/local/bin/kicost -i barriere_ir_is471f.xml

Now work !

Little question, is it possible to add radiospare and Farnell as a supplier ?

Jean-Pierre

#4

@devbisme I also gave a shot at trying to install Python PIP and then getting the KiCost to run but after watching to many videos about installing Python and PIP I gave up due to total confusion and not being able to find a clear set of instructions on how to install or use PIP.

I still could use the great features built in to KiCost but to get it working I’m going to need a set of instructions on how to properly install Python PIP on Windows 8 and then some simple instructions on how where to save the KiCost files to so they are in the right place, and then what I should do to get “sudo easy_install kicost” command to do something useful.

I’m usually pretty good at this stuff but I have never used Python before so its all 100% new to me. I can build 4 layer PCB with Kicad now after only a few instructional video courses but this Python install has me stumped.

@devbisme Any way you can take your Awesome KiCost tool and add a quick guide or video on how to actually install it with minimal steps if somebody has never used Python before?

I know it takes some work but you have already came this far with the program it only seems right to not stop there.

I watched your other videos on Kicad also which are also good. Keep up the good work.

#5

Jean, adding non-US distributors requires dealing with internationalization issues. The currency is different, the monetary delimiters are different, and some of the things I have to search for to scrape the part data from the web page will be in a different language. That’s a bit too much unpaid work for me to take on right now.

Kicost Command Line Error
#6

RWB, I don’t think installing Python really requires a video. Here’s some instructions:

2. Run the installer. In addition to installing Python, it will also install pip.
3. After the install has finished, open a command window and run the command ‘pip install kicost’. That will install kicost and anything else it depends upon.
4. Now you should be able to run kicost in a command window using the commands “kicost -i file.xml” or “python -m kicost -i file.xml”

Let me know if you have any difficulties.

#7

@devbisme OK I got PiP to install your KiCost Program.

I’m at the command line where I type in: kicost -i “The location of my BOM file.”

Should I be placing my BOM file in any specific folder? Or do I just type in the full file path?

My BOM file that I exported from Kicad using the Saxon plug in is called BMS, its a .CSV which is what Saxon exported I’m pretty sure. Maybe I saved it in CSV format for Digikey’s BOM manager.

Either way I need to know about how to properly provide the file path via this command line prompt.

Here is the location of my file on my system:

Using PIP to automagically install your program was super simple and it looks like were almost up and running.

#8

OK, the first thing you need to do is generate an XML file. I do that by starting the BOM tool from Eeschema and clicking on the Generate button. I don’t use any plugins; I just generate the raw XML. The CSV file you’re getting with your BOM plugins is not the file you want to use with KiCost. Look around in your project directory and see if you can find the XML file. If it’s not there, then try to run the BOM tool with no plugins.

Once you have the XML file, all you have to do is run KiCost on it:

kicost -i C:\path\to\my\file.xml


Or:

python -m kicost -i C:\path\to\my\file.xml


Then kicost should grind away for several minutes while it generates the spreadsheet file in the same directory where your XML file is. If you want to see the progress as KiCost runs, add the option “-d 2” to the end of the KiCost command.

#9

OK, I got it to create the spreadsheet but Python did it almost instantly.

I didn’t take any time to look up part cost on the web but I know why that happened. It’s because I have not populated the Manuf# field so there are no part numbers to look up.

So yea that was pretty easy Hopefully this helps somebody else in the future who wants to use this cool tool.

Thanks! @devbisme

#10

Thanks for hanging in there! Let me know if you have any problems.

#11

I just tried to install it on Win7 x64 with Python 3.4 x64 by using “pip install kicost” from administrator prompt. Then received a long list of build commands (some with warnings), ending in this text (in red color):

----------------------------------------
Cleaning up...
Command C:\Python34_64\python.exe -c "import setuptools, tokenize;__file__='D:\\
Temp\\pip_build_Mark\\lxml\\setup.py';exec(compile(getattr(tokenize, 'open', ope
n)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record
D:\Temp\pip-zywsnvlj-record\install-record.txt --single-version-externally-manag
ed --compile failed with error code 1 in D:\Temp\pip_build_Mark\lxml
Storing debug log for failure in C:\Users\Mark\pip\pip.log
----------------------------------------


Trying to run kicost --version or anything else results in:

C:\Windows\system32>kicost --version
Traceback (most recent call last):
File "C:\Python34_64\Scripts\kicost-script.py", line 5, in <module>
File "C:\Python34_64\lib\site-packages\pkg_resources.py", line 2697, in <module>
working_set.require(__requires__)
File "C:\Python34_64\lib\site-packages\pkg_resources.py", line 669, in require
needed = self.resolve(parse_requirements(requirements))
File "C:\Python34_64\lib\site-packages\pkg_resources.py", line 572, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: yattag>=1.5.2


Any ideas? There is a pip.log file, 309kB.

#12

Yeah, you’re having problems with installing lxml on Windows. Try using easy_install kicost and see if that works better.

#13

Interesting… running “easy_install kicost” scans for yattag, finds v1.5.2, installs it, scans for lxml, finds v3.5.0, installs it, then says this:

Building lxml version 3.5.0.
Building without Cython.
ERROR: b"'xslt-config' is not recognized as an internal or external command,\r\n
operable program or batch file.\r\n"
** make sure the development packages of libxml2 and libxslt are installed **

Using build configuration of libxslt
error: Setup script exited with error: Unable to find vcvarsall.bat


Trying to run kicost results in almost the same as previous, but finishes with:

    raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: lxml>=3.3.3


So it looks like lxml isn’t functional, due to components libxml2 and libxslt not being installed. Okay, so the issue definitely seems to be lxml. Googling it, returns a StackExchange question about it, which essentially points to manually installing a lxml v3.5.0 binary. Note Python 2.6 or 2.7 is mandatory; I have 2.7.9 and 3.4.2 both but think 3 is default. Downloaded the executable, installed it, it demands to be installed in the 2.7 folder. Fine, no errors. Try “easy-install kicost” again, same lxml error. So it is trying to install lxml into 3.4.2 Python, which isn’t working.

“python” executes v3. “py” executes v2… interesting. Googling how to switch between these, a large number of workarounds exist, all of which are rather customized and detailed. Adding PY_PYTHON = 2 env var did nothing.

Uninstalled Python 3.4.2, which uninstalled pip and setuptools…
Now “py” gives 2.7.9, but “python” does nothing. Added C:\Python27_64 to path. Now “python” is working.
NOW tried easy_install kicost, “easy_install” not a recognized command…

Okay here we go… uninstall all of the python versions (2.7.9 x32, 2.7.9 x64). Install JUST 2.7.11 x64 into cleaned-out c:\python27… add to the path, verify working with “python” and “py”, but “easy_install” and “pip” do nothing…

Which according to this question, python’s “scripts” folder also needs to be in the path. Looking in there, sure enough, pip.exe and easy_install.exe are there. So added, did the “easy_install kicost” without error, and “kicost --version” returns:

D:\>kicost --version
KiCost 0.1.14


So it was a python configuration/compatibility issue. Decided to post this in case anyone else ran into these issues and need some guidance in what to try. But to be honest, the configuration may be beyond many users.

#14

c:\python27\scripts\kicost.exe pops up in a command window, echoes nothing for a few minutes, then generates the .xlsx file. Opening that, it seems correct (woohoo!), except the components all show #NAME? for Unit$and Ext$ fields, along with the Total Cost and Unit Cost fields. So prices are not being returned properly. Ideas? I added the -s switch in the registry entry, no change.

EDIT: Think I’ve located the issue. The .xlsx renders fine if opened from dropbox (using their built-in viewer) but not from Apache OpenOffice 4.1.2 for Windows. Looks like it is unable to process the Unit$column formulas, which leads to math failures elsewhere. The values are in the formulas, but OO doesn’t understand the syntax: =iferror(LOOKUP(IF(K77="";G77;K77);{0;1;25;100;2500};{0;1.32;1.1;1;0.92});"")  I poked around with this for a bit, and found this post, which explains that “iferror” does not exist in OO (v3 at the time) and that a bug report was made about it (in 2008!) It is still open, marked “trivial” and in no rush to be fixed. Removing the iferror( and ;"") seems to work: =LOOKUP(IF(K77="";G77;K77);{0;1;25;100;2500};{0;1.32;1.1;1;0.92})  Since these formulas only exist in the spreadsheet lines containing actual data, is the “iferror” redundant? Thanks and apologies for the lengthy verbiage. Edit 2… So I wondered why OpenOffice hasn’t had many releases lately, and read up on it, discovering that LibreOffice is generally updated more. Since it has iferror() support, I installed it. Now the .xlsl opens without cell errors in LibreOffice, however all of the Qty, Unit$, Ext$, and totals are zero dollars. If I re-enter the Board Qty, all values populate. Weird. #15 KiCost works with local (customized) libs only, where one has added manf and manf# fields to each and every symbol… That’s why we’re having this discussion going on here: You might also be interested in this: EDIT: looking at my xlsx file after not having those fields they did show$0.00 and not NAME?.. so my answer might be wrong/unrelated.

#16

Fantastic stuff Joan! Almost a year ago I suggested a metadata manager feature. Between that and KiCost, these should save loads of time and frustration.

#17

Very well done! Very nice tool. I use it on a Windows platform and the things I have learned are:

• pip is the name of the tool used on a windows platform to get python packages. And that they are stored in a subdir of WinPython/…/Scripts. That is where the KiCost.exe is found in the end.
• I had to use that path in the windows registry to associate a xml file to KiCost script (if you want to do that too)
• When WinPython is installed, you must expand the path environment variable by yourself. Same for pip (which automatically comes with WinPython). The installer does not do that out of the box.

Good luck!

Peter

#18

Dear devbisme, I spent the last day trying to install KiCost, which now it seems essential to me.
I have read averything how to install it yet I got error message. Do you have tipp for me maybe?
What I did so far:

• Installed python (2.7, 3.5 also the link you provided (Download the WinPython installer for Python 2.7.10 (32-bit))
• did the second and third step as well, and the cmd window give me the following error messages regardles I use pip or easy_install --> “The command “pip” is either misspelled orcould not be found.” No matter what I do I always get this message.

#19

It sounds like you need to add the paths to your WinPython to your PATH environment variable. Without that, Windows doesn’t know where to go to find the pip program. Look for where the pip program is stored and add that directory to your PATH.

#20

Yes indeed it worked. Huge respect, and thank you for your help.
If you allow me I would have 2 more question.
-Can I use eur instead of dollar somehow?
-I use almost exclusively RS Comp, but there are Excel fields where next to a valid link and RS part number, there are no price, yet there are under Digikey or Farnell.