Migrate everything to upstream pip packages

This patch migrates all the Python packages I could find to the
packages provided by rules_python. It's possible that there are some
that I missed. In that case, the finder will have to migrate it on
their own.

A future patch will remove the remaining references to the
Debian-packaged Python packages in future patches. This patch here is
solely focused on migrating the existing users.

Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: Ic7a8ba6110516aa2446ad2ad4e2495fab62d824c
diff --git a/.bazelrc b/.bazelrc
index ce727ec..831889e 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -6,6 +6,7 @@
 
 # Default to py3 since that's all we support
 build --python_version=PY3
+build --incompatible_default_to_explicit_init_py
 
 # For now we only support building on x86 Linux so we can hard-code the host
 # platform.
@@ -21,7 +22,7 @@
 
 # Shortcuts for selecting the target platform.
 build:k8 --platforms=//tools/platforms:linux_x86
-build:k8_upstream_python --platforms=//tools/platforms:linux_x86_upstream_python --host_platform=//tools/platforms:linux_x86_upstream_python
+build:k8_legacy_python --platforms=//tools/platforms:linux_x86_legacy_python --host_platform=//tools/platforms:linux_x86_legacy_python
 build:roborio --platforms=//tools/platforms:linux_roborio
 build:roborio --platform_suffix=-roborio
 build:armv7 --platforms=//tools/platforms:linux_armv7
diff --git a/build_tests/BUILD b/build_tests/BUILD
index 718e817..ea05c0b 100644
--- a/build_tests/BUILD
+++ b/build_tests/BUILD
@@ -100,15 +100,14 @@
     srcs = ["python_opencv.py"],
     main = "python_opencv.py",
     target_compatible_with = ["@platforms//os:linux"],
-    deps = ["@opencv_contrib_nonfree_amd64//:python_opencv"],
+    deps = ["@pip//opencv_python"],
 )
 
 py_test(
     name = "python_jinja2",
     srcs = ["python_jinja2.py"],
-    srcs_version = "PY2AND3",
     target_compatible_with = ["@platforms//os:linux"],
-    deps = ["@python_jinja2"],
+    deps = ["@pip//jinja2"],
 )
 
 go_binary(
diff --git a/debian/glog.BUILD b/debian/glog.BUILD
index 8de9b80..091a966 100644
--- a/debian/glog.BUILD
+++ b/debian/glog.BUILD
@@ -5,6 +5,6 @@
     ],
     visibility = ["//visibility:public"],
     deps = [
-        "//external:python-gflags",
+        "@pip//python_gflags",
     ],
 )
diff --git a/debian/matplotlib.bzl b/debian/matplotlib.bzl
index 4e9feb8..dfb2591 100644
--- a/debian/matplotlib.bzl
+++ b/debian/matplotlib.bzl
@@ -204,6 +204,6 @@
         ],
         visibility = ["//visibility:public"],
         deps = [
-            "@python_repo//:numpy",
+            "@pip//numpy",
         ],
     )
diff --git a/debian/opencv_python.BUILD b/debian/opencv_python.BUILD
index 8d2ef2a..f4911ab 100644
--- a/debian/opencv_python.BUILD
+++ b/debian/opencv_python.BUILD
@@ -11,6 +11,6 @@
     ],
     visibility = ["//visibility:public"],
     deps = [
-        "@python_repo//:numpy",
+        "@pip//numpy",
     ],
 )
diff --git a/debian/osqp_python.BUILD b/debian/osqp_python.BUILD
index b790a75..72eafab 100644
--- a/debian/osqp_python.BUILD
+++ b/debian/osqp_python.BUILD
@@ -11,8 +11,8 @@
     ],
     visibility = ["//visibility:public"],
     deps = [
-        "@python_repo//:numpy",
-        "@python_repo//:scipy",
+        "@pip//numpy",
+        "@pip//scipy",
         "@qdldl_amd64//:python_qdldl",
     ],
 )
