Unable to import python packages in vscode

Hi Experts,

I am trying to use Camelot package in vs code.
Conda.yaml file:
channels:

  • conda-forge

dependencies:

  • python=3.7.5

  • pip=20.1

  • camelot-py=0.9.0

  • pip:

    • rpaframework==12.1.1

After adding it here I am trying to use it in Test.py but showing an error like this: Import “camelot” could not be resolved

Test.py file:
import camelot

def extract_table(self, pdf, table_index=0):

    tables = camelot.read_pdf(pdf, pages='1-end')

    return tables[table_index].df

Thanks

Hi desineediaditya,

I was able to replicate your error and believe it comes down to the fact that you are running the robot outside of the RCC environment (the RCC environment is what is set in the conda.yaml file). I am tracking down some more specific examples to help better explain how to resolve this for you. It may be a few days before I can get back to you on this. In the mean time can you let me know how you are trying to run the robot. RCC command line, VS Code terminal, or the VS Code command pallet “Robocorp: Run Robot”?

Best,
Tim

Hi @Tim

Thanks for your response.

I am running this from VS Code terminal.

Hi @desineediaditya

Thank you for the additional details. Your issue is related to how you are trying to run the robot. When you run in the VS Code terminal it tries to execute in the local environment. In this case the camalot-py library was loaded in the RCC environment via the conda.yaml file

Running RCC vs Local Environment v2

TL;DR

In order to run in the RCC environment you need to do one of two things 1) Use cmd+shift+P (mac) or ctrl+shift+p (windows) and then type “run robot”. This will run the robot via RCC and should provided the expected results. This is also the preferred method 2) if you want to use a terminal to run your robot you need to run from the Robocorp terminal that can be found in VS Code. Select the Robocorp logo on the left hand panel in VS Code Screen Shot 2022-01-05 at 2.56.40 PM and then in the “ROBOTS” panel select the terminal icon next to your robot Screen Shot 2022-01-05 at 3.03.49 PM. This will allow you to execute the robot using “rcc run task.py” command.

Let me know if you are still having issues.

Best,
Tim

1 Like

@Tim

When I closed the visual studio completely and tried it again, it worked.

Just for info.

Thanks a lot for your inputs.

Hi, Chiming in here a bit late,
Definitely recommend using the run methods @Tim suggests as you really do not need to be in the command-line running things :wink:

This case also probably has to do with the VS Code built-in Python extensions which is really keen on just selecting Python environments that are installed on the system, this is exactly what we need to avoid as keeping the environments isolated is the only way we can keep the bots movable and enable executing in the same way.

The solution to this at the moment is running the command:
Robocorp: Set pythonpath based on robot.yaml
…via command palette (CTRL+SHIFT+P)
The command sets the correct environment that has the dependencies you define into the workspace settings of your robot. In @Tim’s picture above you can see the active python environment in the bottom left blue bar.

We are looking for ways to make this automatic or at least a bit more visible.

We are also driving to get an API into to default Python extension developed by Microsoft in here… so all votes and support is appreciated.