2

I have two packages named pkg1 and pkg2. The pkg1 is part of a workspace labeled abc in /home/csbales while pkg2 is a part of a workspace labeled catkin_ws in /home/csbales. To source them and ROS, which they use, I have added the following three lines to the .bashrc:

source /opt/ros/melodic/setup.bash
source ~/catkin_ws/devel/setup.bash
source ~/abc/build/devel/setup.bash

I launch Pycharm Community from a fresh terminal, with pkg2 as the project folder (~/catkin_ws/src/pkg2). I am wanting to run a python script that imports from both packages, starting like so:

#!/usr/bin/env python
import sys
# from os import sys, path
# sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
from pkg2 import Thing2
from pkg1 import Thing1

When I run the python script, I receive the following error:

ModuleNotFoundError: No module named 'pkg2'

To check if pkg1 is being recognized at the very least, I switch the order of the pkg lines and receive the same error as before. I then open a new terminal, directly source pkg2 with

source ~/catkin_ws/devel/setup.bash

in the terminal, and then open Pycharm with the same terminal. When I run the same script, I receive the following error:

ModuleNotFoundError: No module named 'pkg1'

I switch the import lines so that pkg1 comes after pkg2 and run it again, but I get the error with pkg1. Importing pkg2 seemingly works as desired now, but pkg1 does not when it had before. I tried switching the lines in the .bashrc and then opening Pycharm, but the package not sourced last would always cause the ModuleNotFoundError, whether it be a combination of sourcing via terminal or in the .bashrc.

I tried remaking each workspace. I tried deleting and cloning them again. None of that worked. I am not able to combine them. Just to see, I tried moving the ROS source line around in the .bashrc to find that its placement had no effect on the above behavior. ROS would work regardless. I don't know where to go from here and would greatly appreciate any input.

Maybe relevant info:

  • Ubuntu 18.04
  • Using Terminator
  • Pycharm Community
  • Python 3.6
CSBales
  • 21

0 Answers0