0

I have a ROS application which has a work space with a setup.bash file and another python script with its own virtual environment.

So far this is what I do in my terminal:

1_ pipenv shell (to activate my python virtual environment).
2_ source ../ros_workspace/devel/setup.bash
3_ python some_python_script.py

This code works as I expect.

However, I want to do the same and run this script in pycharm, where my virtual environment is already activated. But how do I source the setup bash additionaly? My setup.bash file also looks like the following: enter image description here

What I have tried also is making a "before launch" as follows: enter image description here enter image description here

Alejandro
  • 879
  • 11
  • 27

1 Answers1

0

If you set your virtual environment as your interpreter of choice in PyCharm, it will use that particular virtual environment to run its scripts. However, you can also take advantage of some of the functionality that our run configurations provide.

enter image description here

You can check out the "Before Launch" part of the whole configuration window to enter scripts that you want executed.

Once you've set your configurations, you can then go on to run or debug the configuration. Furthermore, if it is just environment variables that you want to source, you can just put in the environment variables in the "Environment Variables" box.

In case you want to run a shellscript, you will need to create a new shell configuration like so:

enter image description here

Once you've added that configuration, you can then go on to reference it later.

You will now see that you can reference that configuration in question:

enter image description here

enter image description here

Games Brainiac
  • 80,178
  • 33
  • 141
  • 199
  • Thanks for your answer. I also added a picture of what's inside the setup.bash file. However, I'm not sure what to pick from inside it to put in my environmental variables in the configuration. For the "Before Launch" solution, I'm not sure also how, there seemed to be many choices when I wanted to add one. – Alejandro May 09 '20 at 18:50
  • @Azerila I've updated the answer. I hope this helps. – Games Brainiac May 09 '20 at 19:05
  • so I tried that also (shown in the updated images in the question) but still when I run the script it can't import a module as if I was running it in the terminal but without also sourcing that setub.bash file. – Alejandro May 09 '20 at 19:58