44
45

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonのアンインストール

Posted at

#はじめに
 Pythonのサイト(こちらへ)から入手したインストーラーでMacにインストールした場合、
 アンインストールは、手動で行う必要があります。

 手動で行うアンインストール方法について、以下の順に説明します。
  (1) "Applications"フォルダ直下のPythonフォルダの削除
  (2) /Library/Frameworks/Python.frameworkフォルダの削除
  (3) /usr/local/bin直下のシンボリックリンクの削除
  (4) .bash_profileのPythonのPATHを削除
 ※ マシンのOSのバージョンは、macOS High Sierra 10.13.4です。

#1. "Applications"フォルダ直下のPythonフォルダの削除
 "Applications"フォルダ直下にあるPythonフォルダを削除します。
 フォルダ名には、インストールした際のPythonのバージョン番号が書かれています。
 ※ 以下の例では、「Python 3.5」「Python 3.6」を削除しています。
  自身の環境に合わせて削除して下さい。

$ cd /Applications/
$ ls -l
...
drwxr-xr-x@  9 root           wheel  288 11 24  2015 Python 3.5
drwxr-xr-x@ 10 root           wheel  320  3  4  2017 Python 3.6
...
$ sudo rm -r "Python 3.5"
$ sudo rm -r "Python 3.6"

#2. /Library/Frameworks/Python.frameworkフォルダの削除

$ sudo rm -rf  /Library/Frameworks/Python.framework

#3. /usr/local/bin直下のシンボリックリンクの削除
##3-1. シンボリックリンクのリストを表示
以下のコマンドで削除するシンボリックリンクのリスト表示します。
ls -l /usr/local/bin | grep Python

$ ls -l /usr/local/bin | grep Python
lrwxr-xr-x  1 root   wheel     66  3  4  2017 2to3 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/2to3
lrwxr-xr-x  1 root   wheel     70 11 24  2015 2to3-3.5 -> ../../../Library/Frameworks/Python.framework/Versions/3.5/bin/2to3-3.5
lrwxr-xr-x  1 root   wheel     70  3  4  2017 2to3-3.6 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/2to3-3.6
lrwxrwxr-x  1 root   admin     78 11 24  2015 easy_install-3.5 -> ../../../Library/Frameworks/Python.framework/Versions/3.5/bin/easy_install-3.5
lrwxrwxr-x  1 root   admin     78  3  4  2017 easy_install-3.6 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/easy_install-3.6
lrwxr-xr-x  1 root   wheel     67  3  4  2017 idle3 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/idle3
lrwxr-xr-x  1 root   wheel     69 11 24  2015 idle3.5 -> ../../../Library/Frameworks/Python.framework/Versions/3.5/bin/idle3.5
lrwxr-xr-x  1 root   wheel     69  3  4  2017 idle3.6 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/idle3.6
lrwxrwxr-x  1 root   admin     66  3  4  2017 pip3 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/pip3
lrwxrwxr-x  1 root   admin     68 11 24  2015 pip3.5 -> ../../../Library/Frameworks/Python.framework/Versions/3.5/bin/pip3.5
lrwxrwxr-x  1 root   admin     68  3  4  2017 pip3.6 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/pip3.6
lrwxr-xr-x  1 root   wheel     68  3  4  2017 pydoc3 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/pydoc3
lrwxr-xr-x  1 root   wheel     70 11 24  2015 pydoc3.5 -> ../../../Library/Frameworks/Python.framework/Versions/3.5/bin/pydoc3.5
lrwxr-xr-x  1 root   wheel     70  3  4  2017 pydoc3.6 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/pydoc3.6
lrwxr-xr-x  1 root   wheel     69  3  4  2017 python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3
lrwxr-xr-x  1 root   wheel     72  3  4  2017 python3-32 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3-32
lrwxr-xr-x  1 root   wheel     76  3  4  2017 python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3-config
lrwxr-xr-x  1 root   wheel     71 11 24  2015 python3.5 -> ../../../Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5
lrwxr-xr-x  1 root   wheel     74 11 24  2015 python3.5-32 -> ../../../Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5-32
lrwxr-xr-x  1 root   wheel     78 11 24  2015 python3.5-config -> ../../../Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5-config
lrwxr-xr-x  1 root   wheel     72 11 24  2015 python3.5m -> ../../../Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5m
lrwxr-xr-x  1 root   wheel     79 11 24  2015 python3.5m-config -> ../../../Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5m-config
lrwxr-xr-x  1 root   wheel     71  3  4  2017 python3.6 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
lrwxr-xr-x  1 root   wheel     74  3  4  2017 python3.6-32 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6-32
lrwxr-xr-x  1 root   wheel     78  3  4  2017 python3.6-config -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6-config
lrwxr-xr-x  1 root   wheel     72  3  4  2017 python3.6m -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m
lrwxr-xr-x  1 root   wheel     79  3  4  2017 python3.6m-config -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m-config
lrwxr-xr-x  1 root   wheel     68  3  4  2017 pyvenv -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/pyvenv
lrwxr-xr-x  1 root   wheel     72 11 24  2015 pyvenv-3.5 -> ../../../Library/Frameworks/Python.framework/Versions/3.5/bin/pyvenv-3.5
lrwxr-xr-x  1 root   wheel     72  3  4  2017 pyvenv-3.6 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/pyvenv-3.6

