概要
pip install を実行した際に、Cannot uninstall blinker 1.4
という見慣れないエラーが発生した。
この対処法を記載したのがこの記事です。
実行環境
Windwos 上の WSL2 内で、 airobotbook/ros2-desktop-ai-robot-book-humble
という docker イメージをビルドし、その中で pip install を行っていました。
具体的には以下の通り。
item | version など |
---|---|
OS | Windows Home Edition (WSL2) |
docker image | airobotbook/ros2-desktop-ai-robot-book-humble |
OS in docker image | Ubuntu 22.04.5 LTS |
python | 3.10.12 |
エラー発生状況
$ pip install -r requirements.txt
...
Attempting uninstall: blinker
Found existing installation: blinker 1.4
━━━━━━━━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━━━━━ 15/37 [blinker]error: uninstall-distutils-installed-package
× Cannot uninstall blinker 1.4
╰─> It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
エラーまでの出力全文を見る
※ 後ほど原因は mlflow であることが判明したので、 mlflow のみを install しています。
$ pip install -r requirements.txt
WARNING: The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.
Collecting mlflow
Downloading mlflow-2.22.0-py3-none-any.whl.metadata (30 kB)
Collecting mlflow-skinny==2.22.0 (from mlflow)
Downloading mlflow_skinny-2.22.0-py3-none-any.whl.metadata (31 kB)
Collecting Flask<4 (from mlflow)
Downloading flask-3.1.0-py3-none-any.whl.metadata (2.7 kB)
Requirement already satisfied: Jinja2<4,>=2.11 in /home/ubuntu/.local/lib/python3.10/site-packages (from mlflow) (3.1.5)
Collecting alembic!=1.10.0,<2 (from mlflow)
Downloading alembic-1.15.2-py3-none-any.whl.metadata (7.3 kB)
Collecting docker<8,>=4.0.0 (from mlflow)
Downloading docker-7.1.0-py3-none-any.whl.metadata (3.8 kB)
Collecting graphene<4 (from mlflow)
Downloading graphene-3.4.3-py2.py3-none-any.whl.metadata (6.9 kB)
Collecting gunicorn<24 (from mlflow)
Downloading gunicorn-23.0.0-py3-none-any.whl.metadata (4.4 kB)
Requirement already satisfied: markdown<4,>=3.3 in /usr/local/lib/python3.10/dist-packages (from mlflow) (3.8)
Requirement already satisfied: matplotlib<4 in /usr/local/lib/python3.10/dist-packages (from mlflow) (3.9.0)
Requirement already satisfied: numpy<3 in /usr/local/lib/python3.10/dist-packages (from mlflow) (1.26.4)
Requirement already satisfied: pandas<3 in /home/ubuntu/.local/lib/python3.10/site-packages (from mlflow) (2.2.3)
Collecting pyarrow<20,>=4.0.0 (from mlflow)
Downloading pyarrow-19.0.1-cp310-cp310-manylinux_2_28_x86_64.whl.metadata (3.3 kB)
Collecting scikit-learn<2 (from mlflow)
Downloading scikit_learn-1.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (18 kB)
Requirement already satisfied: scipy<2 in /usr/local/lib/python3.10/dist-packages (from mlflow) (1.13.1)
Collecting sqlalchemy<3,>=1.4.0 (from mlflow)
Downloading sqlalchemy-2.0.40-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (9.6 kB)
Collecting cachetools<6,>=5.0.0 (from mlflow-skinny==2.22.0->mlflow)
Downloading cachetools-5.5.2-py3-none-any.whl.metadata (5.4 kB)
Requirement already satisfied: click<9,>=7.0 in /usr/lib/python3/dist-packages (from mlflow-skinny==2.22.0->mlflow) (8.0.3)
Collecting cloudpickle<4 (from mlflow-skinny==2.22.0->mlflow)
Downloading cloudpickle-3.1.1-py3-none-any.whl.metadata (7.1 kB)
Collecting databricks-sdk<1,>=0.20.0 (from mlflow-skinny==2.22.0->mlflow)
Downloading databricks_sdk-0.52.0-py3-none-any.whl.metadata (39 kB)
Requirement already satisfied: fastapi<1 in /home/ubuntu/.local/lib/python3.10/site-packages (from mlflow-skinny==2.22.0->mlflow) (0.115.8)
Collecting gitpython<4,>=3.1.9 (from mlflow-skinny==2.22.0->mlflow)
Downloading GitPython-3.1.44-py3-none-any.whl.metadata (13 kB)
Requirement already satisfied: importlib_metadata!=4.7.0,<9,>=3.7.0 in /usr/lib/python3/dist-packages (from mlflow-skinny==2.22.0->mlflow) (4.6.4)
Collecting opentelemetry-api<3,>=1.9.0 (from mlflow-skinny==2.22.0->mlflow)
Downloading opentelemetry_api-1.32.1-py3-none-any.whl.metadata (1.6 kB)
Collecting opentelemetry-sdk<3,>=1.9.0 (from mlflow-skinny==2.22.0->mlflow)
Downloading opentelemetry_sdk-1.32.1-py3-none-any.whl.metadata (1.6 kB)
Collecting packaging<25 (from mlflow-skinny==2.22.0->mlflow)
Downloading packaging-24.2-py3-none-any.whl.metadata (3.2 kB)
Requirement already satisfied: protobuf<7,>=3.12.0 in /usr/local/lib/python3.10/dist-packages (from mlflow-skinny==2.22.0->mlflow) (4.25.7)
Requirement already satisfied: pydantic<3,>=1.10.8 in /home/ubuntu/.local/lib/python3.10/site-packages (from mlflow-skinny==2.22.0->mlflow) (2.10.6)
Requirement already satisfied: pyyaml<7,>=5.1 in /usr/lib/python3/dist-packages (from mlflow-skinny==2.22.0->mlflow) (5.4.1)
Requirement already satisfied: requests<3,>=2.17.3 in /home/ubuntu/.local/lib/python3.10/site-packages (from mlflow-skinny==2.22.0->mlflow) (2.32.3)
Collecting sqlparse<1,>=0.4.0 (from mlflow-skinny==2.22.0->mlflow)
Downloading sqlparse-0.5.3-py3-none-any.whl.metadata (3.9 kB)
Requirement already satisfied: typing-extensions<5,>=4.0.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from mlflow-skinny==2.22.0->mlflow) (4.12.2)
Requirement already satisfied: uvicorn<1 in /usr/lib/python3/dist-packages (from mlflow-skinny==2.22.0->mlflow) (0.15.0)
Requirement already satisfied: Mako in /usr/lib/python3/dist-packages (from alembic!=1.10.0,<2->mlflow) (1.1.3)
Collecting google-auth~=2.0 (from databricks-sdk<1,>=0.20.0->mlflow-skinny==2.22.0->mlflow)
Downloading google_auth-2.40.0-py2.py3-none-any.whl.metadata (6.2 kB)
Requirement already satisfied: urllib3>=1.26.0 in /usr/lib/python3/dist-packages (from docker<8,>=4.0.0->mlflow) (1.26.5)
Requirement already satisfied: starlette<0.46.0,>=0.40.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from fastapi<1->mlflow-skinny==2.22.0->mlflow) (0.45.3)
Requirement already satisfied: Werkzeug>=3.1 in /usr/local/lib/python3.10/dist-packages (from Flask<4->mlflow) (3.1.3)
Collecting itsdangerous>=2.2 (from Flask<4->mlflow)
Downloading itsdangerous-2.2.0-py3-none-any.whl.metadata (1.9 kB)
Collecting click<9,>=7.0 (from mlflow-skinny==2.22.0->mlflow)
Downloading click-8.1.8-py3-none-any.whl.metadata (2.3 kB)
Collecting blinker>=1.9 (from Flask<4->mlflow)
Downloading blinker-1.9.0-py3-none-any.whl.metadata (1.6 kB)
Collecting gitdb<5,>=4.0.1 (from gitpython<4,>=3.1.9->mlflow-skinny==2.22.0->mlflow)
Downloading gitdb-4.0.12-py3-none-any.whl.metadata (1.2 kB)
Collecting smmap<6,>=3.0.1 (from gitdb<5,>=4.0.1->gitpython<4,>=3.1.9->mlflow-skinny==2.22.0->mlflow)
Downloading smmap-5.0.2-py3-none-any.whl.metadata (4.3 kB)
Collecting pyasn1-modules>=0.2.1 (from google-auth~=2.0->databricks-sdk<1,>=0.20.0->mlflow-skinny==2.22.0->mlflow)
Downloading pyasn1_modules-0.4.2-py3-none-any.whl.metadata (3.5 kB)
Collecting rsa<5,>=3.1.4 (from google-auth~=2.0->databricks-sdk<1,>=0.20.0->mlflow-skinny==2.22.0->mlflow)
Downloading rsa-4.9.1-py3-none-any.whl.metadata (5.6 kB)
Collecting graphql-core<3.3,>=3.1 (from graphene<4->mlflow)
Downloading graphql_core-3.2.6-py3-none-any.whl.metadata (11 kB)
Collecting graphql-relay<3.3,>=3.1 (from graphene<4->mlflow)
Downloading graphql_relay-3.2.0-py3-none-any.whl.metadata (12 kB)
Requirement already satisfied: python-dateutil<3,>=2.7.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from graphene<4->mlflow) (2.9.0.post0)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from Jinja2<4,>=2.11->mlflow) (3.0.2)
Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib<4->mlflow) (1.3.2)
Requirement already satisfied: cycler>=0.10 in /usr/lib/python3/dist-packages (from matplotlib<4->mlflow) (0.11.0)
Requirement already satisfied: fonttools>=4.22.0 in /usr/lib/python3/dist-packages (from matplotlib<4->mlflow) (4.29.1)
Requirement already satisfied: kiwisolver>=1.3.1 in /usr/lib/python3/dist-packages (from matplotlib<4->mlflow) (1.3.2)
Requirement already satisfied: pillow>=8 in /usr/local/lib/python3.10/dist-packages (from matplotlib<4->mlflow) (9.2.0)
Requirement already satisfied: pyparsing>=2.3.1 in /usr/lib/python3/dist-packages (from matplotlib<4->mlflow) (2.4.7)
Collecting deprecated>=1.2.6 (from opentelemetry-api<3,>=1.9.0->mlflow-skinny==2.22.0->mlflow)
Downloading Deprecated-1.2.18-py2.py3-none-any.whl.metadata (5.7 kB)
Collecting importlib_metadata!=4.7.0,<9,>=3.7.0 (from mlflow-skinny==2.22.0->mlflow)
Downloading importlib_metadata-8.6.1-py3-none-any.whl.metadata (4.7 kB)
Collecting zipp>=3.20 (from importlib_metadata!=4.7.0,<9,>=3.7.0->mlflow-skinny==2.22.0->mlflow)
Downloading zipp-3.21.0-py3-none-any.whl.metadata (3.7 kB)
Collecting opentelemetry-semantic-conventions==0.53b1 (from opentelemetry-sdk<3,>=1.9.0->mlflow-skinny==2.22.0->mlflow)
Downloading opentelemetry_semantic_conventions-0.53b1-py3-none-any.whl.metadata (2.5 kB)
Requirement already satisfied: pytz>=2020.1 in /usr/lib/python3/dist-packages (from pandas<3->mlflow) (2022.1)
Requirement already satisfied: tzdata>=2022.7 in /home/ubuntu/.local/lib/python3.10/site-packages (from pandas<3->mlflow) (2025.1)
Requirement already satisfied: annotated-types>=0.6.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from pydantic<3,>=1.10.8->mlflow-skinny==2.22.0->mlflow) (0.7.0)
Requirement already satisfied: pydantic-core==2.27.2 in /home/ubuntu/.local/lib/python3.10/site-packages (from pydantic<3,>=1.10.8->mlflow-skinny==2.22.0->mlflow) (2.27.2)
Requirement already satisfied: six>=1.5 in /usr/lib/python3/dist-packages (from python-dateutil<3,>=2.7.0->graphene<4->mlflow) (1.16.0)
Requirement already satisfied: charset-normalizer<4,>=2 in /home/ubuntu/.local/lib/python3.10/site-packages (from requests<3,>=2.17.3->mlflow-skinny==2.22.0->mlflow) (3.4.1)
Requirement already satisfied: idna<4,>=2.5 in /home/ubuntu/.local/lib/python3.10/site-packages (from requests<3,>=2.17.3->mlflow-skinny==2.22.0->mlflow) (3.10)
Requirement already satisfied: certifi>=2017.4.17 in /home/ubuntu/.local/lib/python3.10/site-packages (from requests<3,>=2.17.3->mlflow-skinny==2.22.0->mlflow) (2025.1.31)
Collecting pyasn1>=0.1.3 (from rsa<5,>=3.1.4->google-auth~=2.0->databricks-sdk<1,>=0.20.0->mlflow-skinny==2.22.0->mlflow)
Downloading pyasn1-0.6.1-py3-none-any.whl.metadata (8.4 kB)
Collecting joblib>=1.2.0 (from scikit-learn<2->mlflow)
Downloading joblib-1.5.0-py3-none-any.whl.metadata (5.6 kB)
Collecting threadpoolctl>=3.1.0 (from scikit-learn<2->mlflow)
Downloading threadpoolctl-3.6.0-py3-none-any.whl.metadata (13 kB)
Collecting greenlet>=1 (from sqlalchemy<3,>=1.4.0->mlflow)
Downloading greenlet-3.2.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.metadata (4.1 kB)
Requirement already satisfied: anyio<5,>=3.6.2 in /home/ubuntu/.local/lib/python3.10/site-packages (from starlette<0.46.0,>=0.40.0->fastapi<1->mlflow-skinny==2.22.0->mlflow) (4.8.0)
Requirement already satisfied: exceptiongroup>=1.0.2 in /home/ubuntu/.local/lib/python3.10/site-packages (from anyio<5,>=3.6.2->starlette<0.46.0,>=0.40.0->fastapi<1->mlflow-skinny==2.22.0->mlflow) (1.2.2)
Requirement already satisfied: sniffio>=1.1 in /home/ubuntu/.local/lib/python3.10/site-packages (from anyio<5,>=3.6.2->starlette<0.46.0,>=0.40.0->fastapi<1->mlflow-skinny==2.22.0->mlflow) (1.3.1)
Collecting wrapt<2,>=1.10 (from deprecated>=1.2.6->opentelemetry-api<3,>=1.9.0->mlflow-skinny==2.22.0->mlflow)
Downloading wrapt-1.17.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (6.4 kB)
Downloading mlflow-2.22.0-py3-none-any.whl (29.0 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 29.0/29.0 MB 70.2 MB/s eta 0:00:00
Downloading mlflow_skinny-2.22.0-py3-none-any.whl (6.3 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.3/6.3 MB 85.2 MB/s eta 0:00:00
Downloading alembic-1.15.2-py3-none-any.whl (231 kB)
Downloading cachetools-5.5.2-py3-none-any.whl (10 kB)
Downloading cloudpickle-3.1.1-py3-none-any.whl (20 kB)
Downloading databricks_sdk-0.52.0-py3-none-any.whl (700 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 700.2/700.2 kB 51.2 MB/s eta 0:00:00
Downloading docker-7.1.0-py3-none-any.whl (147 kB)
Downloading flask-3.1.0-py3-none-any.whl (102 kB)
Downloading click-8.1.8-py3-none-any.whl (98 kB)
Downloading GitPython-3.1.44-py3-none-any.whl (207 kB)
Downloading gitdb-4.0.12-py3-none-any.whl (62 kB)
Downloading google_auth-2.40.0-py2.py3-none-any.whl (216 kB)
Downloading graphene-3.4.3-py2.py3-none-any.whl (114 kB)
Downloading graphql_core-3.2.6-py3-none-any.whl (203 kB)
Downloading graphql_relay-3.2.0-py3-none-any.whl (16 kB)
Downloading gunicorn-23.0.0-py3-none-any.whl (85 kB)
Downloading opentelemetry_api-1.32.1-py3-none-any.whl (65 kB)
Downloading importlib_metadata-8.6.1-py3-none-any.whl (26 kB)
Downloading opentelemetry_sdk-1.32.1-py3-none-any.whl (118 kB)
Downloading opentelemetry_semantic_conventions-0.53b1-py3-none-any.whl (188 kB)
Downloading packaging-24.2-py3-none-any.whl (65 kB)
Downloading pyarrow-19.0.1-cp310-cp310-manylinux_2_28_x86_64.whl (42.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 42.1/42.1 MB 71.7 MB/s eta 0:00:00
Downloading rsa-4.9.1-py3-none-any.whl (34 kB)
Downloading scikit_learn-1.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.5 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 13.5/13.5 MB 70.9 MB/s eta 0:00:00
Downloading smmap-5.0.2-py3-none-any.whl (24 kB)
Downloading sqlalchemy-2.0.40-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.1/3.1 MB 57.8 MB/s eta 0:00:00
Downloading sqlparse-0.5.3-py3-none-any.whl (44 kB)
Downloading blinker-1.9.0-py3-none-any.whl (8.5 kB)
Downloading Deprecated-1.2.18-py2.py3-none-any.whl (10.0 kB)
Downloading wrapt-1.17.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (82 kB)
Downloading greenlet-3.2.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (580 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 580.6/580.6 kB 60.6 MB/s eta 0:00:00
Downloading itsdangerous-2.2.0-py3-none-any.whl (16 kB)
Downloading joblib-1.5.0-py3-none-any.whl (307 kB)
Downloading pyasn1-0.6.1-py3-none-any.whl (83 kB)
Downloading pyasn1_modules-0.4.2-py3-none-any.whl (181 kB)
Downloading threadpoolctl-3.6.0-py3-none-any.whl (18 kB)
Downloading zipp-3.21.0-py3-none-any.whl (9.6 kB)
Installing collected packages: zipp, wrapt, threadpoolctl, sqlparse, smmap, pyasn1, pyarrow, packaging, joblib, itsdangerous, greenlet, graphql-core, cloudpickle, click, cachetools, blinker, sqlalchemy, scikit-learn, rsa, pyasn1-modules, importlib_metadata, gunicorn, graphql-relay, gitdb, Flask, docker, deprecated, opentelemetry-api, graphene, google-auth, gitpython, alembic, opentelemetry-semantic-conventions, databricks-sdk, opentelemetry-sdk, mlflow-skinny, mlflow
Attempting uninstall: zipp
Found existing installation: zipp 1.0.0
Uninstalling zipp-1.0.0:
Successfully uninstalled zipp-1.0.0
Attempting uninstall: pyarrow
Found existing installation: pyarrow 20.0.0
Uninstalling pyarrow-20.0.0:
Successfully uninstalled pyarrow-20.0.0
Attempting uninstall: packaging
Found existing installation: packaging 25.0
Uninstalling packaging-25.0:
Successfully uninstalled packaging-25.0
Attempting uninstall: itsdangerous
Found existing installation: itsdangerous 2.1.0
Uninstalling itsdangerous-2.1.0:
Successfully uninstalled itsdangerous-2.1.0
Attempting uninstall: click
Found existing installation: click 8.0.3
Uninstalling click-8.0.3:
Successfully uninstalled click-8.0.3
Attempting uninstall: blinker
Found existing installation: blinker 1.4
━━━━━━━━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━━━━━ 15/37 [blinker]error: uninstall-distutils-installed-package
× Cannot uninstall blinker 1.4
╰─> It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
対処法
1. blinker に依存しているパッケージを利用しない
まず、私の場合は mlflow
が blinker
に依存していたので、requirements.txt
から mlflow
をコメントアウトするだけで解決しました。
ただ、どうしても mlflow を使いたい場合にはどうすればよいか。それを以下で考えてみました。
2. --ignore-installed オプションの利用 (非推奨)
以下の二つの記事で案内されていました。
1つ目の記事は embedchain
、2つ目の記事は paddlepaddle
というライブラリをインストールしようとして同じエラーに直面しているようでしたが、いずれも --ignore-installed
というオプションを利用することによって問題を回避しているようでした。
具体的には、今回の場合は以下のようにコマンドを打つことで、問題を回避できる可能性があります。(私の場合は回避できました)
$ pip install --ignore-installed -r requirements.txt
このオプションについて詳しく知りたい方は以下の記事が参考になると思います。
私なりにこのオプションについて解説すると以下のようになります。
-
--ignore-installed
は、既にインストールされている(古い)パッケージを残したまま、新しいバージョンの同名パッケージをインストールして、双方を共存させる - その結果、 uninstall が発生しないので、
uninstall blinker 1.4
に失敗することもない
このため、各パッケージの import 実行時によくわからないエラーに出くわすリスクが残っていると思います。
そのため非推奨とさせていただきました
3. docker イメージの変更
こちらで対処できるなら、こちらの対処法の方がいいかもしれません。
以下の記事で提案されていました。
今回私は、この対処法はコストが高すぎて採用できなかったのですが、python 3.12 以上であれば blinker が削除されているらしい ので、この問題は発生しないと予想されます。
4. python3-blinker というパッケージのアンインストール
以下の記事で提案されていた対処法です。
flask も blinker に依存しているようですね。
対処法としては比較的簡単で、 blinker に依存しているパッケージをインストールする前に、 python3-blinker
を除去しておけば、 python パッケージの blinker も削除されて、問題が解決するようです。
具体的には以下のようにします。
# Docker コンテナ内で実施した
$ apt remove python3-blinker
$ pip install -r requirements.txt
この方法でも、私は問題が解消できました。
Dockerfile に書く場合は以下のように書くと良いでしょう。
RUN apt -y remove python3-blinker
RUN pip install -r requirements.txt
判明している原因パッケージ
以下のパッケージを利用している場合には、この問題が発生するようですね( ˘ω˘)スヤァ。。。
- embedchain
- flask
- mlflow
- paddlepaddle