Page 1 of 2

ImportError: No module named PCANBasic,on python

Posted: Wed 8. May 2019, 02:03
by MrSingh
I've installed the PCANBasic api into my ubuntu 18.04 as per the given instructions in the manual.
But while importing the PCANBasic, using

Code: Select all

from PCANBasic import *
in my python program, it shows an import error.

Is this related to some directory issue? Should I copy the API files to some location? I have python 2.7 on my system.

Re: ImportError: No module named PCANBasic,on python

Posted: Wed 8. May 2019, 09:49
by M.Maidhof
Hi,

please post output of cat /proc/pcan, to see if the chardev driver is installed

regards

Michael

Re: ImportError: No module named PCANBasic,on python

Posted: Fri 10. May 2019, 14:49
by MrSingh
Sorry for late reply. Got caught up in another project.

Here's the output of the cat /proc/pcan

Code: Select all

*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20190412_n (8.8.0) May  7 2019 23:31:42 --------------
*------------- [mod] [isa] [pci] [pec] [dng] [par] [usb] [pcc] --------------
*--------------------- 1 interfaces @ major 236 found -----------------------
*n -type- -ndev- --base-- irq --btr- --read-- --write- --irqs-- -errors- status
32    usb   -NA- ffffffff 030 0x001c 0000000b 00000019 0000452c 0000683e 0x0080

Re: ImportError: No module named PCANBasic,on python

Posted: Fri 10. May 2019, 16:26
by M.Maidhof
Hi,

please send us the outputs when you build and install the pcanbasic API package.

Did you run one of our test apps for pcanbasic?

regards

Michael

Re: ImportError: No module named PCANBasic,on python

Posted: Fri 10. May 2019, 16:49
by MrSingh
The outputs for building and installing pcanbasic api :

Code: Select all

