在linux上安裝機器學習開發環境
阿新 • • 發佈:2018-12-23
2017-05-15
下載Anoconda
Anaconda 是一個用於科學計算的 Python 發行版,支援 Linux, Mac, Windows, 包含了眾多流行的科學計算、資料分析的 Python 包。
Anaconda 具有比pip包管理更強大的能力,不僅管理python 包的依賴,也同時管理其他非python的依賴,所以有逐漸取代pip的趨勢. 同時, Anaconda還有virtual envi等功能, 可以建立虛擬環境.
Anaconda 安裝包可以到 https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ 下載。
TUNA 還提供了 Anaconda 倉庫的映象,執行以下命令:
conda config –add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config –set show_channel_urls yes 即可新增 Anaconda Python 免費倉庫。
Conda 三方源 當前tuna還維護了一些anaconda三方源。
配置
Conda Forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
msys2
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-4.3.1-Linux-x86_64.sh
[ [email protected]nServer ~]$ bash Anaconda3-4.3.1-Linux-x86_64.sh
Welcome to Anaconda3 4.3.1 (by Continuum Analytics, Inc.)
[[email protected] ~]$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
[[email protected] ~]$ conda config --set show_channel_urls yes
[ [email protected] ~]$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
[[email protected] ~]$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
[[email protected] ~]$ vi .condarc
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- defaults
show_channel_urls: true
安裝機器學習相關包
安裝numpy scipy mkl
[[email protected] ~]$ conda install numpy scipy mkl
Fetching package metadata ...
CondaHTTPError: HTTP None None for url <https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64/repodata.json>
Elapsed: None
An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
SSLError(SSLError(SSLError("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",),),)
刪除 .condarc的- defaults
[[email protected] ~]$ conda config --show
add_anaconda_token: True
add_pip_as_python_dependency: True
allow_softlinks: True
always_copy: False
always_softlink: False
always_yes: False
auto_update_conda: True
binstar_upload: None
changeps1: True
channel_alias: https://conda.anaconda.org
channel_priority: True
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
client_ssl_cert:
client_ssl_cert_key:
create_default_packages: []
debug: False
default_channels:
- https://repo.continuum.io/pkgs/free
- https://repo.continuum.io/pkgs/r
- https://repo.continuum.io/pkgs/pro
disallow: []
envs_dirs:
- /home/zhouhh/anaconda3/envs
- /home/zhouhh/.conda/envs
json: False
offline: False
proxy_servers: {}
quiet: False
shortcuts: True
show_channel_urls: True
ssl_verify: True
track_features: []
update_dependencies: True
use_pip: True
verbosity: 0
安裝theano
[[email protected] ~]$ conda intall theano
The following NEW packages will be INSTALLED:
libgpuarray: 0.6.4-0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
mako: 1.0.6-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
pygpu: 0.6.4-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
theano: 0.9.0-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
安裝keras
預設會安裝tensorflow 1.1
[[email protected] ~]$ conda install keras
Fetching package metadata .....
Solving package specifications: .
Package plan for installation in environment /home/zhouhh/anaconda3:
The following NEW packages will be INSTALLED:
keras: 2.0.2-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
libprotobuf: 3.2.0-0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
protobuf: 3.2.0-py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
tensorflow: 1.1.0-np112py36_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
測試機器學習環境
[zhouhh@mainServer ~]$ python3
Python 3.6.0 |Anaconda custom (64-bit)| (default, Dec 23 2016, 12:22:00)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from keras.models import Sequential
Using TensorFlow backend.
>>> from keras.layers import Dense, Activation
>>> model = Sequential([
... Dense(32, input_shape=(784,)),
... Activation('relu'),
... Dense(10),
... Activation('softmax'),
... ])
修改.keras/keras.json 將”backend”: “tensorflow”改為 “backend”: “theano”
[[email protected] ~]$ cat .keras/keras.json
{
"epsilon": 1e-07,
"floatx": "float32",
"image_data_format": "channels_last",
"backend": "theano"
}
[[email protected] ~]$ python3
Python 3.6.0 |Anaconda custom (64-bit)| (default, Dec 23 2016, 12:22:00)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from keras.models import Sequential
Using Theano backend.
>>> from keras.layers import Dense, Activation
>>> model = Sequential([
... Dense(32, input_shape=(784,)),
... Activation('relu'),
... Dense(10),
... Activation('softmax'),
... ])
>>>
至此,keras,tensorflow和theano安裝成功
如非註明轉載, 均為原創. 本站遵循知識共享CC協議,轉載請註明來源