← Back to team overview

kicad-developers team mailing list archive

Re: Opening pcbnew from kicad: ImportError: No module named pcbnew

 

Hi Clemens,

I have been looking at your problem.

And I believe you are either running Arch, or there is possibly something wrong with your python install.

PEP-0394 http://legacy.python.org/dev/peps/pep-0394/ says that the "python" command should run the python2 interpreter installed on your system. But in your case its running the python3 interpreter. Which, according to PEP-0394 is not recommended but is what Arch linux does.

The recommended way of running python 3 is with the "python3" command.

Kicad scripting requires python2, so if you don’t have python2 installed, or the "python" command runs the python3 interpreter and not python2 then bad things will happen, as you have been experiencing.

Try installing "python2" or making "python" point to it and see if your problems are resolved.

To bring kicad inline with that PEP we should not use "python" but specifically refer to the interpreter as "python2".

Steven


On 11/01/16 07:31, Clemens Koller wrote:
Hi!

It gets more interesting when I add the path to pcbnew.py:

$ PYTHONPATH=~/SW/lib/python2.7/site-packages ./pcbnew
I believe you wanted to do:

$ export PYTHONPATH=~/SW/lib/python2.7/site-packages ./pcbnew
You don't need the export when you write the variable before the
command like this. But I am unsure if the tilde behaves as you expect
here. One could try to use ${HOME} or actually write /home/username
instead of the tilde.
Python internally resolves the ~/... properly to /home/<username>/...
and puts it in the front of the search path:

$ PYTHONPATH=~/SW/lib/python2.7/site-packages python
Python 3.5.1 (default, Dec  7 2015, 12:58:09)
[GCC 5.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
import sys
print(sys.path)
['', '/home/admin/SW/lib/python2.7/site-packages', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-linux', '/usr/lib/python3.5/lib-dynload', '/usr/lib/python3.5/site-packages']


Traceback (most recent call last):
   File "<string>", line 3, in <module>
   File "/home/admin/SW/lib/python2.7/site-packages/pcbnew.py", line 5055, in <module>
     class BOARD(BOARD_ITEM):
   File "/home/admin/SW/lib/python2.7/site-packages/pcbnew.py", line 5710, in BOARD
     def GetViaByPosition(self, aPosition, aLayer=UNDEFINED_LAYER):
NameError: name 'UNDEFINED_LAYER' is not defined

I am not into the python internals, but it seems something smells down that road.
We can just declare installing kicad with python support as non-root currently
as "unsupported". I am fine with that for now.
At least you resolved you module load issue so that's a step in the
right direction.  I don't know how thoroughly the Python module code has
been tested so you may find some issues here and there.
If somebody wants me to debug something in this area, let me know.
Otherwise, I'll stop digging at this place and call it a day.

Regards,

Clemens

_______________________________________________
Mailing list: https://launchpad.net/~kicad-developers
Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~kicad-developers
More help   : https://help.launchpad.net/ListHelp




Follow ups

References