Forum Discussion

Alexmak85's avatar
Alexmak85
Occasional Contributor
7 years ago

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

  • baxatob's avatar
    baxatob
    Community Hero

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

    • Alexmak85's avatar
      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's avatar
        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
  • PythonAndTC's avatar
    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.