diff --git a/debian/python.BUILD b/debian/python.BUILD
index 803e4bd..86a3e5d 100644
--- a/debian/python.BUILD
+++ b/debian/python.BUILD
@@ -10,7 +10,10 @@
         "usr/include/",
         "usr/include/python3.9/",
     ],
-    target_compatible_with = ["@platforms//cpu:x86_64"],
+    target_compatible_with = [
+        "@platforms//cpu:x86_64",
+        "@//tools/platforms/python:debian_bundled_python",
+    ],
     visibility = ["//visibility:public"],
 )
 
@@ -29,6 +32,9 @@
     includes = [
         "usr/lib/python3/dist-packages/numpy/f2py/src/",
     ],
+    target_compatible_with = [
+        "@//tools/platforms/python:debian_bundled_python",
+    ],
     visibility = ["//visibility:public"],
     deps = [
         ":python3.9_lib",
diff --git a/debian/qdldl_python.BUILD b/debian/qdldl_python.BUILD
index d270029..4120154 100644
--- a/debian/qdldl_python.BUILD
+++ b/debian/qdldl_python.BUILD
@@ -11,7 +11,7 @@
     ],
     visibility = ["//visibility:public"],
     deps = [
-        "@python_repo//:numpy",
-        "@python_repo//:scipy",
+        "@pip//numpy",
+        "@pip//scipy",
     ],
 )
diff --git a/frc971/analysis/BUILD b/frc971/analysis/BUILD
index 9904132..b50e84e 100644
--- a/frc971/analysis/BUILD
+++ b/frc971/analysis/BUILD
@@ -17,8 +17,8 @@
         "//aos/events:shm_event_loop",
         "//aos/events:simulated_event_loop",
         "//aos/events/logging:log_reader",
+        "//third_party/python",
         "@com_github_google_glog//:glog",
-        "@python_repo//:python3.9_lib",
     ],
 )
 
diff --git a/frc971/control_loops/python/BUILD b/frc971/control_loops/python/BUILD
index ef7b31b..7b46439 100644
--- a/frc971/control_loops/python/BUILD
+++ b/frc971/control_loops/python/BUILD
@@ -26,10 +26,10 @@
     legacy_create_init = False,
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//glog",
+        "@pip//matplotlib",
+        "@pip//python_gflags",
     ],
 )
 
@@ -48,8 +48,8 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-glog",
-        "@python_repo//:scipy",
+        "@pip//glog",
+        "@pip//scipy",
     ],
 )
 
@@ -76,7 +76,7 @@
     deps = [
         ":controls",
         ":python_init",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//matplotlib",
     ],
 )
 
@@ -89,7 +89,7 @@
     deps = [
         ":controls",
         ":python_init",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//matplotlib",
     ],
 )
 
@@ -116,7 +116,7 @@
     deps = [
         ":libspline",
         ":python_init",
-        "@python_repo//:numpy",
+        "@pip//numpy",
     ],
 )
 
@@ -130,8 +130,8 @@
         ":controls",
         ":drivetrain",
         ":python_init",
-        "//external:python-glog",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//glog",
+        "@pip//matplotlib",
     ],
 )
 
@@ -152,7 +152,7 @@
         ":controls",
         "//aos/util:py_trapezoid_profile",
         "//frc971/control_loops:python_init",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//matplotlib",
     ],
 )
 
@@ -165,7 +165,7 @@
         ":controls",
         "//aos/util:py_trapezoid_profile",
         "//frc971/control_loops:python_init",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//matplotlib",
     ],
 )
 
@@ -193,8 +193,10 @@
         ":drawing_constants",
         ":libspline",
         ":python_init",
-        "@matplotlib_repo//:matplotlib3",
-        "@python_gtk",
+        "@pip//matplotlib",
+        "@pip//numpy",
+        "@pip//pygobject",
+        "@pip//scipy",
     ],
 )
 
