How to Solve ModuleNotFoundError: No module named 'tencentcloud' on Tencent Serverless Cloud Function?


You are excited to use Tencent Serverless Cloud Function to do your automation. You are following the Tencent API Explorer and you are ready to rock yet when you test your Python code; you encountered ModuleNotFoundError: No module named 'tencentcloud'. This is a guide on how to solve this error and explanations of why you need to do those steps. 

How to solve this error

According to Tencent Cloud's Serverless Cloud Function's Dependency Installation guide, there are two ways to solve this problem. 

  1. Package the dependency libraries and code together for upload - I haven't tried this so if you did and it works, please feel free to write a post and comment here.
  2. Use dependency management tools.

Use dependency management tools to solve this error

I'm going to use the same steps as shown in the guide. I will add pictures and edit the steps so that it will be easier for you. 

  1. Log in to the SCF console and select Function Service on the left sidebar.

  2. In the function list, click a function name to enter the function details page.

  3. On the Function Management page, select Function Code to view and edit the function.

  4. Select the terminal on the Serverless Web IDE.

  5. Run the following commands in the terminal to install the tencentcloud dependency library. Note: Please use pip3 if you are using Python 3 and use pip if you are using Python 2. Also, please do not forget the dot in the second command.
    cd src
    pip3 install tencentcloud-sdk-python -t .

  6. After the installation is completed, view the installed dependency libraries in the file tree on the left side of the IDE. If the tree looks different, you probably forgot to cd src. If you encountered the problem of ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE., try running any other commands then rerun the above command. It will somehow resolve itself. If you know why it happens, please let me know in the comments.



  7. Deploy!


Do let me know if this works for you or not. I wish you luck in whatever you are building. 


Popular posts from this blog

How to Auto Convert Malaysian IC Number to Birthdays Using Excel (Updated to Support Millennials)

How to Prepare for a Table Topics Compeition?