張小白教你創(chuàng)建云服務(wù)器鏡像(省錢妙方)">張小白教你創(chuàng)建云服務(wù)器鏡像(省錢妙方)
792
2025-03-31
雙節(jié)期間,萬事求雙。
光有 《張小白帶你快速體驗MindSpore V1.0(For ubuntu 18.04)》https://bbs.huaweicloud.com/blogs/198324 是不夠的。很多開發(fā)者也想知道源碼安裝該怎么搞。那就讓在這里摸爬滾打過好幾天的張小白,告訴你怎么整吧。。。本文是?https://bbs.huaweicloud.com/forum/thread-80520-1-1.html?論壇文檔的去粗求精版。
打開?https://www.mindspore.cn/install?,按下面方式分別選擇:1.0.0+CPU+Ubuntu-x86+Python 3.7.5+Source。
然后我們看下選中后,鏈接下面顯示的軟件依賴:
源碼安裝需要Python 3.7.5,? wheel 0.32.0(使用pip裝) Gcc 7.3.0 CMake 3.14.1 patch 2.5
安裝依賴是個requirements.txt
numpy?>=?1.17.0,?<=?1.17.5 protobuf?>=?3.8.0 asttokens?>=?1.1.13 pillow?>=?6.2.0 scipy?>=?1.3.3 easydict?>=?1.9 sympy?>=?1.4 cffi?>=?1.13.2 wheel?>=?0.32.0 decorator?>=?4.4.0 setuptools?>=?40.8.0 matplotlib?>=?3.1.3?????????#?for?ut?test opencv-python?>=?4.1.2.30???#?for?ut?test sklearn?>=?0.0??????????????#?for?st?test pandas?>=?1.0.2?????????????#?for?ut?test bs4 astunparse packaging?>=?20.0
那么我們一個一個來準備吧:
Part One:首先,你需要一個ubuntu 18.04的系統(tǒng)環(huán)境。
這個環(huán)境你可以直接在臺式機或筆記本上裝系統(tǒng),也可以像張小白那樣,用虛擬機做。
具體的過程張小白在?《張小白帶你快速體驗MindSpore V1.0(For ubuntu 18.04)》https://bbs.huaweicloud.com/blogs/198324?和 《Atlas 200DK系統(tǒng)折騰紀實:(1)論圖片及18.04.1的誕生》https://bbs.huaweicloud.com/blogs/194291?兩個地方寫的都很清楚了(建議看后者的Part II部分)
這里不再贅述。
這里ubuntu裝完后,記得替換apt源。張小白選擇的是阿里源(也可以選擇華為源或者其他源)
sudo cp /etc/apt/sources.list /etc/apt/source.list.bk
vi /etc/apt/sources.list
注釋現(xiàn)有所有的deb
貼入以下內(nèi)容:
#?阿里源 deb?http://mirrors.aliyun.com/ubuntu/?bionic?main?restricted?universe?multiverse deb?http://mirrors.aliyun.com/ubuntu/?bionic-security?main?restricted?universe?multiverse deb?http://mirrors.aliyun.com/ubuntu/?bionic-updates?main?restricted?universe?multiverse deb?http://mirrors.aliyun.com/ubuntu/?bionic-proposed?main?restricted?universe?multiverse deb?http://mirrors.aliyun.com/ubuntu/?bionic-backports?main?restricted?universe?multiverse deb-src?http://mirrors.aliyun.com/ubuntu/?bionic?main?restricted?universe?multiverse deb-src?http://mirrors.aliyun.com/ubuntu/?bionic-security?main?restricted?universe?multiverse deb-src?http://mirrors.aliyun.com/ubuntu/?bionic-updates?main?restricted?universe?multiverse deb-src?http://mirrors.aliyun.com/ubuntu/?bionic-proposed?main?restricted?universe?multiverse deb-src?http://mirrors.aliyun.com/ubuntu/?bionic-backports?main?restricted?universe?multiverse
保存退出。
sudo apt update
Part Two:源碼安裝gcc 7.3.0
先使用apt install裝下gcc,看看是什么版本?
sudo apt-get update
sudo apt-get install aptitude
sudo aptitude install gcc
耐心的等待結(jié)束:
sudo apt install gcc
sudo apt-get install g++
要求7.3.0,實際7.5.0。在不知道高版本是否可用的情況下,看來要盡量使用官方文檔建議的版本了。
查了下資料,安裝gcc 7.3.0需要完成以下內(nèi)容:mpc+gmp+mpfr+gcc。下面詳細講解:
(1)下載
到?http://www.multiprecision.org/mpc/download.html?網(wǎng)站下載 mpc-1.1.0.tar.gz
wget?http://www.multiprecision.org/downloads/mpc-1.1.0.tar.gz
到?ftp://ftp.gnu.org/gnu/gmp/gmp-5.0.1.tar.bz2 下載gmp-5.0.1.tar.bz2
wget?ftp://ftp.gnu.org/gnu/gmp/gmp-5.0.1.tar.bz2
到?http://ftp.gnu.org/gnu/mpfr/? 下載mpfr-3.1.0.tar.xz。
wget?http://ftp.gnu.org/gnu/mpfr/mpfr-3.1.0.tar.xz
(2)安裝gmp
bzip2 -d gmp-5.0.1.tar.bz2
tar xvf gmp-5.0.1.tar
configure:
...
說缺m4...那就裝m4吧。。。
再來configure...
...
成功了。
make。。。沒有make。
按提示裝make吧。。
再裝make-guile
看下make版本:
要求3.14.1,現(xiàn)在是4.1,應(yīng)該是夠了。
再make吧。屏幕刷刷的編譯中。。。
make完成。安裝:
。。。
GMP搞定了。
(3)安裝mpfr
xz -d mpfr-3.1.0.tar.xz
tar xvf mpfr-3.1.0.tar
解壓后進入目錄做configure
./configure --prefix=/usr/local/mpfr-3.1.0 --with-gmp=/usr/local/gmp-5.0.1
沒報錯:
make,編譯刷屏中。。。
成功了:
安裝:
sudo make install
...
mpfr安裝完畢。
(3)安裝mpc
gzip -d mpc*.gz
tar xvf mpc*.tar
繼續(xù)configure
./configure --prefix=/usr/local/mpc-1.1.0 --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.0
..成功configure
make 刷屏中。。。
成功make
sodu make install 安裝
。。。
mpc也成功安裝。
(4)配置庫環(huán)境
在/etc/ld.so.conf添加以下行
/usr/local/gmp-5.0.1/lib
/usr/local/mpfr-3.1.0/lib
/usr/local/mpc-1.1.0/lib
sudo ldconfig
(5)下載gcc 7.3.0源碼包并安裝
gzip -d gcc*.gz
tar xvf gcc-7.3.0.tar
cd gcc-7.3.0
./configure --with-gmp=/usr/local/gmp-5.0.1 --with-mpc=/usr/local/mpc-1.1.0 --with-mpfr=/usr/local/mpfr-3.1.0 --disable-multilib
以上地址都是前面安裝的地址。記得一一對應(yīng)。
。。。
configure成功
make
等刷完屏
。。。
時間會比較長。。。
也不知道怎么才能提速。好像一個多小時了。。
編譯完畢。
sudo make install
gcc 7.3.0安裝在 /usr/local/bin目錄下。 gcc 7.5.0是個符號鏈接,指向/usr/bin/g**-7 。。
所以可以暫時將/usr/bin/gcc 和g++重新指向 /usr/local/bin/gcc和g++
用root用戶做吧。。否則要不停的sudo
root@ubuntu:/usr/bin#?cp?gcc?gcc7.5 root@ubuntu:/usr/bin#?cp?g++?g++7.5 root@ubuntu:/usr/bin#?rm?gcc root@ubuntu:/usr/bin#?rm?g++ root@ubuntu:/usr/bin#?ln?-s?/usr/local/bin/gcc?gcc root@ubuntu:/usr/bin#?ln?-s?/usr/local/bin/g++?g++ root@ubuntu:/usr/bin#?ls?-lrt?gcc lrwxrwxrwx?1?root?root?18?Oct??2?18:54?gcc?->?/usr/local/bin/gcc root@ubuntu:/usr/bin#?ls?-lrt?g++ lrwxrwxrwx?1?root?root?18?Oct??2?18:54?g++?->?/usr/local/bin/g++
回到普通用戶:
總算gcc 7.3.0安裝成功。
Part Three:源碼安裝python3.7.5
先裝一些依賴:
sudo apt-get install -y build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev
。。。
在python官網(wǎng)已經(jīng)找不到 3.7.5了。
好在在華為云的鏡像站有:
https://mirrors.huaweicloud.com/python/
果然有,復制地址,打開新的teminal,下載吧。。。
wget?https://mirrors.huaweicloud.com/python/3.7.5/Python-3.7.5.tar.xz
解壓:
xz -d Python-3.7.5.tar.xz
tar xvf Python-3.7.5.tar
。。。
python安裝源碼包搞定。
配置:
./configure --prefix=/usr/python3 --enable-optimizations --enable-shared
(上面這句話很重要,記得看三遍。。。)
make
等待刷屏結(jié)束。。。
make install
這個時候需確認 /usr/python3/lib目錄下的文件名是否是.so而不是.a:(so是動態(tài)庫,a是靜態(tài)庫,最后mindspore的編譯需要動態(tài)庫才行。。)
切換到python3.7.5 安裝后的目錄/usr/python3,查看版本:
在/etc/profile加入/usr/python3/bin的PATH,并執(zhí)行,這樣可以在任何地方都可以優(yōu)先執(zhí)行python 3.7.5
Part Four:部分系統(tǒng)依賴和PIP依賴的安裝
在源碼安裝之前,還是要把前面提到的依賴補充一下。
(1)先安裝一些pip的依賴:
python3 -m pip install Pillow
先把Pillow裝完。這里比較慢,下次記得pip install時,加pip的清華源。
裝前面requirements對應(yīng)的依賴。。
python3 -m pip install protobuf asttokens scipy easydict sympy cffi wheel decorator setuptools matplotlib sklearn pandas bs4 astunparse packaging?-i?https://pypi.tuna.tsinghua.edu.cn/simple/
Successfully installed asttokens-2.0.4 astunparse-1.6.3 beautifulsoup4-4.9.2 bs4-0.0.1 certifi-2020.6.20 cffi-1.14.3 cycler-0.10.0 decorator-4.4.2 easydict-1.9 joblib-0.17.0 kiwisolver-1.2.0 matplotlib-3.3.2 mpmath-1.1.0 numpy-1.19.2 packaging-20.4 pandas-1.1.2 protobuf-3.13.0 pycparser-2.20 pyparsing-2.4.7 python-dateutil-2.8.1 pytz-2020.1 scikit-learn-0.23.2 scipy-1.5.2 six-1.15.0 sklearn-0.0 soupsieve-2.0.1 sympy-1.6.2 threadpoolctl-2.1.0 wheel-0.35.1
裝numpy:
python3 -m pip install numpy==1.17.5 -i https://pypi.tuna.tsinghua.edu.cn/simple/
裝opencv-python
python3 -m pip install?opencv-python?-i?https://pypi.tuna.tsinghua.edu.cn/simple/
慢慢等待它building吧。。。。
做個檢查:
要求:
numpy >= 1.17.0, <= 1.17.5? ? ? ? ??實際 numpy-1.17.5 滿足
protobuf >= 3.8.0??實際 protobuf-3.13.0? 滿足
asttokens >= 1.1.13??實際 astunparse-1.6.3? 滿足
pillow >= 6.2.0??實際7.2.0 滿足
scipy >= 1.3.3??實際 scipy-1.5.2 滿足
easydict >= 1.9??實際??easydict-1.9 滿足
sympy >= 1.4??實際?sympy-1.6.2滿足
cffi >= 1.13.2??實際 ?cffi-1.14.3 滿足
wheel >= 0.32.0???實際wheel-0.35.1 滿足
decorator >= 4.4.0??實際 ?decorator-4.4.2 滿足
setuptools >= 40.8.0? 不清楚裝哪里了。。
matplotlib >= 3.1.3? ? ? ? ?# for ut test??實際matplotlib-3.3.2?滿足
opencv-python >= 4.1.2.30? ?# for ut test??實際opencv-python-4.4.0.44 滿足
sklearn >= 0.0? ? ? ? ? ? ? # for st test?實際? sklearn-0.0?滿足。
pandas >= 1.0.2? ? ? ? ? ? ?# for ut test? ? ?實際pandas-1.1.2?滿足
bs4??實際 ?bs4-0.0.1 滿足
astunparse? ? ? ? ?實際astunparse-1.6.3?滿足
packaging >= 20.0?實際?packaging-20.4 滿足
(2)再安裝一些系統(tǒng)依賴或工具:
patch 2.5.4
wget?http://ftp.gnu.org/gnu/patch/patch-2.5.4.tar.gz
gzip -d patch-2.5.4.tar.gz
tar xvf patch-2.5.4.tar
./configure
sudo make
sudo make install
wheel 0.35.1
wget?https://files.pythonhosted.org/packages/83/72/611c121b6bd15479cb62f1a425b2e3372e121b324228df28e64cc28b01c2/wheel-0.35.1.tar.gz
(后來發(fā)現(xiàn)這個好像不用裝,前面使用pip裝過就可以了) --參見這部分:wheel >= 0.32.0???實際wheel-0.35.1 滿足
cmake 4.1
wget?https://cmake.org/files/v3.14/cmake-3.14.1.tar.gz
gzip -d cmake-3.14.1.tar.gz
tar xvf cmake-3.14.1.tar
進入目錄
./configure
...
sudo make
...
sudo make install
...
確認下:
所有依賴似乎都已就緒。可以編譯mindspore了。。。
Part Five:源碼編譯mindspore v1.0
下載mindspore源碼包:
git clone https://gitee.com/mindspore/mindspore.git -b r1.0
沒裝git, 那就裝唄。。。
重新git clone
cd mindspore
bash build.sh -e cpu -j4
等shell慢慢安裝,有時候會卡死在github的下載處,不要急,可以等。如果等不及了。可以ctrl-c中斷掉,然后手工將文件下載下來拷貝到dest目錄下,然后重新運行 bash? build.sh -e cpu -j4 這個過程。
(此處只是做個示范,將自己下載好的gz文件拷貝覆蓋到前面圖中的dst的目錄下的同名文件。)
這個build可以反復運行,它會接著往下跑的,不用擔心。。。
安裝過程一開始還是美好的。畢竟感覺趟過的雷已經(jīng)慢慢快結(jié)束了。。
一直等待進度100%。。
當然,裝到最后,它會報個錯:
不要緊,百度下原因:是還有少裝的包:
那么,照此辦理吧:
再重新執(zhí)行build.sh
...
終于順利的編譯完了。。。
編譯好的文件放在了?/root/mindspore/build/package 目錄下了。
Part Six:安裝mindspore v1.0
使用剛才自己編譯好的whl來安裝mindspore。。
python3 -m install ./mindspore-1.0.0-cp37-cp37m-linux_x86_64.whl
好像沒問題。。。跟使用官方whl的結(jié)果一模一樣。
Part Seven:源碼安裝的mindspore v1.0的LeNet驗證
那還是用lenet進行mindspore的測試吧。。。
將 《張小白帶你快速體驗MindSpore V1.0(For ubuntu 18.04)》https://bbs.huaweicloud.com/blogs/198324? 使用的lenet.zip包導入系統(tǒng)。
unzip lenet.zip
cd lenet目錄
訓練完畢。
然后,驗證:
驗證完畢。
跟前面那個博客的官方whl包的推理和驗證的結(jié)果類似,只是要精度要低一點。。。
好吧。這就把mindspore v1.0源碼安裝和驗證的過程徹底完成了。。。。
(全文完,謝謝閱讀)
AI平臺 EI企業(yè)智能 昇騰
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔相應(yīng)法律責任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實的內(nèi)容,請聯(lián)系我們jiasou666@gmail.com 處理,核實后本網(wǎng)站將在24小時內(nèi)刪除侵權(quán)內(nèi)容。
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔相應(yīng)法律責任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實的內(nèi)容,請聯(lián)系我們jiasou666@gmail.com 處理,核實后本網(wǎng)站將在24小時內(nèi)刪除侵權(quán)內(nèi)容。