Installing python development environment and tensorflow package on mac
There are various options for python‘s development environment. If you are a beginner who has never programmed before, anaconda is a good choice because it comes with many libraries pre-installed and is easy to use with IDEs such as Jupyter and InteriJ. However, as mentioned above, anaconda requires a large amount of memory (several GB) due to the pre-installation of many additional libraries, and recently (April 2020) there has been talk of charging for the use of package repositories (for entities under common control with 200 or more employees). So, if you want to use it as a part of your work, you need to consider other options.
As for python package management tools, there are pip and conda. conda can be installed from Anaconda’s repository, while pip can be installed from PyPI. anaconda is managed by a specific company, while pip is managed by PyPI (open). There are a lot of packages for pip, but I think there are many cases where they are used together.
In addition to anaconda, you can install python (the latest macs come with both 3 and 2 pre-installed. You can also use homebrew or download the installer from the pyhton official page), write your code using a text editor (Atom, NotePad++, Emacs, SublimeText, etc.), and install the package using pip or conda. If you want to use it like a REPL, Jupyter notebook is another option.
In the latest MAC (M1 silicon), some of the anaconda packages are not available, and if you use too high a version of python, you cannot use DNN packages such as tensorflow. For now, it is better to use python3.8, which is installed by default. For package management, it is recommended to use miniforge3 at this time.
The following is the installation procedure of miniforge3 and DNN packages such as tensflow. First, download and run the miniforge3 installation script.
-$ wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh
-$ bash Miniforge3-MacOSX-arm64.sh
If you enter “yes” or “enter” to all the questions on the way, the installation will be completed. If you close the terminal and reopen it. (base) will appear at the top of the command input. Next, launch an environment called python38 (name is optional) and activate it.
(base)..-$ conda create --name python38 python=3.8
(base)..-$ conda activate python38
Now that the environment setup is complete, we will start installing tensorflow and other packages. First, install the necessary packages in advance, and then run
(python38)..-$ conda install numpy
(python38)..-$ conda install six
(python38)..-$ conda install matplotlib
(python38)..-$ conda install opencv
Follow the steps below to install the tensorflow package.
$ wget https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha2/tensorflow_macos-0.1alpha2.tar.gz $ tar xvzf tensorflow_macos-0.1alpha2.tar.gz
$ env="$HOME/miniforge3/envs/python38"
$ libs="$PWD/tensorflow_macos/ar m64/"
$ pip install --upgrade -t "$env/lib/python3.8/site-packages/" --no-dependencies --force "$libs/grpcio-1.33.2-cp38-cp38-macosx_11_0_arm64.whl"
$ pip install --upgrade -t "$env/lib/python3.8/site-packages/" --no-dependencies --force "$libs/h5py-2.10.0-cp38-cp38-macosx_11_0_arm64.whl"
$ pip install --upgrade -t "$env/lib/python3.8/site-packages/" --no-dependencies --force "$libs/tensorflow_addons_macos-0.1a2-cp38-cp38-macosx_11_0_arm64.whl"
$ conda install -c conda-forge -y absl-py
$ conda install -c conda-forge -y astunparse
$ conda install -c conda-forge -y gast
$ conda install -c conda-forge -y opt_einsum
$ conda install -c conda-forge -y termcolor
$ conda install -c conda-forge -y typing_extensions
$ conda install -c conda-forge -y wheel
$ conda install -c conda-forge -y typeguard
$ pip install wrapt flatbuffers tensorflow_estimator google_pasta keras_preprocessing protobuf
$ pip install tensorboard
$ pip install --upgrade -t "$env/lib/python3.8/site-packages/" --no-dependencies --force "$libs/tensorflow_macos-0.1a2-cp38-cp38-macosx_11_0_arm64.whl"
To check if the package has been installed, do the following.
$ python3
Python 3.8.6 | packaged by conda-forge | (default, Jan 25 2021, 22:55:00)
[Clang 11.0.1 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__ '2.4.0-rc0'
If you need TF-Agents for reinforcement learning, etc., run the following command to install it.
-$ conda install bazel
-$ pip install tf_agents
If you want to install PyTorch, you can use pip to do so.
pip install torch
pip install torchvision
pip install torchaudio
By doing the above, we will be able to try DNNs.
These implimentation such as Keras is discussed in the Deep Learning with Python and Keras section below, and pytorch is discussed in the Evolving Deep Learning with PyTorch section.
コメント