@@ -208,7 +210,7 @@
     deps = [
         ":constants",
         ":python_init",
-        "@python_gtk",
+        "@pip//pygobject",
     ],
 )
 
@@ -235,7 +237,7 @@
         ":controls",
         ":linear_system",
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
diff --git a/motors/fet12/BUILD b/motors/fet12/BUILD
index bf94f52..968c592 100644
--- a/motors/fet12/BUILD
+++ b/motors/fet12/BUILD
@@ -86,7 +86,7 @@
     ],
     target_compatible_with = ["@platforms//os:linux"],
     deps = [
-        "@python_repo//:scipy",
+        "@pip//scipy",
     ],
 )
 
@@ -98,7 +98,7 @@
     target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":calib_sensors",
-        "@python_repo//:scipy",
+        "@pip//scipy",
     ],
 )
 
diff --git a/motors/python/BUILD b/motors/python/BUILD
index 2b2b80b..0d9ea32 100644
--- a/motors/python/BUILD
+++ b/motors/python/BUILD
@@ -7,11 +7,11 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
-        "@matplotlib_repo//:matplotlib3",
-        "@python_repo//:scipy",
+        "@pip//glog",
+        "@pip//matplotlib",
+        "@pip//python_gflags",
+        "@pip//scipy",
     ],
 )
 
@@ -24,9 +24,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
diff --git a/motors/seems_reasonable/BUILD b/motors/seems_reasonable/BUILD
index a9eb95b..b899ffb 100644
--- a/motors/seems_reasonable/BUILD
+++ b/motors/seems_reasonable/BUILD
@@ -7,9 +7,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:drivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -23,9 +23,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
diff --git a/tools/build_rules/BUILD b/tools/build_rules/BUILD
index aeb8517..111d9d0 100644
--- a/tools/build_rules/BUILD
+++ b/tools/build_rules/BUILD
@@ -10,7 +10,7 @@
     srcs = ["jinja2_generator.py"],
     target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
-    deps = ["@python_jinja2"],
+    deps = ["@pip//jinja2"],
 )
 
 py_binary(
@@ -22,5 +22,5 @@
     ],
     target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
-    deps = ["@python_jinja2"],
+    deps = ["@pip//jinja2"],
 )
diff --git a/tools/ci/buildkite.yaml b/tools/ci/buildkite.yaml
index 30a7e24..e20c523 100644
--- a/tools/ci/buildkite.yaml
+++ b/tools/ci/buildkite.yaml
@@ -19,13 +19,6 @@
       - tools/ci/clean-disk.sh
       - tools/bazel ${STARTUP} --output_base=../k8_output_base test ${COMMON} --config=k8 --config=eigen ${TARGETS}
 
-  # Temporary step until I manage to migrate everything over.
-  # TODO(phil): Delete this step.
-  - label: "x86_64_upstream_python"
-    commands:
-      - tools/ci/clean-disk.sh
-      - tools/bazel ${STARTUP} --output_base=../k8_output_base_upstream_python test ${COMMON} --config=k8_upstream_python --config=eigen --build_tests_only --test_lang_filters=py ${TARGETS}
-
   - label: "roborio"
     commands:
       - tools/ci/clean-disk.sh
diff --git a/tools/lint/BUILD b/tools/lint/BUILD
index fedead2..58ef879 100644
--- a/tools/lint/BUILD
+++ b/tools/lint/BUILD
@@ -1,4 +1,5 @@
 load("@ci_configure//:ci.bzl", "RUNNING_IN_CI")
