Construction d'environnement Python (pyenv, anaconda, tensorflow)

pyenv

$ brew install pyenv
$ vi ~/.bash_profile
# python
PYENV_ROOT=~/.pyenv
export PATH=$PATH:$PYENV_ROOT/bin
eval "$(pyenv init -)"
$ source ~/.bash_profile
$ python -V
Python 2.7.13
$ pyenv version
system (set by /Users/takahiro/.pyenv/version)
$ pyenv help
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   commands    List all available pyenv commands
   local       Set or show the local application-specific Python version
   global      Set or show the global Python version
   shell       Set or show the shell-specific Python version
   install     Install a Python version using python-build
   uninstall   Uninstall a specific Python version
   rehash      Rehash pyenv shims (run this after installing executables)
   version     Show the current Python version and its origin
   versions    List all Python versions available to pyenv
   which       Display the full path to an executable
   whence      List all Python versions that contain the given executable

anaconda

La plupart des bibliothèques utilisées en science des données sont incluses à l'avance.

$ pyenv install -l | grep anaconda3
  anaconda3-2.0.0
  anaconda3-2.0.1
  anaconda3-2.1.0
  anaconda3-2.2.0
  anaconda3-2.3.0
  anaconda3-2.4.0
  anaconda3-2.4.1
  anaconda3-2.5.0
  anaconda3-4.0.0
  anaconda3-4.1.0
  anaconda3-4.1.1
  anaconda3-4.2.0
$ pyenv install anaconda3-4.2.0
$ pyenv versions
* system (set by /Users/takahiro/.pyenv/version)
  anaconda3-4.2.0
$ pyenv shell anaconda3-4.2.0
$ pyenv version
anaconda3-4.2.0 (set by PYENV_VERSION environment variable)
$ python -V
Python 3.5.2 :: Anaconda 4.2.0 (x86_64)
$ pyenv global anaconda3-4.2.0

commande conda

$ conda -h
usage: conda [-h] [-V] command ...

conda is a tool for managing and deploying applications, environments and packages.

Options:

positional arguments:
  command
    info         Display information about current conda install.
    help         Displays a list of available conda commands and their help
                 strings.
    list         List linked packages in a conda environment.
    search       Search for packages and display their information. The input
                 is a Python regular expression. To perform a search with a
                 search string that starts with a -, separate the search from
                 the options with --, like 'conda search -- -h'. A * in the
                 results means that package is installed in the current
                 environment. A . means that package is not installed but is
                 cached in the pkgs directory.
    create       Create a new conda environment from a list of specified
                 packages.
    install      Installs a list of packages into a specified conda
                 environment.
    update       Updates conda packages to the latest compatible version. This
                 command accepts a list of package names and updates them to
                 the latest versions that are compatible with all other
                 packages in the environment. Conda attempts to install the
                 newest versions of the requested packages. To accomplish
                 this, it may update some packages that are already installed,
                 or install additional packages. To prevent existing packages
                 from updating, use the --no-update-deps option. This may
                 force conda to install older versions of the requested
                 packages, and it does not prevent additional dependency
                 packages from being installed. If you wish to skip dependency
                 checking altogether, use the '--force' option. This may
                 result in an environment with incompatible packages, so this
                 option must be used with great caution.
    upgrade      Alias for conda update. See conda update --help.
    remove       Remove a list of packages from a specified conda environment.
    uninstall    Alias for conda remove. See conda remove --help.
    config       Modify configuration values in .condarc. This is modeled
                 after the git config command. Writes to the user .condarc
                 file (/Users/takahiro/.condarc) by default.
    clean        Remove unused packages and caches.
    package      Low-level conda package utility. (EXPERIMENTAL)
$ conda info
Current conda install:

               platform : osx-64
          conda version : 4.2.9
       conda is private : False
      conda-env version : 4.2.9
    conda-build version : 2.0.2
         python version : 3.5.2.final.0
       requests version : 2.11.1
       root environment : /Users/takahiro/.pyenv/versions/anaconda3-4.2.0  (writable)
    default environment : /Users/takahiro/.pyenv/versions/anaconda3-4.2.0
       envs directories : /Users/takahiro/.pyenv/versions/anaconda3-4.2.0/envs
          package cache : /Users/takahiro/.pyenv/versions/anaconda3-4.2.0/pkgs
           channel URLs : https://repo.continuum.io/pkgs/free/osx-64/
                          https://repo.continuum.io/pkgs/free/noarch/
                          https://repo.continuum.io/pkgs/pro/osx-64/
                          https://repo.continuum.io/pkgs/pro/noarch/
            config file : None
           offline mode : False
$ conda list | grep pandas
pandas                    0.18.1              np111py35_0

Installation de Tensorflow

$ conda list | grep tensorflow
$ conda install -c conda-forge tensorflow
$ python
Python 3.5.2 |Anaconda 4.2.0 (x86_64)| (default, Jul  2 2016, 17:52:12)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow as tf
>>> node1 = tf.constant(3.0, tf.float32)
>>> node2 = tf.constant(4.0) # also tf.float32 implicitly
>>> print(node1, node2)
Tensor("Const:0", shape=(), dtype=float32) Tensor("Const_1:0", shape=(), dtype=float32)

