cancel
Showing results for 
Search instead for 
Did you mean: 

Calling 3rd party packages from scripts written in Python

SOLVED
Highlighted
Senior Member

Calling 3rd party packages from scripts written in Python

Hello,

 

I'm trying to import external 3rd party packages from my scripts written in Python language. Is there a way to use Python installed in different folder? I was trying to use default "site-packages" folder - I added 3rd party package to the folder, also copied whole content, installed it from commad line (by using PIP) and tried to call it from script, but TestComplete shows: "no module named requests".

 

I wrote in script also:

 

from os import sys
sys.path.append("C:\Data\Python\Lib\site-packages")

 

 

and then try to import 3rd party module, but there's also no effect. I don't want to use PyUnit, so is there any way to load 3rd party package in TestComplete in scripts?

 

Best Regards,

matju

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Contributor

Re: Calling 3rd party packages from scripts written in Python

TestComplete installs it's own python instance so the third-party package in the site-packages folder won't work. If you copy the third-party package you want from the site-packages into the TestComplete python folder it will work.

 

For example I use the pytz and tzlocal packages. After installing through pip, I copied those folders from the site-packages folder into C:\Program Files\SmartBear\TestComplete 11\Bin\Extensions\Python\Python34\Lib . Then just import like regular and it should work.

 

 

I think you could also add the site-packages folder to the sys path like you are in your code, I think the mistake you are making is not escaping the backslash character in your string or using a raw string. So it should be sys.path.append("C:\\Data\\Python\\Lib\\site-packages") or sys.path.append(r"C:\Data\Python\Lib\site-packages")

 

 

View solution in original post

7 REPLIES 7
Highlighted
Contributor

Re: Calling 3rd party packages from scripts written in Python

TestComplete installs it's own python instance so the third-party package in the site-packages folder won't work. If you copy the third-party package you want from the site-packages into the TestComplete python folder it will work.

 

For example I use the pytz and tzlocal packages. After installing through pip, I copied those folders from the site-packages folder into C:\Program Files\SmartBear\TestComplete 11\Bin\Extensions\Python\Python34\Lib . Then just import like regular and it should work.

 

 

I think you could also add the site-packages folder to the sys path like you are in your code, I think the mistake you are making is not escaping the backslash character in your string or using a raw string. So it should be sys.path.append("C:\\Data\\Python\\Lib\\site-packages") or sys.path.append(r"C:\Data\Python\Lib\site-packages")

 

 

View solution in original post

Highlighted
Contributor

Re: Calling 3rd party packages from scripts written in Python

But i still encounter error:

ImportError

No module named 'win32com' 

 

i have copy site-packages from C:\Program Files (x86)\Python36-32\Lib\site-packages  to C:\Program Files (x86)\SmartBear\TestComplete 12\Bin\Extensions\Python\Python34\Lib\site-packages

 

but seem not working. when i try to import:

import win32com.client as win32

 

Highlighted
Contributor

Re: Calling 3rd party packages from scripts written in Python

Did you copy your entire site-packages folder or just the win32com folder? You don't want the whole site-packages folder, only the folder of the third party package should go in the Lib folder, i.e. only copy the win32com folder into Lib, not entire site-packages.

Highlighted
Contributor

Re: Calling 3rd party packages from scripts written in Python

Thanks, i copied the win32com folder to Lib only now. but another error pops when i run the script

 

ImportError No module named 'win32api'

Error location: Unit: "HorizonTestSuite\HorizonAutoTest\Script\genfuncs"

Line: 7 Column: 1.

 
 
It is weird since i didn't use win32api, my script only import win32com.client
 
import win32com.client as win3
Highlighted
Community Hero

Re: Calling 3rd party packages from scripts written in Python

Hi,

 

I'm not a Python guy and don't have TC at hand as we speak, so just a wild guess: I believe that win32api is referenced from win32com module. Have you checked if there is win32api folder within site-packages one and have you copied it to lib\ folder for TestComplete?

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted
Contributor

Re: Calling 3rd party packages from scripts written in Python

Thank you. Still not work. Anyway, i've tried use OLE now. Need re-write my code.

Highlighted
Contributor

Re: Calling 3rd party packages from scripts written in Python

You need to copy all related folders from site-packages to Lib folder as suggested. You can check by date and time you installed your win32. Unless all related folder copy, you will see those type of errors.

New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
Let's start July with new challenges!

Create a script to pass custom command-line arguments as a test parameter for the TechCorner tag!

Will you dare to take the challenge?


Top Kudoed Authors