+load("@pip_deps//:requirements.bzl", "entry_point")
 
 sh_binary(
     name = "gofmt",
@@ -38,7 +39,7 @@
     name = "yapf",
     srcs = ["yapf.sh"],
     data = [
-        "@python_yapf",
+        entry_point("yapf"),
     ],
     deps = [
         "@bazel_tools//tools/bash/runfiles",
diff --git a/tools/lint/yapf.sh b/tools/lint/yapf.sh
index 404d5fd..d88aa42 100755
--- a/tools/lint/yapf.sh
+++ b/tools/lint/yapf.sh
@@ -11,7 +11,8 @@
   { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
 # --- end runfiles.bash initialization v2 ---
 
-readonly YAPF="$(rlocation python_yapf/python_yapf)"
+YAPF="$(rlocation pip_deps_yapf/rules_python_wheel_entry_point_yapf)"
+readonly YAPF
 
 # Run everything from the root of the tree.
 cd "${BUILD_WORKSPACE_DIRECTORY}"
diff --git a/tools/platforms/BUILD b/tools/platforms/BUILD
index 6165b00..7851a72 100644
--- a/tools/platforms/BUILD
+++ b/tools/platforms/BUILD
@@ -8,15 +8,16 @@
         "//tools/platforms/go:has_support",
         "//tools/platforms/rust:has_support",
         "//tools/platforms/nodejs:has_support",
+        "//tools/platforms/python:upstream_bundled_python",
     ],
 )
 
 # TODO(phil): Delete this platform after migrating everything to use upstream
 # pip rules.
 platform(
-    name = "linux_x86_upstream_python",
+    name = "linux_x86_legacy_python",
     constraint_values = [
-        "//tools/platforms/python:upstream_bundled_python",
+        "//tools/platforms/python:debian_bundled_python",
     ],
     parents = [
         ":linux_x86",
diff --git a/y2014/control_loops/python/BUILD b/y2014/control_loops/python/BUILD
index 20035bc..5704405 100644
--- a/y2014/control_loops/python/BUILD
+++ b/y2014/control_loops/python/BUILD
@@ -9,9 +9,9 @@
     target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:drivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -25,9 +25,9 @@
     target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -39,11 +39,11 @@
     ],
     target_compatible_with = ["@platforms//os:linux"],
     deps = [
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
         "//frc971/control_loops/python:drivetrain",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -57,10 +57,10 @@
     deps = [
         ":polydrivetrain_lib",
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//glog",
+        "@pip//matplotlib",
+        "@pip//python_gflags",
     ],
 )
 
@@ -73,10 +73,10 @@
     target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//glog",
+        "@pip//matplotlib",
+        "@pip//python_gflags",
     ],
 )
 
@@ -89,10 +89,10 @@
     target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//glog",
+        "@pip//matplotlib",
+        "@pip//python_gflags",
     ],
 )
 
diff --git a/y2014_bot3/control_loops/python/BUILD b/y2014_bot3/control_loops/python/BUILD
index b63ca0a..ab15cf3 100644
--- a/y2014_bot3/control_loops/python/BUILD
+++ b/y2014_bot3/control_loops/python/BUILD
@@ -9,9 +9,9 @@
     target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:drivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -25,9 +25,9 @@
     target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
diff --git a/y2016/control_loops/python/BUILD b/y2016/control_loops/python/BUILD
index 3300e62..ad3fbe9 100644
--- a/y2016/control_loops/python/BUILD
+++ b/y2016/control_loops/python/BUILD
@@ -9,9 +9,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:drivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -25,9 +25,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -41,11 +41,11 @@
     visibility = ["//visibility:public"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
         "//frc971/control_loops/python:drivetrain",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -58,10 +58,10 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//glog",
+        "@pip//matplotlib",
+        "@pip//python_gflags",
     ],
 )
 
@@ -74,10 +74,10 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:angular_system",
         "//frc971/control_loops/python:controls",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -91,10 +91,10 @@
     deps = [
         ":python_init",
         "//aos/util:py_trapezoid_profile",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//glog",
+        "@pip//matplotlib",
+        "@pip//python_gflags",
     ],
 )
 
@@ -108,10 +108,10 @@
     deps = [
         ":python_init",
         "//aos/util:py_trapezoid_profile",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//glog",
+        "@pip//matplotlib",
+        "@pip//python_gflags",
     ],
 )
 
