--- title: 'Python環境架設(ubuntu 18.04)' disqus: hackmd --- Python環境架設(ubuntu 18.04) === [TOC] ## 安裝 Anaconda ### 下載 Anaconda > (1) 至官網下載安裝檔 ```gherkin= https://www.anaconda.com/products/individual ``` > (2) 安裝 ```gherkin= 打開命令提示字元 $ cd ~/Dowloads/ $ sudo chmod +x Anaconda3-2020.11-Linux-x86_64.sh $ ./Anaconda3-2020.11-Linux-x86_64.sh 完成後會將Anaconda3相關路徑加到~/.bashrc ``` > (2) 建立python環境 ```gherkin= $ conda create -n tracker python=3.7 tracker為這個個虛擬環境的名字 ``` > (2) 轉換到此python環境 ```gherkin= $ conda activate tracker 使用下列指令可以察看目前有建立哪些虛擬環境 conda env list ``` ### 安裝需要Package >(1)打開命令提示字元 * 安裝以下: ```gherkin= $ conda activate tracker $ pip install shortuuid $ pip install pyinstaller==4.4 $ pip install numpy scipy imutils ``` opencv套件部份 ```gherkin= 直接輸入這個會show 出當前所有版本(注意先不要切換到環境 $ pip install opencv-python== ``` ![](https://i.imgur.com/jC47DHr.png) ```gherkin= 此為測試目前能使用到的最高版本,太高在tracker方面會出問題 $ conda activate tracker 若沒有要用yolov4 $ pip install opencv-python==4.2.0.34 $ pip install opencv-contrib-python==4.2.0.34 若要用yolov4 $ pip install opencv-python==4.4.0.40 $ pip install opencv-contrib-python==4.4.0.40 ``` 若要移除opencv更新版本可參考如下指令 ```gherkin= pip uninstall -y opencv-python pip uninstall -y opencv-contrib-python ``` 若是要裝到opencv最新版本可參考如下指令 ```gherkin= pip install opencv-python --upgrade pip install opencv-contrib-python --upgrade ``` * **若日後在執行程式時,出現Python ImportError: No module named 'XXXX'就代表說,缺少了某樣package,請再次輸入pip3 install XXXX,每個程式需要的package都不盡相同,若缺少就安裝起來** 若有出現如下情況 ,請按照下列指令解決 ![](https://i.imgur.com/M6TyagH.png) ```gherkin= conda uninstall pyqt -n tracker(虛擬環境名稱) ``` ### pip 安裝套件查詢 ```gherkin= $ pip list ``` ![](https://i.imgur.com/N1FrlSt.png) ### 測試Python是否正常執行 >(1)打開命令提示字元 ```gherkin= $ conda activate tracker $ python print ('hello') exit() ``` ![](https://i.imgur.com/tqGwGXe.png) * **若日後在執行程式時,出現Python ImportError: No module named 'XXXX'就代表說,缺少了某樣package,請再次輸入pip3 install XXXX,由於每個程式需要的package都不盡相同,若缺少就安裝起來** opencv 版本查詢 ```gherkin= $ conda activate tracker pthon import cv2 cv2.__version__ ``` ### 之後版本確定後請製作requirements.txt(尚未完成) requirements example: numpy==1.19.1 opencv-python==4.3.0.38 Pillow==7.2.0 scipy==1.5.2 torch==1.6.0 torchvision==0.7.0 ```gherkin= 安裝 $ pip install -r requirements.txt ``` ### 測試 vott與 CVTRK相關程式 請參考[此文章 ](https://hackmd.io/@NTUTVOTT/HkDpdiE8D) 下載程式碼 vott_tracker.py測試指令 ```gherkin= $ python3 vott_tracker.py ../../../Drone_Target/vott_source_info.tmp ../../../Drone_Target/vott_target_path.json v0.04之後的版本請用 $ python3 vott_tracker.py ../../../Drone_Target/vott_source_info.json ../../../Drone_Target/vott_target_path.json ``` ###### tags: `setup`, `Python`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up