Forum Discussion

rjoyce's avatar
rjoyce
Occasional Contributor
2 years ago

Why is it so problematic to add python modules and why are there so many missing?

Why is it so problematic to add python modules and why are there so many missing?

There are many articles, however none of them really help.

I am trying to run a simple little script as a test, however I'm getting the no module pycurl error

This is a basic module that many people would use, so why isn't it part of the system and why can't I get it installed?

My Code:

import http.client
import pycurl

#import cStringIO
import re
import urllib.error
import urllib.request


def test2():
curl = pycurl.Curl()

buff = cStringIO.StringIO()
hdr = cStringIO.StringIO()

curl.setopt(pycurl.URL, 'http://example.org')
curl.setopt(pycurl.WRITEFUNCTION, buff.write)
curl.setopt(pycurl.HEADERFUNCTION, hdr.write)
curl.perform()

print("status code: %s" % curl.getinfo(pycurl.HTTP_CODE))
# -> 200

status_line = hdr.getvalue().splitlines()[0]
m = re.match(r'HTTP\/\S*\s*\d+\s*(.*?)\s*$', status_line)
if m:
status_message = m.groups(1)
else:
status_message = ''

print("status message: %s" % status_message)
# -> "OK"

 

The Error: ModuleNotFoundError: No module named 'pycurl' 14:22:35 Normal 0.00

5 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    From what I understand, TestComplete comes with minimal installation of Python, and each version of TestComplete comes with a version of Python. TestComplete v15.42.9.7 x64 comes with Python 3.8.10 x64.

     

    Therefore, you need to download the same version of Python and follow Python - Specifics of Usage

     

    Alternative method, is to open WHL file and extract the folder to e.g. <TestComplete>\x64\Bin\Extensions\Python\Python38\Lib (depending on your version) and use

    import sys
    sys.path.insert(0, "<TestComplete>\x64\Bin\Extensions\Python\Python38\Lib\site-packages")
    import your_library_name

     

    • rjoyce's avatar
      rjoyce
      Occasional Contributor

      I have pycurl here

      C:\Program Files (x86)\SmartBear\TestComplete 15\Bin\Extensions\Python\Python38\Lib\site-packages\curl

      My Code

      from os import sys
      sys.path.insert(0, 'C:\Program Files (x86)\SmartBear\TestComplete 15\Bin\Extensions\Python\Python38\Lib\site-packages')

      def test2():
            curl = pycurl.Curl()

       

      Generates the error: Python runtime error

      ModuleNotFoundError: No module named 'pycurl'

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I have installed Python 3.8.10 x64 in folder C:\Temp\Python\Python38, which is the exact same version that comes with TestComplete 15.42.9.7 x64. Also, I have installed pip install pycurl and pip install certifi

     

    If I run my Test1(), I get an error relating to the module name

    However, if I run Test2()

    The error is not relating to import pycurl but something else. This indicates that pycurl and certifi has been imported

    • rjoyce's avatar
      rjoyce
      Occasional Contributor

      pip install pycurl==7.43.0.5 gives the response

      Requirement already satisfied: pycurl==7.43.0.5 in c:\program files (x86)\smartbear\testexecutelite 15\x64\bin\extensions\python\python38\lib\site-packages (7.43.0.5)

      so now that I have the path of where it is installed, in testExecute mind you, not in testComplete, I add that path to my script:

      from os import sys
      sys.path.insert(0, 'C:\Program Files (x86)\SmartBear\TestExecuteLite 15\x64\Bin\Extensions\Python\Python38\Lib\site-packages')

       

      but when I execute, I still get the not found error

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Are you able to use the code, that's shown in the second picture (def Test2()) ?

     

    I had used TestCompletes Python from the command prompt to test that it was able to pick up the site-packages from the installed Python. I suggest you do the same, before you run any test cases in TestComplete

     

    Try this in Python,

     

    import pycurl

     

    Or

     

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

     

    If it fails, then it's not correctly setup.