@@ -123,9 +123,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         "//aos/util:py_trapezoid_profile",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -137,10 +137,10 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         "//aos/util:py_trapezoid_profile",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//glog",
+        "@pip//matplotlib",
+        "@pip//python_gflags",
     ],
 )
 
@@ -154,10 +154,10 @@
         ":shoulder_lib",
         ":wrist_lib",
         "//aos/util:py_trapezoid_profile",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//glog",
+        "@pip//matplotlib",
+        "@pip//python_gflags",
     ],
 )
 
@@ -173,9 +173,9 @@
         ":shoulder_lib",
         ":wrist_lib",
         "//aos/util:py_trapezoid_profile",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
diff --git a/y2017/control_loops/python/BUILD b/y2017/control_loops/python/BUILD
index a6277e7..209bd70 100644
--- a/y2017/control_loops/python/BUILD
+++ b/y2017/control_loops/python/BUILD
@@ -9,9 +9,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:drivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -25,9 +25,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -39,10 +39,10 @@
     ],
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
         "//frc971/control_loops/python:drivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -55,10 +55,10 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//glog",
+        "@pip//matplotlib",
+        "@pip//python_gflags",
     ],
 )
 
@@ -71,9 +71,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -86,10 +86,10 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
         "//frc971/control_loops/python:linear_system",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -103,10 +103,10 @@
     deps = [
         ":python_init",
         "//aos/util:py_trapezoid_profile",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//glog",
+        "@pip//matplotlib",
+        "@pip//python_gflags",
     ],
 )
 
@@ -120,10 +120,10 @@
     deps = [
         ":python_init",
         "//aos/util:py_trapezoid_profile",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//glog",
+        "@pip//matplotlib",
+        "@pip//python_gflags",
     ],
 )
 
@@ -135,9 +135,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         "//aos/util:py_trapezoid_profile",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -148,9 +148,9 @@
     ],
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -165,10 +165,10 @@
         ":indexer_lib",
         ":python_init",
         ":turret_lib",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//glog",
+        "@pip//matplotlib",
+        "@pip//python_gflags",
     ],
 )
 
diff --git a/y2018/control_loops/python/BUILD b/y2018/control_loops/python/BUILD
index 772c7e1..35f7433 100644
--- a/y2018/control_loops/python/BUILD
+++ b/y2018/control_loops/python/BUILD
@@ -9,9 +9,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:drivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -25,9 +25,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -41,11 +41,11 @@
     visibility = ["//visibility:public"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
         "//frc971/control_loops/python:drivetrain",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -59,10 +59,10 @@
     deps = [
         ":polydrivetrain_lib",
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -76,9 +76,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -91,10 +91,10 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//glog",
+        "@pip//matplotlib",
+        "@pip//python_gflags",
     ],
 )
 
@@ -122,7 +122,9 @@
         ":python_init",
         "//frc971/control_loops/python:basic_window",
         "//frc971/control_loops/python:color",
-        "@python_gtk",
+        "@pip//numpy",
+        "@pip//pygobject",
+        "@pip//shapely",
     ],
 )
 
@@ -136,7 +138,7 @@
     target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":python_init",
-        "@python_repo//:numpy",
+        "@pip//numpy",
     ],
 )
 