>>> sess = tf.Session()
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
>>> print(sess.run([node1, node2]))
[3.0, 4.0]

Changer l'environnement pour chaque dossier de travail

Comment installer une autre version avec pyenv et utiliser pyenv local

$ pyenv install -l | grep anaconda2
  anaconda2-2.4.0
  anaconda2-2.4.1
  anaconda2-2.5.0
  anaconda2-4.0.0
  anaconda2-4.1.0
  anaconda2-4.1.1
  anaconda2-4.2.0
$ pyenv install anaconda2-4.2.0
$ pyenv versions
  system
  anaconda2-4.2.0
* anaconda3-4.2.0 (set by PYENV_VERSION environment variable)
$ mkdir py2 
$ cd py2
$ pyenv local anaconda2-4.2.0
$ pyenv version
anaconda2-4.2.0 (set by /Users/takahiro/workspace/py2/.python-version)
$ python -V
Python 2.7.12 :: Anaconda 4.2.0 (x86_64)

Comment créer un environnement virtuel pour conda et utiliser pyenv local

$ conda create -n tensorflow
$ conda info -e
# conda environments:
#
tensorflow               /Users/takahiro/.pyenv/versions/anaconda3-4.2.0/envs/tensorflow
root                  *  /Users/takahiro/.pyenv/versions/anaconda3-4.2.0
$ pyenv versions
  system
  anaconda2-4.2.0
* anaconda3-4.2.0 (set by /Users/takahiro/.pyenv/version)
  anaconda3-4.2.0/envs/tensorflow
$ mkdir tensorflow
$ cd tensorflow
$ pyenv local anaconda3-4.2.0/envs/tensorflow
$ pyenv version
anaconda3-4.2.0/envs/tensorflow (set by /Users/takahiro/workspace/tensorflow/.python-version)

Recommended Posts

Construction d'environnement Python (pyenv, anaconda, tensorflow)
Construction de l'environnement Python + Anaconda + Pycharm
Procédure de construction de l'environnement python Anaconda3
Construction d'environnement Python et TensorFlow
Construction de l'environnement Python3 TensorFlow (Mac et pyenv virtualenv)
Construction de l'environnement Anaconda Python sous Windows 10
Construction d'environnement (python)
installer tensorflow dans un environnement anaconda + python3.5
Construction d'environnement Python (pyenv + poetry + pipx)
construction d'environnement python
Python - Construction de l'environnement
pyenv + anaconda + python3
[Python] Construction de l'environnement Django (pyenv + pyenv-virtualenv + Anaconda) pour macOS
Construction de l'environnement Python
Construction de l'environnement Python3 TensorFlow pour Mac
Construction de l'environnement Python3.6 (à l'aide de l'environnement Win Anaconda)
Construction de l'environnement Python sur Mac (pyenv, virtualenv, anaconda, notebook ipython)
[Ubuntu 18.04] Créer un environnement Python avec pyenv + pipenv
Procédure de construction de l'environnement de développement Python (anaconda) (SpringToolsSuites) _2020.4
Construction de l'environnement de développement Python
construction de l'environnement pyenv + fish
Construction de l'environnement de développement python2.7
Mémo de construction de l'environnement Anaconda
Construction de l'environnement Python @ Win7
Construction de l'environnement Python (Anaconda + VSCode) @ Windows10 [version janvier 2020]
Construire un environnement Anaconda pour Python avec pyenv
Construction de l'environnement Python 3.x par Pyenv (CentOS, Ubuntu)
De la construction d'environnement Python à la construction d'environnement virtuel avec anaconda
[Ubuntu 18.04] Construction de l'environnement Tensorflow 2.0.0-GPU
Utiliser Anaconda dans un environnement pyenv
Installer l'environnement Python avec Anaconda
Construction de l'environnement Anaconda sur CentOS7
Introduction de Tensorflow (environnement Win / Anaconda)
Construction de l'environnement Python (Windows10 + Emacs)
Construction de l'environnement CI ~ Édition Python ~
Construction de l'environnement Python pour Mac
Anaconda3 × Mémo de construction de l'environnement Pycharm
Construction de l'environnement Python3 (pour les débutants)
Construire un environnement Python sous un environnement Windows 7
[MEMO] [Construction de l'environnement de développement] Python
Construction de l'environnement Ubuntu14.04 + GPU + TensorFlow
[Tensorflow] Construction de l'environnement Tensorflow sous Windows 10
[Python] Anaconda, pyenv, virtualenv, .bash_profile
Construction de l'environnement de python2 & 3 (OSX)
Construire un environnement Python avec pyenv, pyenv-virtualenv, Anaconda (Miniconda)
[Construction de l'environnement] @anaconda qui exécute keras / tensorflow sur GPU
Mémo de construction de l'environnement Python sur Windows 10
Commencez avec Python! ~ ① Construction de l'environnement ~
Construction d'un environnement d'apprentissage amélioré Python + Unity
Construction de l'environnement Anaconda sur Mac (version 2018)
J'ai vérifié la construction de l'environnement Mac Python
[Python3] Construction de l'environnement de développement << Édition Windows >>
Construction de l'environnement de développement Python sur macOS
Construire un environnement pour python3.8 sur Mac
Construction de l'environnement Python3 avec pyenv-virtualenv (CentOS 7.3)