Command framework and PYTHONPATH


#1

Hello All,

Starting to move to Python for my team (I’m the programming mentor). I use it (somewhat) professionally, so am fairly conversant in it. However, I’m not much of an eclipse user (doing it only for the kids), preferring emacs in
the professional world.

I installed PyDev into Eclipse, and manually created the Command framework based on https://github.com/robotpy/examples/tree/master/command-based - when I say manually created, I created folders manually, and added new files into these folders manually. This results in a folder structure that looks like:
> pybot
>> Commands
>>>init.py
>>> AutoCommand.py
>>> setspeed.py
>>> timedMotor.py
>> Robot
>>> robot.py
>>> robotmap.py
>> Subsystems
>>> Motor.py

Eclipse thinks all is OK (no red flags indicating syntax problems). I’m able to do install-robotpy deploy --skip-tests to get the code transferred to the rio.

When I do install-robotpy run, I get:
File “/home/lvuser/py/robot.py”, line 7, in <module>
from Subsystems import Motor
ModuleNotFoundError: No module named ‘Subsystems’

I’m not sure what to do (if anything) with PYTHONPATH, and the README.md doesn’t make any references to the variable. Or, is there some other configuration thing I’ve not set up properly.

I’ve also tried running this from the command line on the driverstation laptop - robot.py --help - and I get the same error. I’ve tried setting PYTHONPATH to the project directory, to no avail.

Thanks for any help on this…


#2

Looking at the diagram you made of your file layout, robot.py appears to be in a sister directory (Robot) from Subsystems. That means that Subsystems is not in robot.py’s import path.


#3

You can solve this one of two ways.

  1. Add the Subsystems folder to PYTHONPATH, or call sys.path.append( path ) for it inside your code.
  2. Assuming the root “pybot” folder is on your python path already, just add an empty init.py file to the Subsystems folder, which declares it as a package containing importable modules.

#2 would by my recommendation.


#4

As stated by others, for best results your robot.py should be at the root of your robot code source tree.


#5

Sorry for being incommunicado for a while.

Moving the robot.py file to the same level as the commands and subsystem folders. did the trick.

Thank you all.