Python - and KiField

So, I have some programming skills but am really struggling with the basics to get KiField up and running. I may be confusing myself.

What directory do I install KiField into? And do I move the whole KiField folder or just the .py file?

Then:
"At the command line:

$ easy_install kifield"

What paths are involved with this? What does this “install” command do?

ON EDIT: Win 7Pro 64
Python 2.7 Installed

We really need a template for people to report problems… people fail to mention the most basic information, and we are not mind readers.

Before starting to answer, we need to know what OS you are using?

1 Like

You first need to have Python installed. Once you have that, then you use the command easy_install kifield or pip install kifield and the program will be installed where Python can find it. You don’t have to be concerned with moving files or where they are stored.

Then you can use kifield at the command line. Just type kifield -h and you’ll get the help information. I assume you’ve found the documentation.

1 Like

The OP also needs to be instructed for which version of Python to have installed… 2.x (currently 2.7.13) or 3.x (currently 3.6.1). I hope 3.x, but personally I don’t know.

It doesn’t really matter: KiField works for both.

Well, part of that is because the instructions don’t even indicate which OS it was meant for. I sorta figured it didn’t matter.

When everything is set up right, python is very similar on any OS, which is a nice feature. When things go wrong, or you need to look under the hood, there are of course big differences in implementation between OSes.

If you installed Python and selected the option to “add to system path” then you can start a Command Prompt and run Python, and the associated tools like easy_install and pip.

Otherwise, you need to add the python paths : c:\python27;c:\python27\scripts

C:> path %path%;c:\python27;c:\python27\scripts

Assuming python was installed in c:\python27.

With python on the path, you can run python, easy_install and any other installed packages from any folder like any DOS command.

easy_install (and pip) will look on https://pypi.python.org/pypi to find packages, so you don’t need to download a zip if the package is registered on PyPi. Python packages are installed into C:\Python27\Lib\site-packages, and a command launcher for the package is created in C:\Python27\Scripts, so you can run the package like a command.

1 Like

If you install python 3.x on windows it will even add some dll to your windows system32 folder which then allows co-existence between 2.7.x and 3.x without the inserts into the PATH variable.
You can remove them.

On the command line for the live interpreter to appear you just type

py -2

for python 2.7.x and

py -3

for python 3.x

If you write scripts add this in the first line to tell the launcher which interpreter to use:

#!python2

or

#!python3

I guess the best shebang line for python2/3 is

#!/usr/bin/env python2

or

#!/usr/bin/env python3

However I do not know how Windows handles the shebang.

Well, I’m sure the dudes implementing this will have thought of that and made it OS-agnostic.
https://www.python.org/dev/peps/pep-0397/

Just tested and no complaining if I use that longer shebang line in Windows.

It does not have anything like this… which is why I asked what OS is being used. And now you have muddied the water with unusable advice…

Er…installing Python 3 to avoid changing the path seems like a sledgehammer to crack a nut?

Python 2/3 compatibility introduces a whole new set of problems. KiCad has python2.7 built in, so if you need to run a script in KiCad it needs to be Python2.7.

If you run a python script in KiCAD, the KiCAD environment should take care of picking the correct interpreter that comes with KiCAD and not have any problems with what python versions you have installed outside of KiCAD’s scope.
If KiCAD can’t do that, it’s about damn time…

Suggesting to install 3 in parallel to 2 is about removing the python PATH from the windows PATH variable and not have any python scripts run into version problems because of exactly that reason.
The python launcher under windows takes care of it.
That’s the clean and proper way IMHO.

And to come back to the OP… he wanted to run KiField, which is a 3rd party python script run outside of KiCAD afaik, running on the python interpreter that your system has installed and doesn’t even care for 2 or 3.

From an online tutorial, I had to do this:

“If after you install it python still isn’t recognized then in PowerShell enter this:”

“[ENVIRONMENT]::SETENVIRONMENTVARIABLE(“PATH”, “$ENV:PATH;C:\PYTHON27”, “USER”)”

I really need LINE by LINE instructions for this.

I’m using Win7Pro64bit. And I downloaded Python 2.7 and followed the tutorial here:
Learn Python the Hard Way

I have not done ANYTHING else with Python other in the tutorial; and I think I got up to lesson 13 or so.

Help me figure out why I can not seem to make this work.

In Windows 7 Pro 64 Bit, I used the start button and entered CMD into the search field.
Then I entered “cd”.

The prompt changed to the basic C prompt, “C:>”.

I tried a few things that did NOT work. I even launched Python and tried a few more things that did NOT work.

So, I entered the text:
“exit()” and hit the enter key.

Then, I entered the text:
“cmd” and hit the enter key.
One would think that this probably did NOT matter, but I did it anyways.

The command prompt and text:

“C:>easy_install kifield” <— NO QUOTE INDICATORS ACTUALLY TYPED; it is what is between them that matters.

It now appears that it is installed… and I have to learn the command line text commands to run it.

Thanks BOBC for reminding me of the good ole’ DOS days … i think …

LOL!

This is all very much PATH Dependant, as I figured from the start.

Yeah, I think we are NOT on the same page here.

Windoze 7 does NOT work like indicated as a newcomer trying to learn this stuff.

In order to make kifield work, I had to move a copy of my kicad.sch file to the C:> root location.

The instructions don’t state anywhere that paths matter, and they apparently DO. Nor, are there instructions about the SYNTAX of the path requirements.

To expect the average user of KiCad to have to learn and navigate all of this is ridiculous.

That’s the state of affairs… at least KiField and KiCAD are free and you can change the code if you don’t like something. :wink:
If this stuff was easy most of us would be doing something else. (*)

As for why you have problems with your path.
Install python 3 as well, it will place a dll in your system32 folder which will make this all way less painful in regards to python.

*) like wonder why Microsoft decided to cut off service updates on Intel 7th generation processors. And not even my fault, I had to get a bew CPU+RAM+mobo, becuase my old one died and I couldn’t get a new mini-ITX mobo for LGA1150 socket here in Oz… (4th gen).
No one tells you upfront that you will loose serviceability via Windows updates of your OS (inclusive safety patches) if you run windows 7 on a 7th gen cpu… luckily some dude wrote some code, put it on github and I got my safety patches working again. Argghhh…

1 Like

A post was split to a new topic: Running kifield from the command line