@@ -155,8 +157,8 @@
     ],
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
diff --git a/y2019/control_loops/python/BUILD b/y2019/control_loops/python/BUILD
index 3d5e641..bab607c 100644
--- a/y2019/control_loops/python/BUILD
+++ b/y2019/control_loops/python/BUILD
@@ -9,9 +9,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:drivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -25,9 +25,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -41,11 +41,11 @@
     visibility = ["//visibility:public"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
         "//frc971/control_loops/python:drivetrain",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -66,10 +66,10 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
         "//frc971/control_loops/python:linear_system",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -82,10 +82,10 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:angular_system",
         "//frc971/control_loops/python:controls",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -98,10 +98,10 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:angular_system",
         "//frc971/control_loops/python:controls",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -114,9 +114,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
         "//frc971/control_loops/python:linear_system",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
diff --git a/y2020/control_loops/python/BUILD b/y2020/control_loops/python/BUILD
index 9886452..8a1f737 100644
--- a/y2020/control_loops/python/BUILD
+++ b/y2020/control_loops/python/BUILD
@@ -9,9 +9,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:drivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -25,9 +25,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -41,11 +41,11 @@
     visibility = ["//visibility:public"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
         "//frc971/control_loops/python:drivetrain",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -58,10 +58,10 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:angular_system",
         "//frc971/control_loops/python:controls",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -74,10 +74,10 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:angular_system",
         "//frc971/control_loops/python:controls",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -90,10 +90,10 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:angular_system",
         "//frc971/control_loops/python:controls",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -106,10 +106,10 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:angular_system",
         "//frc971/control_loops/python:controls",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -121,7 +121,7 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         "//frc971/control_loops/python:controls",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//matplotlib",
     ],
 )
 
@@ -135,8 +135,8 @@
     deps = [
         ":flywheel",
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -150,8 +150,8 @@
     deps = [
         ":flywheel",
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
diff --git a/y2020/vision/sift/BUILD b/y2020/vision/sift/BUILD
index 195a82e..1920cce 100644
--- a/y2020/vision/sift/BUILD
+++ b/y2020/vision/sift/BUILD
@@ -259,7 +259,7 @@
     target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":sift_fbs_python",
-        "@opencv_contrib_nonfree_amd64//:python_opencv",
+        "@pip//opencv_python",
     ],
 )
 
diff --git a/y2020/vision/tools/python_code/BUILD b/y2020/vision/tools/python_code/BUILD
index d259ba7..4da3191 100644
--- a/y2020/vision/tools/python_code/BUILD
+++ b/y2020/vision/tools/python_code/BUILD
@@ -2,9 +2,9 @@
     name = "train_and_match",
     srcs = ["train_and_match.py"],
     deps = [
-        "//external:python-glog",
-        "@opencv_contrib_nonfree_amd64//:python_opencv",
-        "@python_repo//:scipy",
+        "@pip//glog",
+        "@pip//opencv_python",
+        "@pip//scipy",
     ],
 )
 
@@ -15,9 +15,9 @@
     ],
     deps = [
         ":train_and_match",
-        "//external:python-glog",
-        "@opencv_contrib_nonfree_amd64//:python_opencv",
-        "@python_repo//:scipy",
+        "@pip//glog",
+        "@pip//opencv_python",
+        "@pip//scipy",
     ],
 )
 
@@ -28,7 +28,7 @@
     ],
     deps = [
         ":define_training_data",
-        "//external:python-glog",
+        "@pip//glog",
     ],
 )
 
@@ -42,8 +42,8 @@
         ":camera_definition",
         ":define_training_data",
         ":train_and_match",
-        "//external:python-glog",
-        "@opencv_contrib_nonfree_amd64//:python_opencv",
+        "@pip//glog",
+        "@pip//opencv_python",
     ],
 )
 
@@ -76,10 +76,10 @@
     deps = [
         ":camera_definition",
         ":target_definition",
-        "//external:python-glog",
         "//y2020/vision/sift:sift_fbs_python",
         "@bazel_tools//tools/python/runfiles",
-        "@opencv_contrib_nonfree_amd64//:python_opencv",
+        "@pip//glog",
+        "@pip//opencv_python",
     ],
 )
 
@@ -95,10 +95,10 @@
     deps = [
         ":camera_definition",
         ":target_definition",
-        "//external:python-glog",
         "//y2020/vision/sift:sift_fbs_python",
         "@bazel_tools//tools/python/runfiles",
-        "@opencv_contrib_nonfree_amd64//:python_opencv",
+        "@pip//glog",
+        "@pip//opencv_python",
     ],
 )
 
