Ubuntu: Python2.7綠色版製作方法_20180427_七俠鎮莫尛貝
目的:在另外一臺不能訪問外網的同版本ubuntu機器上安裝Python2.7環境和相關庫
測試環境:Ubuntu14.04
步驟:
1.安裝好Python2.7並安裝你的專案執行所依賴的庫。
2.抽取python2.7相關檔案和目錄,get_py27.sh:
#!/bin/bash
mkdir py27x64_u14
cd py27x64_u14
cp /usr/bin/python ./
cp -r /usr/lib/python2.7 ./usr_lib_python2.7
cp -r /usr/local/lib/python2.7 ./usr_local_lib_python2.7
#某些通過apt install安裝的庫會放到這裡,比如:apt install python-mysqldb
cp /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18 ./usr_lib_x86_64-linux-gnu/
3.打包這個資料夾,複製到目標機
4.初始化python2.7環境,init_python_env.sh:
#!/bin/bash
basepath=$(cd `dirname $0`; pwd)
echo 當前目錄:$basepath
rm -fr /usr/bin/python
rm -fr /usr/lib/python2.7
rm -fr /usr/local/lib/python2.7
ln -s $basepath/python /usr/bin/python
ln -s $basepath/usr_lib_python2.7 /usr/lib/python2.7
ln -s $basepath/usr_local_lib_python2.7 /usr/local/lib/python2.7
#apt install python-mysqldb。如果是ubuntu16,則為libmysqlclient.so.20
ln -s $basepath/usr_lib_x86_64-linux-gnu/libmysqlclient.so.18 /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18
echo "Python2.7 init OK!"
5.測試通過。
8.缺點:無法使用pip增加額外庫
2018/8/6 補充:
應該還是可以安裝額外庫的.參考:http://cx-oracle.readthedocs.io/en/latest/installation.html
首先安裝pip,這個應該可以實現綠色移植(待測試): apt install python-pip
然後:
python -m pip install cx_Oracle --upgrade