【问题标题】:How to install fastai on Mac m1如何在 Mac m1 上安装 fastai
【发布时间】:2022-08-02 17:56:33
【问题描述】:

我正在尝试在我的新 Mac m1 上安装 fastai(版本 1.0.61)。

我第一次尝试:

pip install fastai==1.0.61

这给了我一个我没有cmake的错误,所以我用brew install cmake成功安装了cmake。

然后,重新运行 fastai install 命令,我收到此错误:

Collecting fastai==1.0.61
  Using cached fastai-1.0.61-py3-none-any.whl (239 kB)
Collecting fastprogress>=0.2.1
  Using cached fastprogress-1.0.2-py3-none-any.whl (12 kB)
Collecting numexpr
  Using cached numexpr-2.8.1-cp310-cp310-macosx_11_0_arm64.whl
Collecting scipy
  Using cached scipy-1.8.0-cp310-cp310-macosx_12_0_arm64.whl (28.7 MB)
Collecting pyyaml
  Using cached PyYAML-6.0-cp310-cp310-macosx_11_0_arm64.whl (173 kB)
Collecting bottleneck
  Using cached Bottleneck-1.3.4-cp310-cp310-macosx_11_0_arm64.whl
Collecting matplotlib
  Using cached matplotlib-3.5.1-cp310-cp310-macosx_11_0_arm64.whl (7.2 MB)
Collecting pynvx>=1.0.0
  Using cached pynvx-1.0.0.tar.gz (150 kB)
  Preparing metadata (setup.py) ... done
Collecting beautifulsoup4
  Using cached beautifulsoup4-4.11.1-py3-none-any.whl (128 kB)
Collecting nvidia-ml-py3
  Using cached nvidia_ml_py3-7.352.0-py3-none-any.whl
Requirement already satisfied: requests in /Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages (from fastai==1.0.61) (2.27.1)
Requirement already satisfied: Pillow in /Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages (from fastai==1.0.61) (9.1.0)
Requirement already satisfied: pandas in /Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages (from fastai==1.0.61) (1.4.2)
Collecting packaging
  Using cached packaging-21.3-py3-none-any.whl (40 kB)
Requirement already satisfied: torch>=1.0.0 in /Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages (from fastai==1.0.61) (1.11.0)
Requirement already satisfied: torchvision in /Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages (from fastai==1.0.61) (0.12.0)
Requirement already satisfied: numpy>=1.15 in /Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages (from fastai==1.0.61) (1.22.3)
Requirement already satisfied: typing-extensions in /Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages (from torch>=1.0.0->fastai==1.0.61) (4.2.0)
Collecting soupsieve>1.2
  Using cached soupsieve-2.3.2.post1-py3-none-any.whl (37 kB)
Collecting pyparsing>=2.2.1
  Using cached pyparsing-3.0.8-py3-none-any.whl (98 kB)
Collecting kiwisolver>=1.0.1
  Using cached kiwisolver-1.4.2-cp310-cp310-macosx_11_0_arm64.whl (63 kB)
Requirement already satisfied: python-dateutil>=2.7 in /Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages (from matplotlib->fastai==1.0.61) (2.8.2)
Collecting cycler>=0.10
  Using cached cycler-0.11.0-py3-none-any.whl (6.4 kB)
Collecting fonttools>=4.22.0
  Using cached fonttools-4.33.3-py3-none-any.whl (930 kB)
