Page 1 of 1

OSError: [WinError 126] The specified module could not be found

Posted: Sat 20. Feb 2021, 17:42
by Bobity
I have a simple python program using PCANBasic. It fails on execution with the following:

Code: Select all

C:\My_Docs\...\NF_Processing\venv\Scripts\python.exe C:/My_Docs/.../NF_Processing/PCAN_Test.py
Traceback (most recent call last):
  File "C:/My_Docs/.../NF_Processing/PCAN_Test.py", line 28, in <module>
    objPCAN = PCANBasic()
  File "C:\My_Docs\...\NF_Processing\PCANBasic.py", line 378, in __init__
    self.__m_dllBasic = windll.LoadLibrary("C:\\MY Docs\\Phd\\PCAN-Basic API\\x64\\PCANBasic")
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\ctypes\__init__.py", line 442, in LoadLibrary
    return self._dlltype(name)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\ctypes\__init__.py", line 364, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

Process finished with exit code 1

The python program PCAN_Test.py is:

Code: Select all

import sys
#import pyodbc
import numpy as np
import pandas as pd
import random
import time

import ctypes
from ctypes import *
#from ctypes import wintypes

sys.path.append('''C:\Python34\Projects\ARM''')
sys.path.append('''C:\Python34\Lib\site-packages\python_can-1.4-py3.4.egg\can\interfaces''')
sys.path.append('''C:\My_Docs\PhD\PCAN-Basic API\x64''')
#sys.path.append('''C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Lib\ctypes''')
#sys.path.append(['C:\My_Docs\PhD\PCAN-Basic API\x64\'])

from PCANBasic import *
channel = PCAN_USBBUS1
#channel = PCAN_USBBUS2
baud = PCAN_BAUD_500K
timeprev = 0.0

## The Plug & Play Channel (PCAN-USB) is initialized
##
#objPCAN =# The Plug & Play Channel (PCAN-USB) is initialized
#
objPCAN = PCANBasic()
result = objPCAN.Initialize(channel, baud)
There is probably something very simple I'm doing wrong but have no idea what it is.

Thanks

Rob

Re: OSError: [WinError 126] The specified module could not be found

Posted: Mon 22. Feb 2021, 07:32
by M.Heidemann
Hello,

Is this error reproducable, if the PCANBasic API was installed using the PEAK-Device Driver Setup?

Dowload Peak Device Driver Setup:

https://www.peak-system.com/quick/DrvSetup

Make sure to check the "PCANBasic" option during the setup:
DriverSetupPcanBasic.PNG
DriverSetupPcanBasic.PNG (31.46 KiB) Viewed 9468 times
Please report back to us if this was able to resolve the issue.

Best Regards

Marvin

Re: OSError: [WinError 126] The specified module could not be found

Posted: Sat 27. Feb 2021, 16:26
by Bobity
Marvin,

Tried what you suggested - Rebooted after. Still get a similar error:

Code: Select all

C:\My_Docs\PhD\NF_Processing\venv\Scripts\python.exe C:/My_Docs/PhD/NF_Processing/PCAN_Test.py
Traceback (most recent call last):
  File "C:/My_Docs/PhD/NF_Processing/PCAN_Test.py", line 28, in <module>
    objPCAN = PCANBasic()
  File "C:\My_Docs\PhD\NF_Processing\PCANBasic.py", line 378, in __init__
    self.__m_dllBasic = windll.LoadLibrary("C:\\MY Docs\\Phd\\PCAN-Basic API\\x64\\PCANBasic")
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\ctypes\__init__.py", line 442, in LoadLibrary
    return self._dlltype(name)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\ctypes\__init__.py", line 364, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

Process finished with exit code 1
no external download allowed - removed by admin

Thanks

Rob

Re: OSError: [WinError 126] The specified module could not be found

Posted: Sun 28. Feb 2021, 11:39
by PEAK-Support
You mix up 32/64 Bit DLLs. Search on your PC in all folders the file "pcanbasic.dll " - delete them all.
Run the Setup again as my colleauge wrote in the last post - select PCANBasic API.

If you want to understand read this:
viewtopic.php?f=116&t=886
and
viewtopic.php?f=41&t=870

We use Python (2.x and 3.x) with 32 and 64 Bit DLLs and Runtime, since years - it works without any problem if the environment is setup correct.

Re: OSError: [WinError 126] The specified module could not be found

Posted: Thu 4. Mar 2021, 16:45
by Bobity
I ended up changing the reference to PCANBasic in PCANBasic.py thus which solved the problem:

if platform.system() == 'Windows':
# self.__m_dllBasic = windll.LoadLibrary("C:\\MY Docs\\Phd\\PCAN-Basic API\\x64\\PCANBasic")
# self.__m_dllBasic = windll.LoadLibrary("C:\\Windows\\SysWOW64\\PCANBasic")
self.__m_dllBasic = windll.LoadLibrary("C:\\Windows\\System32\\PCANBasic")


Thanks for your help

Rob

Re: OSError: [WinError 126] The specified module could not be found

Posted: Thu 4. Mar 2021, 16:57
by PEAK-Support
Also a solution!