##3-2. シンボリックリンクの削除
出力したシンボリックリンクのリストから削除するコマンドを作成し、削除します。
※ 私は正規表現を使って作成しました。

$ unlink /usr/local/bin/2to3
$ unlink /usr/local/bin/2to3-3.5
$ unlink /usr/local/bin/2to3-3.6
$ unlink /usr/local/bin/easy_install-3.5
$ unlink /usr/local/bin/easy_install-3.6
$ unlink /usr/local/bin/idle3
$ unlink /usr/local/bin/idle3.5
$ unlink /usr/local/bin/idle3.6
$ unlink /usr/local/bin/pip3
$ unlink /usr/local/bin/pip3.5
$ unlink /usr/local/bin/pip3.6
$ unlink /usr/local/bin/pydoc3
$ unlink /usr/local/bin/pydoc3.5
$ unlink /usr/local/bin/pydoc3.6
$ unlink /usr/local/bin/python3
$ unlink /usr/local/bin/python3-32
$ unlink /usr/local/bin/python3-config
$ unlink /usr/local/bin/python3.5
$ unlink /usr/local/bin/python3.5-32
$ unlink /usr/local/bin/python3.5-config
$ unlink /usr/local/bin/python3.5m
$ unlink /usr/local/bin/python3.5m-config
$ unlink /usr/local/bin/python3.6
$ unlink /usr/local/bin/python3.6-32
$ unlink /usr/local/bin/python3.6-config
$ unlink /usr/local/bin/python3.6m
$ unlink /usr/local/bin/python3.6m-config
$ unlink /usr/local/bin/pyvenv
$ unlink /usr/local/bin/pyvenv-3.5
$ unlink /usr/local/bin/pyvenv-3.6

##3-3. シンボリックリンクの確認
正常にシンボリックリンクが削除されたか確認します。

$ ls -l /usr/local/bin | grep Python
$

#4. .bash_profileのPythonのPATHを削除
インストール時、/Library/Frameworks/Python.frameworkへのPATHが
.bash_profileに追記されている為、その設定を削除します。

##4-1. PATHの確認

$ printenv PATH
/Library/Spring/gradle-4.8.1/bin:/Library/Spring/apache-maven-3.5.3/bin:/Library/Spring/spring-2.1.0.BUILD-SNAPSHOT/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Library/Spring/apache-maven-3.5.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

##4-2. .bash_profileの修正
以下のコマンドで.bash_profileを開きます。

$ open ~/.bash_profile

以下の部分を削除します。

# Setting PATH for Python 3.5
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH

# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH

##4-3. .bash_profileの更新

$ source ~/.bash_profile

##4-4. PATHの確認(.bash_profileの更新後)

$ printenv PATH
/Library/Spring/gradle-4.8.1/bin:/Library/Spring/apache-maven-3.5.3/bin:/Library/Spring/spring-2.1.0.BUILD-SNAPSHOT/bin:/Library/Spring/apache-maven-3.5.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

##4-5. .bash_profile.pysaveの削除
インストール時、変更前の状態を「.bash_profile.pysave」というフィアル名で
バックアップされている為、このファイルも削除します。

$ rm ~/.bash_profile.pysave

以上で、手順が完了です。

#参考元
本家Pythonのアンインストール for Mac

44
45
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
44
45

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?