DesiVirgo
DesiVirgo

Reputation: 11

TestComplete error for Panda library Import "OSError: [WinError 193] %1 is not a valid Win32 application"

I am facing this below given error for Pandas library only via Testcomplete. I am able to add path of libraries with given code. Even other library xlrd is also working but issue only coming for Pandas library. As error is mentioning 32bit so only anomaly I see is that OS is 64 bit, TestComplete is also 64 bit but Python which is installed as part of Testcomplete is 32 bit. Whether anything to be changed to Python version of 32 bit or it is code issue;

Note: When i use Python directly on command prompt shell and try to import pandas in that compiler and run basic function of pandas so it is working there. problem seems only when I load pandas in TestComplete.

Code: import sys sys.path.append("C:\Program Files (x86)\SmartBear\TestComplete 15\Bin\Extensions\Python\Python38\Lib\site-packages\") import xlrd

#sys.path.append("C:\Program Files (x86)\SmartBear\TestComplete 15\Bin\Extensions\Python\") #pandas_loc="C:\Program Files (x86)\SmartBear\TestComplete 15\Bin\Extensions\Python\Python38\Lib\site-packages\" #sys.path.insert(0,pandas_loc)

import pandas as pd

def main(): workbook = xlrd.open_workbook("C:\Users\user\Downloads\Test1.xls")

Error OSError: [WinError 193] %1 is not a valid Win32 application

OS Processor 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz 3.00 GHz System type 64-bit operating system, x64-based processor Edition Windows 10 Enterprise Version 20H2 OS build 19042.1466 Experience Windows Feature Experience Pack 120.2212.3920.0

TestComplete Version: 15.20.341.7 x64

Python Python 3.8.10 (tags/v3.8.10:3d8993a, May 3 2021, 11:34:34) [MSC v.1928 32 bit (Intel)] on win32 python : 3.8.10.final.0 python-bits : 32 OS : Windows OS-release : 10 Version : 10.0.19042 machine : AMD64 processor : Intel64 Family 6 Model 140 Stepping 1, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : English_United States.1252

Panda Library Name: pandas Version: 1.4.1 Summary: Powerful data structures for data analysis, time series, and statistics Home-page: https://pandas.pydata.org Author: The Pandas Development Team Author-email: [email protected] License: BSD-3-Clause Location: c:\program files (x86)\smartbear\testcomplete 15\bin\extensions\python\python38\lib\site-packages Requires: numpy, python-dateutil, pytz Required-by:

Python Libraries Package Version


numpy 1.22.2 pandas 1.4.1 pip 22.0.3 python-dateutil 2.8.2 pytz 2021.3 setuptools 56.0.0 six 1.16.0 xlrd 2.0.1

Upvotes: 1

Views: 340

Answers (1)

Dermot Canniffe
Dermot Canniffe

Reputation: 36

So, there's a few issues here;

Firstly, your paths should have double-slashes so the path delimiter is properly escaped, e.g. "C:\\Program Files (x86)\\..."

Secondly, you shouldn't need to explicitly append the TestComplete Python Library path, since that's automatic.

Thirdly, the Library path you're attempting to append is the path for TestComplete's 32bit Python interpreter. The 64bit Python Library is here;

<TestComplete>\x64\Bin\Extensions\Python\Python38\Lib

Lastly, it may be better to approach imports by referencing Python installed for the system (provided it matches the TestComplete python version, at time of writing with TestComplete v15 this is Python v3.8 ). This way you can use System environment variables, Aliases etc. and use Pip to install packages and dependencies.

If you've co-installed a more recent version of Python, you can create Powershell aliases to your older version by following these instructions. E.g.

Set-Alias pip38 "C:\Python38\scripts\pip.exe"

Then you need to make sure your required packages are installed;

pip38 install pandas

In TestComplete's script editor, you can then insert the system Python 3.8 Library path - wherever you installed it - and import whatever package you require;

import sys
sys.path.insert(0,'C:\\Python38\\Lib\\site-packages')
import numpy
import pandas as pd
import xlrd

user = Project.Variables.WindowsUser
workbook_file = "C:\\Users\\" + user + "\\Downloads\\Test1.xlsx"

def main(): 
  workbook = xlrd.open_workbook(workbook_file)

You can find further information on working with Python within TestComplete in the documentation.

Upvotes: 1

Related Questions