~/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic$ make clean
make[1]: Entering directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/pcanbasic'
Considering PCANBasic library with FD support (PCAN driver >= 8.0)
rm -f src/*~ src/*.o *~ *.so.* *.so libpcanfd.o
make[1]: Leaving directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/pcanbasic'
make[1]: Entering directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/pcaninfo'
rm -f src/*~ src/*.o ../pcanbasic/src/*~ ../pcanbasic/src/*.o *~ *.so.* *.so pcaninfo.1.0.2 pcaninfo
make[1]: Leaving directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/pcaninfo'
make[1]: Entering directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples'
make[2]: Entering directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples/python'
rm -f *.pyc
make[2]: Leaving directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples/python'
make[2]: Entering directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples/c++'
rm -f src/*~ src/*.o *~ pcanwrite pcanread pcaneventread pcaneventwrite
make[2]: Leaving directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples/c++'
make[1]: Leaving directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples'

Code: Select all

~/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic$ make
make[1]: Entering directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/pcanbasic'
Considering PCANBasic library with FD support (PCAN driver >= 8.0)
***
*** Making PCANBasic library with FD support (PCAN driver >= 8.0)
***
*** target=libpcanbasic
*** version=4.3.1
*** PCAN_ROOT=src/pcan
*** gcc version=7
***
gcc -fPIC -shared -O2 -Wall -Wcast-align -Wcast-qual -Wimplicit  -Wpointer-arith -Wswitch -Wredundant-decls -Wreturn-type -Wunused -DNO_RT -Isrc/pcan/driver -Isrc/pcan/lib  -c src/libpcanbasic.c -o src/libpcanbasic.o
gcc -fPIC -shared -O2 -Wall -Wcast-align -Wcast-qual -Wimplicit  -Wpointer-arith -Wswitch -Wredundant-decls -Wreturn-type -Wunused -DNO_RT -Isrc/pcan/driver -Isrc/pcan/lib  -c src/pcaninfo.c -o src/pcaninfo.o
gcc -fPIC -shared -O2 -Wall -Wcast-align -Wcast-qual -Wimplicit  -Wpointer-arith -Wswitch -Wredundant-decls -Wreturn-type -Wunused -DNO_RT -Isrc/pcan/driver -Isrc/pcan/lib  -c src/pcanlog.c -o src/pcanlog.o
gcc -fPIC -shared -O2 -Wall -Wcast-align -Wcast-qual -Wimplicit  -Wpointer-arith -Wswitch -Wredundant-decls -Wreturn-type -Wunused -DNO_RT -Isrc/pcan/driver -Isrc/pcan/lib  -c src/pcbcore.c -o src/pcbcore.o
gcc -fPIC -shared -O2 -Wall -Wcast-align -Wcast-qual -Wimplicit  -Wpointer-arith -Wswitch -Wredundant-decls -Wreturn-type -Wunused -DNO_RT -Isrc/pcan/driver -Isrc/pcan/lib  -c src/pcblog.c -o src/pcblog.o
gcc -fPIC -shared -O2 -Wall -Wcast-align -Wcast-qual -Wimplicit  -Wpointer-arith -Wswitch -Wredundant-decls -Wreturn-type -Wunused -DNO_RT -Isrc/pcan/driver -Isrc/pcan/lib  -c src/pcbtrace.c -o src/pcbtrace.o
gcc -fPIC -shared -O2 -Wall -Wcast-align -Wcast-qual -Wimplicit  -Wpointer-arith -Wswitch -Wredundant-decls -Wreturn-type -Wunused -DNO_RT -Isrc/pcan/driver -Isrc/pcan/lib  -c src/pcan/lib/src/libpcanfd.c -o src/libpcanfd.o
gcc -shared -Wl,-soname,libpcanbasic.so -o libpcanbasic.so.4.3.1 src/libpcanbasic.o src/pcaninfo.o src/pcanlog.o src/pcbcore.o src/pcblog.o src/pcbtrace.o src/libpcanfd.o -lm 
ln -sf libpcanbasic.so.4.3.1 libpcanbasic.so
make[1]: Leaving directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/pcanbasic'
make[1]: Entering directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/pcaninfo'
*** Making PCANINFO
***
*** target=pcaninfo
*** version=1.0.2
*** PCAN_ROOT=../pcanbasic/src/pcan
*** gcc version=7
***
gcc src/main.c ../pcanbasic/src/pcanlog.c ../pcanbasic/src/pcblog.c ../pcanbasic/src/pcbtrace.c ../pcanbasic/src/pcbcore.c ../pcanbasic/src/pcaninfo.c ../pcanbasic/src/pcan/lib/src/libpcanfd.c -O2 -Wall -Wcast-align -Wcast-qual -Wimplicit  -Wpointer-arith -Wswitch -Wredundant-decls -Wreturn-type -Wunused -DNO_RT -I../pcanbasic/src -I../pcanbasic/src/pcan/driver -I../pcanbasic/src/pcan/lib  -lm  -o pcaninfo.1.0.2
ln -sf pcaninfo.1.0.2 pcaninfo
make[1]: Leaving directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/pcaninfo'
make[1]: Entering directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples'
make[2]: Entering directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples/python'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples/python'
make[2]: Entering directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples/c++'
***
*** Making PCANBasic C++ examples
***
*** target=pcanwrite pcanread pcaneventread pcaneventwrite
*** g++ version=7
*** PCANBASIC_ROOT=../../pcanbasic
***
g++ -I../../pcanbasic -I../../pcanbasic/src/pcan/driver -DNO_RT src/pcanwrite.cpp -L../../pcanbasic -Wl,-rpath ../../pcanbasic -lpcanbasic -o pcanwrite
g++ -I../../pcanbasic -I../../pcanbasic/src/pcan/driver -DNO_RT src/pcanread.cpp -L../../pcanbasic -Wl,-rpath ../../pcanbasic -lpcanbasic -o pcanread
g++ -I../../pcanbasic -I../../pcanbasic/src/pcan/driver -DNO_RT src/pcaneventread.cpp -L../../pcanbasic -Wl,-rpath ../../pcanbasic -lpcanbasic -o pcaneventread
g++ -I../../pcanbasic -I../../pcanbasic/src/pcan/driver -DNO_RT src/pcaneventwrite.cpp -L../../pcanbasic -Wl,-rpath ../../pcanbasic -lpcanbasic -o pcaneventwrite
make[2]: Leaving directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples/c++'
make[1]: Leaving directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples'

Code: Select all

~/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic$ sudo make install
[sudo] password for akash: 
make[1]: Entering directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/pcanbasic'
Considering PCANBasic library with FD support (PCAN driver >= 8.0)
cp libpcanbasic.so.4.3.1 /usr/lib/libpcanbasic.so.4.3.1
ln -sf /usr/lib/libpcanbasic.so.4.3.1 /usr/lib/libpcanbasic.so.4
ln -sf /usr/lib/libpcanbasic.so.4.3.1 /usr/lib/libpcanbasic.so.0
ln -sf /usr/lib/libpcanbasic.so.4 /usr/lib/libpcanbasic.so
cp PCANBasic.h /usr/include/PCANBasic.h
chmod 644 /usr/include/PCANBasic.h
/sbin/ldconfig
make[1]: Leaving directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/pcanbasic'
make[1]: Entering directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/pcaninfo'
cp pcaninfo.1.0.2 /usr/local/bin/pcaninfo
chmod 755 /usr/local/bin/pcaninfo
make[1]: Leaving directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/pcaninfo'
make[1]: Entering directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples'
make[2]: Entering directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples/python'
make[2]: Nothing to be done for 'install'.
make[2]: Leaving directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples/python'
make[2]: Entering directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples/c++'
#cp pcanwrite pcanread pcaneventread pcaneventwrite /usr/local/bin
make[2]: Leaving directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples/c++'
make[1]: Leaving directory '/home/akash/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples'
I tried running the python example file, PCANBasic.py, but it gives me the import library error, for which I started this thread.

Best Regards
Akash

Re: ImportError: No module named PCANBasic,on python

Posted: Mon 13. May 2019, 02:26
by MrSingh
I tried running the receivetest, and got the following output.

Code: Select all

$ /usr/local/bin/receivetest -f=/dev/pcan32 -e

receivetest Version "Release_20150611_n"  (www.peak-system.com)
------- Copyright (C) 2004-2009 PEAK System-Technik GmbH ------
receivetest comes with ABSOLUTELY NO WARRANTY.     This is free
software  and you are welcome  to redistribute it under certain
conditions.   For   details   see    attached   COPYING   file.

receivetest: device node="/dev/pcan32"
             Extended frames are accepted, init with 500 kbit/sec.
receivetest: driver version = Release_20190412_n
2928728910.987 receivetest: x - 0x00000001 4 00 00 00 00 
receivetest: pending CAN status 0x0020 read.
^Creceivetest: type            = usb
             Serial Number   = 0xffffffff
             Device Number   = 30
             count of reads  = 1
             count of writes = 0
             count of errors = 0
             count of irqs   = 26
             last CAN status = 0x0000
             last error      = 0
             open paths      = 1
             driver version  = Release_20190412_n
receivetest: finished (0): 1 message(s) received

Does this mean driver has not been correctly installed?

Re: ImportError: No module named PCANBasic,on python

Posted: Mon 13. May 2019, 11:09
by F.Vergnaud
Hello,

Can you copy the result of the following commands.

Code: Select all

# moves to the PCANBasic python example directory 
cd ~/PCAN/PCAN-Basic_Linux-4.3.1/
cd libpcanbasic/examples/python/

# fetches the name of the PCANBasic library that is loaded by python
grep -e '__m_dllBasic = cdll.LoadLibrary(".*")' PCANBasic.py

# asserts the above library exists in the filesystem
ls -al /usr/lib/`grep -e '__m_dllBasic = cdll.LoadLibrary(".*")' PCANBasic.py | sed 's:^.*"\(.*\)".*$:\1:'`
You should expect a valid symlink for the last command:

Code: Select all

lrwxrwxrwx 1 root root 26 13 mai   10:12 /usr/lib/libpcanbasic.so -> /usr/lib/libpcanbasic.so.4
Finally can you copy the output of the PCANBasic import from a python console:

Code: Select all

python2.7
>>> from PCANBasic import *
Thank you.

Re: ImportError: No module named PCANBasic,on python

Posted: Mon 13. May 2019, 16:08
by MrSingh
OK. The import works in the terminal now, although I did try before as well.
But Still does not work in PyCharm.
This is the output in Pycharm

Code: Select all

    from PCANBasic import *
ImportError: No module named PCANBasic
The result of the first set of commands is same as expected, but I will put it here for clarity.

Code: Select all

~/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples/python$ grep -e '__m_dllBasic = cdll.LoadLibrary(".*")' PCANBasic.py
            self.__m_dllBasic = cdll.LoadLibrary("libpcanbasic.so")

Code: Select all

~/PCAN/PCAN-Basic_Linux-4.3.1/libpcanbasic/examples/python$ ls -al /usr/lib/`grep -e '__m_dllBasic = cdll.LoadLibrary(".*")' PCANBasic.py | sed 's:^.*"\(.*\)".*$:\1:'`
lrwxrwxrwx 1 root root 26 maj 13 02:35 /usr/lib/libpcanbasic.so -> /usr/lib/libpcanbasic.so.4

Re: ImportError: No module named PCANBasic,on python

Posted: Mon 13. May 2019, 16:10
by MrSingh
MrSingh wrote:I tried running the receivetest, and got the following output.

Code: Select all

$ /usr/local/bin/receivetest -f=/dev/pcan32 -e

receivetest Version "Release_20150611_n"  (www.peak-system.com)
------- Copyright (C) 2004-2009 PEAK System-Technik GmbH ------
receivetest comes with ABSOLUTELY NO WARRANTY.     This is free
software  and you are welcome  to redistribute it under certain
conditions.   For   details   see    attached   COPYING   file.

receivetest: device node="/dev/pcan32"
             Extended frames are accepted, init with 500 kbit/sec.
receivetest: driver version = Release_20190412_n
2928728910.987 receivetest: x - 0x00000001 4 00 00 00 00 
receivetest: pending CAN status 0x0020 read.
^Creceivetest: type            = usb
             Serial Number   = 0xffffffff
             Device Number   = 30
             count of reads  = 1
             count of writes = 0
             count of errors = 0
             count of irqs   = 26
             last CAN status = 0x0000
             last error      = 0
             open paths      = 1
             driver version  = Release_20190412_n
receivetest: finished (0): 1 message(s) received

Does this mean driver has not been correctly installed?
But this behavior has still not changed.!!

Re: ImportError: No module named PCANBasic,on python

Posted: Mon 13. May 2019, 16:24
by F.Vergnaud
Sorry I didn't respond to your receivetest concern because it is working fine ;)
This tool infinetely waits for CAN messages, you are receiving a single message which is a status frame stating that the device is up and active.
You then hit Ctrl-C (^C) which closed the application.

Back to python, your issue lies within the configuration of PyCharm IDE: you have to specify where to find the file PCANBasic.py.