PhotonVision import failing

When VS code is closed and reopened the PhotonLib import in our files appears to fail. The band-aid solution that I have found is to uninstall the PhotonVision library and reinstall it. I am unsure of what could be causing this issue but I think it has something to do with the way that PhotonVision is stored on my laptop.

Error reads as follows:
C:\Users\kphan\OneDrive\Documents\GitHub\ChargedUp2023\src\main\java\frc\robot\commands\AimTarget.java:7: error: package org.photonlib does not exist
import org.photonlib.PhotonUtils;
^
C:\Users\kphan\OneDrive\Documents\GitHub\ChargedUp2023\src\main\java\frc\robot\commands\AimTarget.java:38: error: cannot find symbol
range = PhotonUtils.calculateDistanceToTargetMeters(CameraConstants.cameraHeightMeters, CameraConstants.goalDistanceMeters, CameraConstants.cameraAngleRadians, Units.degreesToRadians(result.getBestTarget().getPitch()));
^
symbol: variable PhotonUtils
location: class AimTarget
2 errors
Both of these errors are in Constants

Link to our Github

I see your code is in OneDrive. Iirc this is known to cause weird problems.

Also, where is that error message from? Does it happen when you try to build robot code?

1 Like

I should have clarified in the post but yes this is occurring when I build.

I second this. A few of my students have odd build issues when using OneDrive. Start by moving your robot project outside of OneDrive and try again.

After a bit of messing around with trying to get it out of OneDrive I got it out and rebuilt it, the new error that appears is as follows:
C:\GitHub\ChargedUp2023\src\main\java\frc\robot\commands\AimTarget.java:7: error: package org.photonlib does not exist
import org.photonlib.PhotonUtils;
^
C:\GitHub\ChargedUp2023\src\main\java\frc\robot\commands\AimTarget.java:38: error: cannot find symbol
range = PhotonUtils.calculateDistanceToTargetMeters(CameraConstants.cameraHeightMeters, CameraConstants.goalDistanceMeters, CameraConstants.cameraAngleRadians, Units.degreesToRadians(result.getBestTarget().getPitch()));
^
symbol: variable PhotonUtils
location: class AimTarget
2 errors

it doesn’t appear to be an issue with one drive, I also tried to uninstall and reinstall the library to still have the same error.

Edit: I should add that I am on Windows 11 at this moment however I do not believe this should matter, like at all.

Can you post a link to your code on GitHub?

It appears that the import should be org.photonvision.PhotonUtils

That fixed the issue, now I’m curious why VS code auto-imported photonlib and not photonvision