@@ -149,10 +149,10 @@
     target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":load_sift_training",
-        "//external:python-glog",
         "//y2020/vision/sift:sift_fbs_python",
         "@bazel_tools//tools/python/runfiles",
-        "@opencv_contrib_nonfree_amd64//:python_opencv",
+        "@pip//glog",
+        "@pip//opencv_python",
     ],
 )
 
diff --git a/y2021_bot3/control_loops/python/BUILD b/y2021_bot3/control_loops/python/BUILD
index 15dacaa..c4010ba 100644
--- a/y2021_bot3/control_loops/python/BUILD
+++ b/y2021_bot3/control_loops/python/BUILD
@@ -9,9 +9,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:drivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -25,9 +25,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -40,11 +40,11 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     visibility = ["//visibility:public"],
     deps = [
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
         "//frc971/control_loops/python:drivetrain",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
diff --git a/y2022/control_loops/python/BUILD b/y2022/control_loops/python/BUILD
index 17f7b2a..ef274b8 100644
--- a/y2022/control_loops/python/BUILD
+++ b/y2022/control_loops/python/BUILD
@@ -9,9 +9,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:drivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -25,9 +25,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -40,11 +40,11 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     visibility = ["//visibility:public"],
     deps = [
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
         "//frc971/control_loops/python:drivetrain",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -58,7 +58,7 @@
         "//aos/util:py_trapezoid_profile",
         "//frc971/control_loops/python:angular_system",
         "//frc971/control_loops/python:controls",
-        "@matplotlib_repo//:matplotlib3",
+        "@pip//matplotlib",
     ],
 )
 
@@ -72,9 +72,9 @@
     deps = [
         ":catapult_lib",
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
-        "@osqp_amd64//:python_osqp",
+        "@pip//glog",
+        "@pip//osqp",
+        "@pip//python_gflags",
     ],
 )
 
@@ -87,10 +87,10 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:angular_system",
         "//frc971/control_loops/python:controls",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -103,10 +103,10 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:angular_system",
         "//frc971/control_loops/python:controls",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -119,10 +119,10 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
         "//frc971/control_loops/python:linear_system",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
diff --git a/y2022/vision/BUILD b/y2022/vision/BUILD
index 58dbba8..777d139 100644
--- a/y2022/vision/BUILD
+++ b/y2022/vision/BUILD
@@ -54,7 +54,7 @@
         "camera_definition.py",
     ],
     deps = [
-        "//external:python-glog",
+        "@pip//glog",
     ],
 )
 
@@ -70,10 +70,10 @@
     target_compatible_with = ["@platforms//os:linux"],
     deps = [
         ":camera_definition",
-        "//external:python-glog",
         "//y2022/vision:calibration_fbs_python",
         "@bazel_tools//tools/python/runfiles",
-        "@opencv_contrib_nonfree_amd64//:python_opencv",
+        "@pip//glog",
+        "@pip//opencv_python",
     ],
 )
 
diff --git a/y2022_bot3/control_loops/python/BUILD b/y2022_bot3/control_loops/python/BUILD
index b2ce1be..65a6033 100644
--- a/y2022_bot3/control_loops/python/BUILD
+++ b/y2022_bot3/control_loops/python/BUILD
@@ -9,9 +9,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:drivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -25,9 +25,9 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -40,11 +40,11 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     visibility = ["//visibility:public"],
     deps = [
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
         "//frc971/control_loops/python:drivetrain",
         "//frc971/control_loops/python:polydrivetrain",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -57,10 +57,10 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:controls",
         "//frc971/control_loops/python:linear_system",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )
 
@@ -73,10 +73,10 @@
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
         ":python_init",
-        "//external:python-gflags",
-        "//external:python-glog",
         "//frc971/control_loops/python:angular_system",
         "//frc971/control_loops/python:controls",
+        "@pip//glog",
+        "@pip//python_gflags",
     ],
 )