荒れ果てたpython開発環境を再構築する
きっかけ
tensorflow入れようとpip install
しようとしたらpipが何故かお亡くなりになった.
うーん.と調べているうちにすごいことに気づいてしまった.
自分の開発環境が:
- brew, pyenv, virtualenv, pyenv-virtualenv, virtualenvwrapper, anacondaごちゃ混ぜ(←すごいミックス!)
- bash/zshごちゃ混ぜ
よく理解しない大学3年生の時とかにインストールしたのと,
友達に勝手にシェルをzshにされていたのが原因です.
(terminal便利にしといたから〜って言われたこともあったな〜)
参考文献
ここが一番よくまとまってた
www.zopfco.de
アンインストール
ゆっくりいきましょう
anaconda
conda install anaconda-clean
anaconda-clean --yes
rm -rf ~/anaconda2
ホームディレクトリで~/.condarc
などもあったら消しました
virtualenvwrapper
sudo pip uninstall virtualenvwrapper
そのほかにも/usr/local/bin/
以下にあるvirtualenvwrapper関係のファイルを削除.
virtualenvwrapper.sh
など.
virtualenv
sudo pip uninstall virtualenv
pyenv-virtualenv
brew uninstall pyenv-virtualenv
pyenv
brew uninstall pyenv
which pyenv
で残っていたのでsudo rm -rf .pyenv/
でフォルダーを全削除しました.
僕はbrewとgit経由どちらも入れてしまった可能性があります(バカです)
この時Pathがまだ通っていると何故かまだwhich pyenv
で返ってくるので
~/.bash_profile
とかの中を消します.
ここは臨機応変にやってください.
なんせ自分は何も覚えていなかったので両方やってみました
環境変数の削除
環境変数はインストール時にシェルの設定ファイルに設定しているはず
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile $ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile $ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
そのほかにpyenv
やconda
みたいな言葉がないか探します.
探すべきシェルの設定ファイル.
- ~/.bash_profile - ~/.bashrc - ~/.zshrc
加え以下のファイルは削除しました
- ~/.bash_history - ~/.zsh_history
この時初めてzsh君がいることに気付きました
zsh ごちゃごちゃ解消
僕は~/.bash_profile
にzshを読み込ませるようにしていたので
一旦zshの行を消しました.とりあえずbashでやろうと.
そして,source ~/.bash_profile
などで読み込ませます.
brew アンインストール
brew list
でなんのパッケージがインストールされているか見てみた.
するとopencvがあった.
brew
やpip
,手動?でインストールした記憶があるので混在しないようにとりあえずbrewとパッケージを全て削除.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
さあ再構築
方針
- Homebrewでpythonに関わらない基本コマンドの管理(gitやpyenvなど)
- pyenvでpython 3.xを管理
- python2系は使わない前提でvenvでpython3系のパッケージ管理をする
すると各仮想環境ごとにpip installでパッケージをインストールできる.
簡単にpip install tensorflow
できる.
Homebrew
Homebrewはrubyで書かれているのでMacに予め入っているrubyコマンドでインストール
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
pyenv
brew install pyenv
.bash_profile に環境変数や init コマンドを追加。
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile echo 'eval "$(pyenv init -)"' >> ~/.bash_profile source ~/.bash_profile
とりあえず最新のpythonインストール.
globalに設定
pyenv install -l pyenv install 3.7.0 pyenv global 3.7.0
pyenv versions
で確認
これでpythonのバージョン管理ができるようになった.
それぞれ自分の開発しているフォルダーのルートに行き,
pyenv local X.X.X
とすればバージョン管理できる.
venv
デフォルトでpythonに付随されている.
分の開発しているフォルダーのルートに行き,
python3.7 -m venv NEW_ENV_NAME
今回は3.7.0だったのでpython3.7
NEW_ENV_NAMEの所に自由に自分のつけたい名前をつける.
その環境内でのみ完結させたい場合は
source NEW_ENV_NAME/bin/activate
でアクティベート.
終了したいときは
deactivate
これで簡単構築終わり.
良い点
pyenvのみインストール.
仮想環境は1発で作れる.
悪い点
- 毎回activate
環境内のみで開発したいときは毎回source NEW_ENV_NAME/bin/activate
が必要 - 容量がいっぱい
NEW_ENV_NAME以下のフォルダーにpipでインストールしたもの全て入ってしまう.
Anacondaはデータサイエンティスト以外にオススメしない!!!
Windowsは例外.
Wi-Fi: No hardware Installed
Problem
My Macbook Pro Late 2011 suddenly started spitting out that says it cannot find Wi-Fi board on my mac.
Methods Tested
I tried resetting NVRAM and SMC as mentioned in many websites. It sometimes bring back Wi-Fi, but soon it turns off.
Final Solution
I realized that I had played around with this Wi-Fi board before when I changed the battery or CD-ROM disk on back of my mac. The problem was that one of the part was not touching the mac's "ground".
Normally this silver part is on top of everything while touching the mac's housing. However, mine was underneath the wire, not touching the housing. I guess this was functioning as "Ground". That is why it was not recognized properly
Started writing a Engineering Blog
At First
I'm in the first year of master's degree at a university in Japan.
I decided to write an engineering blog to share some of my knowledge about Aerospace and Robotics, as there aren't many of that field shared throughout the internet.
Motivation
- To increase my visibility as a robotics engineer on internet
- To leave a memo to myself
- To make people understand more about Robotics Engineer, as it is still unvalued compared to Web Engineer here in Japan.
What will I be Writing?
- Theories and Algorithms related to Robotics
- Debugging
- Thoughts