Requirement already satisfied: pytz>=2020.1 in /Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages (from pandas->fastai==1.0.61) (2022.1)
Requirement already satisfied: certifi>=2017.4.17 in /Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages (from requests->fastai==1.0.61) (2021.10.8)
Requirement already satisfied: idna<4,>=2.5 in /Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages (from requests->fastai==1.0.61) (3.3)
Requirement already satisfied: charset-normalizer~=2.0.0 in /Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages (from requests->fastai==1.0.61) (2.0.12)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages (from requests->fastai==1.0.61) (1.26.9)
Requirement already satisfied: six>=1.5 in /Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib->fastai==1.0.61) (1.16.0)
Building wheels for collected packages: pynvx
  Building wheel for pynvx (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [78 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-11.0-arm64-cpython-310
      creating build/lib.macosx-11.0-arm64-cpython-310/pynvx
      copying pynvx/pynvml.py -> build/lib.macosx-11.0-arm64-cpython-310/pynvx
      copying pynvx/__init__.py -> build/lib.macosx-11.0-arm64-cpython-310/pynvx
      running build_ext
      -- The C compiler identification is AppleClang 13.1.6.13160021
      -- The CXX compiler identification is AppleClang 13.1.6.13160021
      -- Detecting C compiler ABI info
      -- Detecting C compiler ABI info - done
      -- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
      -- Detecting C compile features
      -- Detecting C compile features - done
      -- Detecting CXX compiler ABI info
      -- Detecting CXX compiler ABI info - done
      -- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
      -- Detecting CXX compile features
      -- Detecting CXX compile features - done
      -- Found PythonInterp: /Users/connoreaton/miniforge3/envs/spaff_nlp/bin/python3.10 (found version \"3.10.4\")
      -- Found PythonLibs: /Users/connoreaton/miniforge3/envs/spaff_nlp/lib/libpython3.10.dylib
      -- Performing Test HAS_CPP14_FLAG
      -- Performing Test HAS_CPP14_FLAG - Success
      -- pybind11 v2.3.dev0
      -- Performing Test HAS_FLTO
      -- Performing Test HAS_FLTO - Success
      -- LTO enabled
      CMake Error at /opt/homebrew/Cellar/cmake/3.23.1/share/cmake/Modules/FindCUDA.cmake:859 (message):
        Specify CUDA_TOOLKIT_ROOT_DIR
      Call Stack (most recent call first):
        CMakeLists.txt:8 (find_package)
      
      
      -- Configuring incomplete, errors occurred!
      See also \"/private/var/folders/fn/lgvtrxd90cl3nqryfdfcsld80000gn/T/pip-install-81yvkyvs/pynvx_19ff0317a3854976bb7ea683521d385f/build/temp.macosx-11.0-arm64-cpython-310/CMakeFiles/CMakeOutput.log\".
      See also \"/private/var/folders/fn/lgvtrxd90cl3nqryfdfcsld80000gn/T/pip-install-81yvkyvs/pynvx_19ff0317a3854976bb7ea683521d385f/build/temp.macosx-11.0-arm64-cpython-310/CMakeFiles/CMakeError.log\".
      Traceback (most recent call last):
        File \"<string>\", line 2, in <module>
        File \"<pip-setuptools-caller>\", line 34, in <module>
        File \"/private/var/folders/fn/lgvtrxd90cl3nqryfdfcsld80000gn/T/pip-install-81yvkyvs/pynvx_19ff0317a3854976bb7ea683521d385f/setup.py\", line 68, in <module>
          setup(
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/__init__.py\", line 87, in setup
          return distutils.core.setup(**attrs)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/core.py\", line 148, in setup
          return run_commands(dist)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/core.py\", line 163, in run_commands
          dist.run_commands()
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/dist.py\", line 967, in run_commands
          self.run_command(cmd)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/dist.py\", line 1214, in run_command
          super().run_command(command)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/dist.py\", line 986, in run_command
          cmd_obj.run()
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/wheel/bdist_wheel.py\", line 299, in run
          self.run_command(\'build\')
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/cmd.py\", line 313, in run_command
          self.distribution.run_command(command)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/dist.py\", line 1214, in run_command
          super().run_command(command)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/dist.py\", line 986, in run_command
          cmd_obj.run()
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/command/build.py\", line 136, in run
          self.run_command(cmd_name)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/cmd.py\", line 313, in run_command
          self.distribution.run_command(command)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/dist.py\", line 1214, in run_command
          super().run_command(command)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/dist.py\", line 986, in run_command
          cmd_obj.run()
        File \"/private/var/folders/fn/lgvtrxd90cl3nqryfdfcsld80000gn/T/pip-install-81yvkyvs/pynvx_19ff0317a3854976bb7ea683521d385f/setup.py\", line 32, in run
          self.build_extension(ext)
        File \"/private/var/folders/fn/lgvtrxd90cl3nqryfdfcsld80000gn/T/pip-install-81yvkyvs/pynvx_19ff0317a3854976bb7ea683521d385f/setup.py\", line 56, in build_extension
          subprocess.check_call([\'cmake\', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/subprocess.py\", line 369, in check_call
          raise CalledProcessError(retcode, cmd)
      subprocess.CalledProcessError: Command \'[\'cmake\', \'/private/var/folders/fn/lgvtrxd90cl3nqryfdfcsld80000gn/T/pip-install-81yvkyvs/pynvx_19ff0317a3854976bb7ea683521d385f\', \'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/private/var/folders/fn/lgvtrxd90cl3nqryfdfcsld80000gn/T/pip-install-81yvkyvs/pynvx_19ff0317a3854976bb7ea683521d385f/build/lib.macosx-11.0-arm64-cpython-310\', \'-DPYTHON_EXECUTABLE=/Users/connoreaton/miniforge3/envs/spaff_nlp/bin/python3.10\', \'-DCMAKE_BUILD_TYPE=Release\']\' returned non-zero exit status 1.
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pynvx
  Running setup.py clean for pynvx
Failed to build pynvx
Installing collected packages: pynvx, nvidia-ml-py3, soupsieve, scipy, pyyaml, pyparsing, kiwisolver, fonttools, fastprogress, cycler, bottleneck, packaging, beautifulsoup4, numexpr, matplotlib, fastai
  Running setup.py install for pynvx ... error
  error: subprocess-exited-with-error
  
  × Running setup.py install for pynvx did not run successfully.
  │ exit code: 1
  ╰─> [82 lines of output]
      running install
      /Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_py
      creating build
      creating build/lib.macosx-11.0-arm64-cpython-310
      creating build/lib.macosx-11.0-arm64-cpython-310/pynvx
      copying pynvx/pynvml.py -> build/lib.macosx-11.0-arm64-cpython-310/pynvx
      copying pynvx/__init__.py -> build/lib.macosx-11.0-arm64-cpython-310/pynvx
      running build_ext
      -- The C compiler identification is AppleClang 13.1.6.13160021
      -- The CXX compiler identification is AppleClang 13.1.6.13160021
      -- Detecting C compiler ABI info
      -- Detecting C compiler ABI info - done
      -- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
      -- Detecting C compile features
      -- Detecting C compile features - done
      -- Detecting CXX compiler ABI info
      -- Detecting CXX compiler ABI info - done
      -- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
      -- Detecting CXX compile features
      -- Detecting CXX compile features - done
      -- Found PythonInterp: /Users/connoreaton/miniforge3/envs/spaff_nlp/bin/python3.10 (found version \"3.10.4\")
      -- Found PythonLibs: /Users/connoreaton/miniforge3/envs/spaff_nlp/lib/libpython3.10.dylib
      -- Performing Test HAS_CPP14_FLAG
      -- Performing Test HAS_CPP14_FLAG - Success
      -- pybind11 v2.3.dev0
      -- Performing Test HAS_FLTO
      -- Performing Test HAS_FLTO - Success
      -- LTO enabled
      CMake Error at /opt/homebrew/Cellar/cmake/3.23.1/share/cmake/Modules/FindCUDA.cmake:859 (message):
        Specify CUDA_TOOLKIT_ROOT_DIR
      Call Stack (most recent call first):
        CMakeLists.txt:8 (find_package)
      
      
      -- Configuring incomplete, errors occurred!
      See also \"/private/var/folders/fn/lgvtrxd90cl3nqryfdfcsld80000gn/T/pip-install-81yvkyvs/pynvx_19ff0317a3854976bb7ea683521d385f/build/temp.macosx-11.0-arm64-cpython-310/CMakeFiles/CMakeOutput.log\".
      See also \"/private/var/folders/fn/lgvtrxd90cl3nqryfdfcsld80000gn/T/pip-install-81yvkyvs/pynvx_19ff0317a3854976bb7ea683521d385f/build/temp.macosx-11.0-arm64-cpython-310/CMakeFiles/CMakeError.log\".
      Traceback (most recent call last):
        File \"<string>\", line 2, in <module>
        File \"<pip-setuptools-caller>\", line 34, in <module>
        File \"/private/var/folders/fn/lgvtrxd90cl3nqryfdfcsld80000gn/T/pip-install-81yvkyvs/pynvx_19ff0317a3854976bb7ea683521d385f/setup.py\", line 68, in <module>
          setup(
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/__init__.py\", line 87, in setup
          return distutils.core.setup(**attrs)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/core.py\", line 148, in setup
          return run_commands(dist)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/core.py\", line 163, in run_commands
          dist.run_commands()
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/dist.py\", line 967, in run_commands
          self.run_command(cmd)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/dist.py\", line 1214, in run_command
          super().run_command(command)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/dist.py\", line 986, in run_command
          cmd_obj.run()
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/command/install.py\", line 68, in run
          return orig.install.run(self)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/command/install.py\", line 670, in run
          self.run_command(\'build\')
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/cmd.py\", line 313, in run_command
          self.distribution.run_command(command)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/dist.py\", line 1214, in run_command
          super().run_command(command)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/dist.py\", line 986, in run_command
          cmd_obj.run()
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/command/build.py\", line 136, in run
          self.run_command(cmd_name)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/cmd.py\", line 313, in run_command
          self.distribution.run_command(command)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/dist.py\", line 1214, in run_command
          super().run_command(command)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/site-packages/setuptools/_distutils/dist.py\", line 986, in run_command
          cmd_obj.run()
        File \"/private/var/folders/fn/lgvtrxd90cl3nqryfdfcsld80000gn/T/pip-install-81yvkyvs/pynvx_19ff0317a3854976bb7ea683521d385f/setup.py\", line 32, in run
          self.build_extension(ext)
        File \"/private/var/folders/fn/lgvtrxd90cl3nqryfdfcsld80000gn/T/pip-install-81yvkyvs/pynvx_19ff0317a3854976bb7ea683521d385f/setup.py\", line 56, in build_extension
          subprocess.check_call([\'cmake\', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
        File \"/Users/connoreaton/miniforge3/envs/spaff_nlp/lib/python3.10/subprocess.py\", line 369, in check_call
          raise CalledProcessError(retcode, cmd)
      subprocess.CalledProcessError: Command \'[\'cmake\', \'/private/var/folders/fn/lgvtrxd90cl3nqryfdfcsld80000gn/T/pip-install-81yvkyvs/pynvx_19ff0317a3854976bb7ea683521d385f\', \'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/private/var/folders/fn/lgvtrxd90cl3nqryfdfcsld80000gn/T/pip-install-81yvkyvs/pynvx_19ff0317a3854976bb7ea683521d385f/build/lib.macosx-11.0-arm64-cpython-310\', \'-DPYTHON_EXECUTABLE=/Users/connoreaton/miniforge3/envs/spaff_nlp/bin/python3.10\', \'-DCMAKE_BUILD_TYPE=Release\']\' returned non-zero exit status 1.
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> pynvx

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

我显然无法安装pynvx。这是有道理的,因为pynvx 处理 CUDA,显然 Mac M1 无法支持。我在这里尝试了来自 fastai 的仅 CPU 构建安装文档:

https://fastai1.fast.ai/install.html

但我得到同样的错误。

我能做些什么?如果我不能在本地训练模型也没关系,但我希望至少能够加载模型并使用它们进行预测。

    标签: python macos deep-learning pytorch fast-ai


    【解决方案1】:

    fastai 似乎需要pyenv 这需要 CUDA 才能工作。 CUDA 仅在 Nvidia GPU 上可用,MAC M1 具有完全不同的 SOC,没有 Nvidia GPU

    您可以阅读实际错误

    CMake Error at /opt/homebrew/Cellar/cmake/3.23.1/share/cmake/Modules/FindCUDA.cmake:859
    

    【讨论】:

    • 那么在 Mac m1 上不能使用 fastai 吗?
    • @connor449 我不知道你的项目是否需要pyenv,但如果你不需要,你可以安装fastai,并且只需要手动使用pip install --no-deps fastai==1.0.61 的依赖项。如果您需要pyenv,则无法在 M1 Mac 上安装它
    • forums.fast.ai/t/fastai-on-apple-m1/86059讨论你可以使用cpu进行训练可能有帮助....
    【解决方案2】:

    我可以在第一章中获得第一个训练示例,以便在我的 mac mini 上使用 M1。我正在使用 Ventura(测试版),但我认为这并不重要。最新的 Xcode 可以。我已经尝试过很多次但都失败了,如果你也有的话,看到它实际播放真的很有趣,即使只是一点点。但我可以使用一些帮助将它哄得更远。

    我制作了一个 bash 脚本,它创建了一个 miniconda 环境并安装了在 macOS 上的 jupyter notebook 中运行 fastai 所需的一切。我是 conda 和 python 和 fastai 的新手,所以可能有更好的方法来做到这一点,但它对我有用并且是可重现的。

    我们需要下载 fastbook,但在撰写本文时,我们还需要一些前沿的夜间源代码构建来完成这项工作。所以创建一个空目录并 cd 进入它。然后运行这个脚本,给它一个你希望它创建的新虚拟环境的名称。安装所有东西需要几分钟,如果运气好的话,可能会没有错误地完成。而已。

    Conda 激活环境,然后运行 ​​jupyter notebook。从那里导航到 fastbook / clean / 01_intro。

    您将需要编辑任何 DataLoader 以添加显式的“num_workers=0”参数。所以第一个笔记本看起来像:

    # CLICK ME
    from fastai.vision.all import *
    path = untar_data(URLs.PETS)/'images'
    
    def is_cat(x): return x[0].isupper()
    dls = ImageDataLoaders.from_name_func(
        path, get_image_files(path), valid_pct=0.2, seed=42,
        label_func=is_cat, item_tfms=Resize(224), num_workers=0)
    
    learn = vision_learner(dls, resnet34, metrics=error_rate)
    learn.fine_tune(1)
    

    运行时,第一个示例通常会显示弃用警告(将其更改为“arch=resnet34”而不仅仅是“resnet34”可能会修复它)。但不管是否警告,它都会运行:进度条很快出现,任务在大约五分钟内完成(对我来说)。

    这是我创建或更新环境的脚本。

    #!/usr/bin/env bash
    
    set -e
    
    # Apple's recommendation.  Untested with homebrew's miniconda.
    #    https://developer.apple.com/metal/tensorflow-plugin/
    CONDA=miniforge3
    
    # the location of the environments directories
    ENVS=${HOME}/${CONDA}/envs
    
    if [ 1 -ne $# ]; then cat << EOT
    Usage: $0 <name>
        Create conda (${CONDA}) virtual environment <name> with
        python 3.9 and fastai development native to MacOS M1.
    EOT
        exit 0
    fi
    
    if [ -d ${ENVS}/$1 ]; then
        printf "$1 already exists.  Delete the environment completely and re-install everything clean? (y/N): "
        read reply
        if [ "$reply" = "y" ] || [ "$reply" = "Y" ]; then 
            conda remove  -y -n "$1" --all
            if [ -d fastai ]; then
                if [ ! -d bk ]; then mkdir bk; fi
                # we'll save one backup just in case
                mv -f fastai fastbook fastcore nbdev bk/ 
            fi  
        else
            printf "Continue installation? (y/N): "
            read reply
            if [ "$reply" != "y" ] && [ "$reply" != "Y" ]; then
                echo "no change"
                exit 1
            fi  
        fi  
    fi
    
    if [ ! -d ${ENVS}/$1 ]; then conda create -y -n $1 python=3.9; fi
    
    eval "$(conda shell.bash hook)"
    conda activate $1
    
    brew install -q graphviz
    
    conda config --env --add channels conda-forge
    conda install -y scipy matplotlib ipython scikit-learn pandas pillow qtconsole pylint mypy graphviz ipykernel ipywidgets nbconvert notebook jupyter
    
    # Apple's recommendation for updating from an older version
    python -m pip uninstall -q -y tensorflow-macos
    python -m pip uninstall -q -y tensorflow-metal
    # Upgrade tensorflow-deps
    conda install -y -c apple tensorflow-deps=2.9.0  # this must match tensorflow
    python -m pip install tensorflow-macos
    python -m pip install tensorflow-metal
    conda install -y pytorch torchvision -c pytorch-nightly
    
    # may need to: sudo dot -c
    conda install -y -c fastai fastdot
    
    if [ ! -d fastai ];     then git clone https://github.com/fastai/fastai; fi
    if [ ! -d fastbook ];   then git clone https://github.com/fastai/fastbook; fi
    if [ ! -d fastcore ];   then git clone https://github.com/fastai/fastcore.git; fi
    if [ ! -d nbdev ];      then git clone https://github.com/fastai/nbdev.git; fi
    
    echo "Use the latest fastai, fastcore, nbdev, and fastbook source"
    (cd fastai; git pull);      pip install -e fastai
    (cd fastcore; git pull);    pip install -e fastcore
    (cd nbdev; git pull);       pip install -e nbdev
    (cd fastbook; git pull);    pip install fastbook -U
    
    printf "# to activate the environment:\nconda activate $1\n"
    echo "conda activate $1" | pbcopy
    

    【讨论】:

      猜你喜欢
      • 2021-08-08
      • 1970-01-01
      • 2022-06-11
      • 1970-01-01
      • 2021-05-17
      • 2021-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多