LoginSignup
13
12

More than 5 years have passed since last update.

CentOS で yum remove pythonをしたら詰みました。

Posted at

Python環境を作ろうと思って失敗しました。環境はVagrantのCentOS5.6です。

pipをインストール

pipをインストールします。

pipをインストールで失敗
sudo yum install -y pip

No package pip available.

ありゃ。。

setuptoolsをインストールします
sudo yum -y install python-setuptools
sudo easy_install pip

なにかはいったぽい??

けど

pipでシンタックスエラー
pip -h
Traceback (most recent call last):
  File "/usr/bin/pip", line 7, in ?
    sys.exit(
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 236, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 2097, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 1830, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.4/site-packages/pip-7.1.2-py2.4.egg/pip/__init__.py", line 211
    except PipError as exc:
                     ^
SyntaxError: invalid syntax

SyntaxErrorがでてだめぽいです。

Pythonのバージョンを確認
python -v

Python 2.4.3 (#1, Mar  5 2011, 21:26:05) 

そもそもPythonが古そうなのでバージョンを上げると良いかもと考えました。

パッケージのインストール

Pythonで使うらしいパッケージをインストールしました。

sudo yum install zlib zlib-devel tk-devel tcl-devel sqlite-devel ncurses-devel gdbm-devel readline-devel bzip2-devel db4-devel openssl-devel

wget python2.7経由でpython2.7をインストールする

Python2.7をインストールします。

wget http://python.org/ftp/python/2.7.2/Python-2.7.2.tgz
tar zxvf Python-2.7.2.tgz

解凍すると、Python-2.7.2というディレクトリができています。

ll
total 67788
drwxr-x--- 17 vagrant vagrant     4096 Jun 11  2011 Python-2.7.2
-rw-rw-r--  1 vagrant vagrant 14091337 Jun 11  2011 Python-2.7.2.tgz

できたディレクトリに移動します。

cd Python-2.7.2
./configure --with-threads --enable-shared
make
sudo make install
python

python2.7: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

あら。。libpython2.7.so.1.0が開けないそうです。

libpython2.7.so.1.0にシンボリックリンクを貼る
sudo ln -s /usr/local/lib/libpython2.7.so.1.0 /lib64/

ここにはシンボリックリンクを貼るみたいです。
再度makeします。

./configure --with-threads --enable-shared
make
sudo make install
python
Python 2.7.2 (default, Oct 28 2015, 12:10:09) 

Python2.7.2になりました。

元からあったyumのPythonを確認してみます。

yum list installed python
略
python.x86_64                                                2.4.3-43.el5                                                 installed

yum の Pythonとは違うバージョンになりました。

pipをインストールで失敗

sudo easy_install pip
Searching for pip
Best match: pip 7.1.2
Processing pip-7.1.2-py2.4.egg
pip 7.1.2 is already the active version in easy-install.pth
Installing pip script to /usr/bin
Installing pip2 script to /usr/bin
Installing pip2.4 script to /usr/bin

Using /usr/lib/python2.4/site-packages/pip-7.1.2-py2.4.egg
Processing dependencies for pip

失敗しました。2.4を見ているみたいです。

Python2.4を削除したらPython2.7で動くようになるかも?

pythonをremove
sudo yum remove python

やたら関連パッケージが大量にあるなと思ったのですが、削除しました。

主要コマンドが動かなくなる

Python2.4をremoveしたら主要コマンドが効かなくなりました。

sudoコマンドがなくなる
sudo
-bash: /usr/bin/sudo: No such file or directory

yum
-bash: /usr/bin/yum: No such file or directory

sudoやyumなどコマンドが効かなくなりました。完全に詰みました\(^o^)/

Vagrantのboxから復帰を試みる

幸いなことに3日前に当環境のVagrantのBoxをpackage.boxにしていました。ラッキー\(^o^)/

boxを削除する
vagrant box remove pugiemonn-centos5.6

現在のboxを削除しました。

boxを削除する
vagrant box add pugiemonn-centos5.6 package.box

とってあったpackage.boxから同名のboxを入れなおしました。
boxを入れなおしただけなので、Vagrantfileの変更は必要ないです。

Vagrantが立ち上がらない

Vagrantを立ち上げます。

vagrant up
略
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

Connection timeout.がでます。

これはVagrantを立ち上げっぱなしででvagrant box removeをしたので、VirtualBox内でOSが起動しっぱなしになったりしている現象でした。

該当Vagrantboxのディレクトリごと消すか、VirtualBoxから起動しているOSを削除すると良いです。今回は後者でVirtualBoxからOSを消しました。

一応boxのremoveとaddをやり直しておきました。

Vagrantを立ち上げる

vagrant up

今度は成功しました。動作しているみたいなので良かったです。

感想

yum remove pythonはそもそもやってはいけなかったみたいです(☝ ՞ਊ ՞)

参考

13
12
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
13
12