Python Versions

Hi, I am trying to use some programs that are Python 3 under Windows7 64bit pro.

I see that the Python package installed with KiCad is V2.7.13 from Jan 2017.
Is this the version always called by KiCad, or will it use the 3.6 version that the windows PATH is set to?
Does it matter?
Is there anyway to update the 2.7.13 to the latest 2.7.14, or replace it with 3.6.4?
Sorry if these questions are dumb, but I am Python Muppet!

I’m not 100% sure, but I believe on Windows at least KiCad always uses it’s own Python installation, and only that version.
If you are running a script in KiCad or using “import pcbnew” you must use the KiCad python.

But, if you are running a script independently of KiCad, then you can install Python3 and run scripts in windows Command Prompt.

In fact, I have the choice of 3 Pythons, KiCad Python, my own Python 2 install, and a Python 3 install. I use a batch file to set the PATH accordingly.

Certainly on macOS you can install and run multiple Python versions - either at the system level using a package manager like Brew. You then call them as ‘Python2’ or ‘Python3’ etc. Alternatively, you can use a virtual environment to separate out different python versions. I use Conda/Anaconda which I think runs on other platforms too - it enables you to run mutually incompatible versions of whatever packages you want together whoever Python version you want without tearing your hair out.

On macOS, like Windows, Pcbnew scripting needs to run with its own Python version. I have found it easiest to put this version in the shebang line. You can still write your main application in whatever other flavour of Python you want - you can just call the parts that need pcbnew as external processes.

This python version thing is quite messy with KiCad. Some official documentation uses python3 syntax, yet KiCad has python2. Python2 will be officially retired in 2020 (https://pythonclock.org/). When people try to use scripts written by others it’s difficult to know if works with specific version, especially because not all scripts are run inside KiCad. In my opinion KiCad should move to 3 only as soon as possible and there should be no reason to write python2 compatible scripts.

I have seen talk on the mailing list of releasing 4.0.7a to update to the newer Python 2 for security reasons

I don’t really understand it but maybe someone can explain. It’s hard to find details outside of developer circles, so I’m putting together what I can glean.

It appears that Python 3 support would require Phoenix (to replace wxPython). That may also mean a move from SWIG to SIP. Wayne won’t introduce a dependency until it is a package in Debian, and I don’t see any sign of it. Since it missed v5 freeze, no new Python would be in KiCad until v6.

So bottom line is we will have Python 2 in KiCad through to 2020 at least regardless. I get the impression that the KiCad devs like the idea of Python scripting, as long as it doesn’t require extra work. IOW, it’s not really a priority.

About the Python and KiCad, I agree with @eelik, soon (maybe in the road map of KiCad version 6, just a guess) it will change. For sure, keep the Python in KiCad allow us create script and workaround or also create full tools.
In this middle time, I am developing all python applications in version 3 and using the future and pasteurize tools (http://python-future.org/pasteurize.html) to release to user that just have the version 2 installed. But, sure, some times is needed a work around code to deal with the correct version of python (see line 144 of https://github.com/xesscorp/KiCost/blob/master/kicost/eda_tools/csv/generic_csv.py#L144)
About wxPython, I start to read about because of the development of the tool KiCost. Yes, in Python3 we need to install wxPython Phoenix. The last stable version (4.0.0) went to pip library in the beginning of this year.

2 Likes

Also version 3 change some variables types compared if version 2, this provide some improvement in speed. Some example that I read about was the range(), in v2 is a function, in v3 is a type.
That means that in some codes change the behavior, for example if 4 in range(0,6), for v2 first is evaluated range() returning a list() and after checking if belogs, for v3 is just a checking.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.