anaconda環境---ubuntu下重裝
@wp20190312
為何重裝? 配置一個環境,意外發現conda命令不好用了,提示“找不到conda模塊”,整個conda虛擬環境中的工程項目無法使用,網上有說主要是python路徑的指向調用出現了問題。經過多番嘗試仍然未解決問題,所以還是重裝一下吧,簡單bao力。
原來使用的是anaconda2,這次改用anaconda3。
(1)卸載原來的anaconda2:rm -rf /home/wp/anaconda2
(2)安裝新的anaconda3
在網址 https://www.cnblogs.com/gaofighting/p/8799169.html 中下載anaconda3
wp@wp-MS-7519:~/Anaconda3$ sudo sh Anaconda3-2018.12-Linux-x86_64.sh #安裝完后帶鎖
sh Anaconda3-2018.12-Linux-x86_64.sh #安裝完后不帶鎖
=======================安裝過程部分展示================================
一直enter到選擇yes?
Anaconda3 will now be installed into this location:
/home/wp/anaconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/home/wp/anaconda3] >>>
PREFIX=/home/wp/anaconda3
# 安裝根據機器性能,通常需要持續幾分鍾。
Do you wish the installer to initialize Anaconda3
in your /home/wp/.bashrc ? [yes|no]
[no] >>>
You may wish to edit your /home/wp/.bashrc to setup Anaconda3:
source /home/wp/anaconda3/etc/profile.d/conda.sh
Thank you for installing Anaconda3!
====================================================================
To install Visual Studio Code, you will need:
- Administrator Privileges
- Internet connectivity
Visual Studio Code License: https://code.visualstudio.com/license
Do you wish to proceed with the installation of Microsoft VSCode? [yes|no]
>>> yes
Proceeding with installation of Microsoft VSCode
VSCode is already installed!
到此Anaconda3安裝成功。 重啟終端,即可使用Anaconda3
假如,Anaconda3未安裝成功,可以執行: rm -rf ~/anaconda3 ,找到Anaconda3的安裝路徑,卸載后重新安裝即可。
===============================================================
(3)在終端,查看當前電腦的python版本:
wp@wp-MS-7519:~/anaconda3$ python
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
wp@wp-MS-7519:~/anaconda3$ python3
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
我們可以看到,若在終端輸入 python,仍然會顯示Ubuntu自帶的python版本。
(4)所以如果想用anaconda,則需要修改終端的默認python為anaconda,執行:
wp@wp-MS-7519:~/anaconda3$ gedit ~/.bashrc
在文件后面添加:export PATH="/home/wp/anaconda3/bin:$PATH" #並保存
wp@wp-MS-7519:~/anaconda3$ source ~/.bashrc #使用修改的路徑生效
【export PATH=/home/wp/anaconda2/bin:$PATH
gedit ~/.bashrc
source ~/.bashrc】
(5)再次,查看當前電腦的python版本:
wp@wp-MS-7519:~/anaconda3$ python -V
Python 3.7.1 #anaconda3 安裝的python版本
wp@wp-MS-7519:~/anaconda3$ python
Python 3.7.1 (default, Dec 14 2018, 19:28:38)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
wp@wp-MS-7519:~/anaconda3$ python2
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
(6)根據工作要求,增加虛擬環境。
6.1查找可用版本:conda search "^python$"
wp@wp-MS-7519:~/anaconda3$ conda search "^python$"
Loading channels: done
# Name Version Build Channel
python 1.0.1 0 anaconda/cloud/conda-forge
python 1.0.1 0 anaconda/pkgs/free
........
python 2.7.3 2 anaconda/pkgs/free
python 2.7.3 3 anaconda/pkgs/free
python 2.7.3 4 anaconda/pkgs/free
python 2.7.3 5 anaconda/pkgs/free
......................
python 2.7.15 0 anaconda/cloud/conda-forge
python 2.7.15 h1571d57_0 anaconda/pkgs/main
python 2.7.15 h33da82c_1 anaconda/cloud/conda-forge
python 2.7.15 h33da82c_3 anaconda/cloud/conda-forge
python 2.7.15 h33da82c_4 anaconda/cloud/conda-forge
...
python 2.7.15 h9bab390_2 anaconda/pkgs/main
python 2.7.15 h9bab390_4 anaconda/pkgs/main
python 2.7.15 h9bab390_6 anaconda/pkgs/main
python 2.7.15 h9fef7bc_0 anaconda/cloud/conda-forge
................................
python 3.5.0 0 anaconda/pkgs/free
python 3.5.0 1 anaconda/pkgs/free
python 3.5.1 0 anaconda/cloud/conda-forge
python 3.5.1 0 anaconda/pkgs/free
python 3.5.1 1 anaconda/cloud/conda-forge
python 3.5.1 5 anaconda/pkgs/free
python 3.5.2 0 anaconda/cloud/conda-forge
python 3.5.2 0 anaconda/pkgs/free
python 3.5.2 1 anaconda/cloud/conda-forge
...
python 3.5.5 hc3d631a_0 anaconda/pkgs/main
python 3.5.5 hc3d631a_1 anaconda/pkgs/main
python 3.5.5 hc3d631a_3 anaconda/pkgs/main
python 3.5.5 hc3d631a_4 anaconda/pkgs/main
python 3.5.6 hc3d631a_0 anaconda/pkgs/main
python 3.6.0a3 0 anaconda/cloud/conda-forge
............................
python 3.6.7 hd21baee_1002 anaconda/cloud/conda-forge
python 3.6.8 h0371630_0 anaconda/pkgs/main
python 3.7.0 h5001a0f_0 anaconda/cloud/conda-forge
python 3.7.0 h5001a0f_1 anaconda/cloud/conda-forge
python 3.7.0 h5001a0f_4 anaconda/cloud/conda-forge
python 3.7.0 h5001a0f_6 anaconda/cloud/conda-forge
python 3.7.0 h6e4f718_3 anaconda/pkgs/main
...
python 3.7.1 h0371630_7 anaconda/pkgs/main
python 3.7.1 h381d211_1002 anaconda/cloud/conda-forge
python 3.7.1 h5001a0f_0 anaconda/cloud/conda-forge
python 3.7.1 hd21baee_1000 anaconda/cloud/conda-forge
python 3.7.1 hd21baee_1001 anaconda/cloud/conda-forge
python 3.7.2 h0371630_0 anaconda/pkgs/main
6.2下載的TensorFlow對應的Python版本一定要和conda create -n tensorflow python=x.x的版本一樣才行。
考慮,環境沒破壞之前,FaceNet使用的環境:Ubuntu 18.04 + Tensorflow 1.5.0 + Python 2.7 + OpenCV 3.2.0,
A1,這里,裝一個Python 2.7,配一個Tensorflow 1.5.0 環境。
wp@wp-MS-7519:~/anaconda3$ conda create -n test_py2 python=2
wp@wp-MS-7519:~/anaconda3$ source activate test_py2
wp@wp-MS-7519:~/anaconda3$ python #查看是python2.7.15
wp@wp-MS-7519:~/anaconda3$ pip install tensorflow
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Looking in indexes: http://pypi.douban.com/simple
Collecting tensorflow
Downloading http://pypi.doubanio.com/packages/d2/ea/ab2c8c0e81bd051cc1180b104c75a865ab0fc66c89be992c4b20bbf6d624/tensorflow-1.13.1-cp27-cp27mu-manylinux1_x86_64.whl (92.5MB)
B1,安裝完成后,python ,import tensorflow as tf,報錯
>>> import tensorflow as tf
2019-03-11 16:39:04.749263: F tensorflow/core/platform/cpu_feature_guard.cc:37] The TensorFlow library was compiled to use SSE4.2 instructions, but these aren't available on your machine.
已放棄 (核心已轉儲)
解決辦法:安裝bazel,編譯tensorflow。這個問題的原因是CPU支持更快的運算,安裝的Tensorflow中缺少對應的模塊,需要編譯安裝。當我們使用GPU的情況下,並不需要用到CPU,所以這些warning可以忽略。 安裝bazel 太麻煩了,換思路解決“安裝tf”。
C1,卸載tensorflow:(test_py2) wp@wp-MS-7519:~/anaconda3$ pip uninstall tensorflow
D1,重新安裝tensorflow:sudo pip install --ignore-installed --upgrade https://mirrors.tuna.tsinghua.edu.cn/tensorflow/linux/cpu/tensorflow-1.5.0-cp27-none-linux_x86_64.whl
這里說明一下: 這一步安裝之后,python2下面import tensorflow as tf 還是報錯,但是在python3下面import tensorflow as tf 不報錯。所以,換思路。
A2,換思路,裝一個Python 3.5,配一個Tensorflow 1.5.0 環境。【剛開始裝的是Python 3.6和Tensorflow 1.5.0 最后不好用,經過折騰換Python 3.5好用。】
wp@wp-MS-7519:~/anaconda3$ conda create -n test_py3 python=3.6
wp@wp-MS-7519:~/anaconda3$ source activate test_py3
(test_py3) wp@wp-MS-7519:~/anaconda3$ cd test_py3
(test_py3) wp@wp-MS-7519:~/anaconda3/test_py3$ cd tf
(test_py3) wp@wp-MS-7519:~/anaconda3/test_py3/tf$ python
Python 3.6.7 | packaged by conda-forge | (default, Feb 28 2019, 09:07:38)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
安裝tf:sudo pip install --ignore-installed --upgrade https://mirrors.tuna.tsinghua.edu.cn/tensorflow/linux/cpu/tensorflow-1.5.0rc0-cp36-cp36m-linux_x86_64.whl
安裝tf報錯:tensorflow-1.5.0rc0-cp36-cp36m-linux_x86_64.whl is not a supported wheel on this platform.
退出虛擬環境,並卸載python3.6,重裝python3.5
(test_py3) wp@wp-MS-7519:~/anaconda3/test_py3/tf$ source deactivate (conda deactivate) #退出虛擬環境
wp@wp-MS-7519:~/anaconda3/test_py3/tf$ conda remove --name test_py3 --all #卸載python3.6
wp@wp-MS-7519:~/anaconda3/test_py3/tf$ conda create -n test_py3 python=3.5 #重裝python3.5
(test_py3) wp@wp-MS-7519:~/anaconda3/test_py3/tf$ conda activate test_py3
(test_py3) wp@wp-MS-7519:~/anaconda3/test_py3/tf$ pip install --ignore-installed --upgrade tensorflow-1.5.0-cp35-cp35m-linux_x86_64.whl
【安裝下載鏡像網址 https://mirrors.tuna.tsinghua.edu.cn/tensorflow/linux/cpu/】
(test_py3) wp@wp-MS-7519:~/anaconda3/test_py3/tf$ python
Python 3.5.5 | packaged by conda-forge | (default, Jul 23 2018, 23:45:43)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
'1.5.0'
>>>
提示,這里需要 py 和 tf 版本相匹配,所以可能會出現反復的:
(1)安裝 conda create -n test_py3 python=3.5 與卸載 conda remove --name test_py3 --all ,
(2)安裝 pip install --ignore-installed --upgrade tf_setup_name 與卸載 pip uninstall tensorflow 。
【
總結說明:
安裝可用環境:conda create --name my_env python=3
刪除環境變量:conda remove --name my_env --all
激活新環境:source activate my_env
停用環境:source deactivate
安裝可用環境python3.5版本:conda create -n my_env35 python=3.5
刪除可用環境python3.5版本:conda remove --name my_env35 --all
激活新環境:source activate my_env
停用:source deactivate
更新版本:conda update python=3.5.2
查看所有環境:conda info --envs
給環境安裝其他軟件包:conda install --name my_env35 numpy
更新 anaconda:conda update conda
卸載Anaconda:conda install anaconda-clean --yes
rm -rf ~/anaconda3
vim ~/.bashrc
更換倉庫鏡像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
】
