Ask a Question

Python: fail to import lib during the second attempt to run script

Alexmak85
Occasional Contributor

Python: fail to import lib during the second attempt to run script

Test Complete 12.3

Python 3.6

 

Trying to import win32com.client

First run is ok.

Second run: import failed with 'NoneType' object is not callable.

 

After restart Test Complete the same result: first run is ok, second is failed.

Such problem with most external libraries.

 

How it can be fixed?

9 REPLIES 9
baxatob
Community Hero

Please show, where and how do you import the library.

Alexmak85
Occasional Contributor

x64 Win7 1)Install TC12.3 2) Install Python 3.6.x (x64) to folder where we have TC Python: C:\Program Files (x86)\SmartBear\TestComplete 12\Bin\Extensions\Python\Python36 to get it registered, to get pip and full Python I download and install Python (x64), but can see in cmd that i have x86 Python (!??!!?) So, i can install only x86 libs. 3) donwload x86 lib and install via pip: pywin32-221-cp36-cp36m-win32.whl Aftre this i use: import sys sys.path.insert(0, r'C:\Program Files (x86)\SmartBear\TestComplete 12\Bin\Extensions\Python\Python36\Lib\site-packages') sys.path.insert(0, r'C:\Program Files (x86)\SmartBear\TestComplete 12\Bin\Extensions\Python\Python36\Lib\site-packages\win32') sys.path.insert(0, r'C:\Program Files (x86)\SmartBear\TestComplete 12\Bin\Extensions\Python\Python36\Lib\site-packages\win32\lib') import win32com.client
Alexmak85
Occasional Contributor

x64 Win7 1)Install TC12.3 2) Install Python 3.6.x (x64) to folder where we have TC Python: C:\Program Files (x86)\SmartBear\TestComplete 12\Bin\Extensions\Python\Python36 to get it registered, to get pip and full Python I download and install Python (x64), but can see in cmd that i have x86 Python !? So, i can install only x86 libs. 3) donwload x86 lib and install via pip: pywin32-221-cp36-cp36m-win32.whl Aftre this i use: import sys sys.path.insert(0, r'C:\Program Files (x86)\SmartBear\TestComplete 12\Bin\Extensions\Python\Python36\Lib\site-packages')  sys.path.insert(0, r'C:\Program Files (x86)\SmartBear\TestComplete 12\Bin\Extensions\Python\Python36\Lib\site-packages\win32') sys.path.insert(0, r'C:\Program Files (x86)\SmartBear\TestComplete 12\Bin\Extensions\Python\Python36\Lib\site-packages\win32\lib') import win32com.client
Alexmak85
Occasional Contributor

Please, suggest: if i have test complete x86 (inside Python is also x86) , but win7 x64 Should i install full Python x86? What place is better to install: usual (c:) or to testcomplet/ext/bin/python?
Alexmak85
Occasional Contributor

What i found about win32 api for Python.  It turned out that win32com.client couldn't be imported more than once within the same process. Sorry, this is a limitation of the PyGILState API used by pywin32; pywin32 will never be able to play with the multiple interpreter API, nor work correctly with multiple interpreter initializations and cleanups. But such problem occurs with another libraries. For example, with lxml. Second import cause Test Complete crash 🙂

Hi,

 

 

TestComplete has its own Python interpreter and you do not need to install another one, especially you should not install new  interpreter into the TestComplete directory, because it can override important dependencies and cause conflicts.

 

Alexmak85
Occasional Contributor

But to install third party Python libs we need full Python with pip, or we're not?

You can download any required package manually and then install it using setup.py script.

Also you can install pip itself to work with your TestComplete Python installation. 

 

Spoiler
NB! For the some reason SmartBear does not include pip installer by default. So you will do it on your own risk.

 

https://packaging.python.org/tutorials/installing-packages/

PythonAndTC
Occasional Contributor

TestComplete cannot work correctly with the win32com Python library because this library cannot work after the reinitialization of the Python interpreter. You can find the same information on the official SourceForge page (https://sourceforge.net/p/pywin32/bugs/445/😞 "pywin32 will never be able to play with the multiple interpreter API, nor work correctly with multiple interpreter initializations and cleanups". And, that's why, it could work successfully only one time, and, after this, you needed to relaunch the tool.

cancel
Showing results for 
Search instead for 
Did you mean: