如何使用conda安装pytorch和fastai

时间:2018-10-08 22:25:38

标签: python deep-learning conda pytorch

我创建了conda环境,并按如下所示安装pytorch和fastai(Mac OS Mojave):

conda create -n fai_course python=3.7
source activate fai_course
conda install -c pytorch pytorch-nightly-cpu
conda install -c fastai torchvision-nightly-cpu 
jupyter notebook

当我从jupyter笔记本中导入软件包时,出现OSError,如下所示:

from fastai.imports import *

-

--------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/font_manager.py in <module>
   1352         try:
-> 1353             fontManager = json_load(_fmcache)
   1354             if (not hasattr(fontManager, '_version') or

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/font_manager.py in json_load(filename)
    887     """
--> 888     with open(filename, 'r') as fh:
    889         return json.load(fh, object_hook=_json_decode)

FileNotFoundError: [Errno 2] No such file or directory: '/Users/user/.matplotlib/fontlist-v300.json'

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
<ipython-input-5-9f9378ae0f2a> in <module>
----> 1 from fastai.imports import *

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/fastai/__init__.py in <module>
----> 1 from .basic_train import *
      2 from .callback import *
      3 from .callbacks import *
      4 from .core import *
      5 from .data import *

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/fastai/basic_train.py in <module>
      1 "Provides basic training and validation with `Learner`"
----> 2 from .torch_core import *
      3 from .data import *
      4 from .callback import *
      5 

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/fastai/torch_core.py in <module>
      1 "Utility functions to help deal with tensors"
----> 2 from .imports.torch import *
      3 from .core import *
      4 
      5 AffineMatrix = Tensor

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/fastai/imports/__init__.py in <module>
----> 1 from .core import *
      2 from .torch import *

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/fastai/imports/core.py in <module>
      1 import csv, gc, gzip, os, pickle, shutil, sys, warnings
----> 2 import math, matplotlib.pyplot as plt, numpy as np, pandas as pd, random
      3 import scipy.stats, scipy.special
      4 import abc, collections, hashlib, itertools, json, operator
      5 import mimetypes, inspect, typing, functools

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/pyplot.py in <module>
     30 from cycler import cycler
     31 import matplotlib
---> 32 import matplotlib.colorbar
     33 import matplotlib.image
     34 from matplotlib import rcsetup, style

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/colorbar.py in <module>
     30 import matplotlib.collections as collections
     31 import matplotlib.colors as colors
---> 32 import matplotlib.contour as contour
     33 import matplotlib.cm as cm
     34 import matplotlib.gridspec as gridspec

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/contour.py in <module>
     16 import matplotlib.colors as mcolors
     17 import matplotlib.collections as mcoll
---> 18 import matplotlib.font_manager as font_manager
     19 import matplotlib.text as text
     20 import matplotlib.cbook as cbook

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/font_manager.py in <module>
   1361             raise
   1362         except Exception:
-> 1363             _rebuild()
   1364     else:
   1365         _rebuild()

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/font_manager.py in _rebuild()
   1342         global fontManager
   1343 
-> 1344         fontManager = FontManager()
   1345 
   1346         if _fmcache:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/font_manager.py in __init__(self, size, weight)
    976         self.defaultFont = {}
    977 
--> 978         ttffiles = findSystemFonts(paths) + findSystemFonts()
    979         self.defaultFont['ttf'] = next(
    980             (fname for fname in ttffiles

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/font_manager.py in findSystemFonts(fontpaths, fontext)
    268             # check for OS X & load its fonts if present
    269             if sys.platform == 'darwin':
--> 270                 fontfiles.update(OSXInstalledFonts(fontext=fontext))
    271 
    272     elif isinstance(fontpaths, str):

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/font_manager.py in OSXInstalledFonts(directories, fontext)
    216         directories = OSXFontDirectories
    217     return [path
--> 218             for directory in directories
    219             for ext in get_fontext_synonyms(fontext)
    220             for path in list_fonts(directory, ext)]

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/font_manager.py in <listcomp>(.0)
    218             for directory in directories
    219             for ext in get_fontext_synonyms(fontext)
--> 220             for path in list_fonts(directory, ext)]
    221 
    222 

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/font_manager.py in list_fonts(directory, extensions)
    155     extensions = ["." + ext for ext in extensions]
    156     return [str(path)
--> 157             for path in filter(Path.is_file, Path(directory).glob("**/*.*"))
    158             if path.suffix in extensions]
    159 

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/font_manager.py in <listcomp>(.0)
    154     """
    155     extensions = ["." + ext for ext in extensions]
--> 156     return [str(path)
    157             for path in filter(Path.is_file, Path(directory).glob("**/*.*"))
    158             if path.suffix in extensions]

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py in glob(self, pattern)
   1080             raise NotImplementedError("Non-relative patterns are unsupported")
   1081         selector = _make_selector(tuple(pattern_parts))
-> 1082         for p in selector.select_from(self):
   1083             yield p
   1084 

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py in _select_from(self, parent_path, is_dir, exists, scandir)
    541             try:
    542                 successor_select = self.successor._select_from
--> 543                 for starting_point in self._iterate_directories(parent_path, is_dir, scandir):
    544                     for p in successor_select(starting_point, is_dir, exists, scandir):
    545                         if p not in yielded:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py in _iterate_directories(self, parent_path, is_dir, scandir)
    531                 if entry.is_dir() and not entry.is_symlink():
    532                     path = parent_path._make_child_relpath(entry.name)
--> 533                     for p in self._iterate_directories(path, is_dir, scandir):
    534                         yield p
    535         except PermissionError:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py in _iterate_directories(self, parent_path, is_dir, scandir)
    531                 if entry.is_dir() and not entry.is_symlink():
    532                     path = parent_path._make_child_relpath(entry.name)
--> 533                     for p in self._iterate_directories(path, is_dir, scandir):
    534                         yield p
    535         except PermissionError:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py in _iterate_directories(self, parent_path, is_dir, scandir)
    531                 if entry.is_dir() and not entry.is_symlink():
    532                     path = parent_path._make_child_relpath(entry.name)
--> 533                     for p in self._iterate_directories(path, is_dir, scandir):
    534                         yield p
    535         except PermissionError:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py in _iterate_directories(self, parent_path, is_dir, scandir)
    531                 if entry.is_dir() and not entry.is_symlink():
    532                     path = parent_path._make_child_relpath(entry.name)
--> 533                     for p in self._iterate_directories(path, is_dir, scandir):
    534                         yield p
    535         except PermissionError:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py in _iterate_directories(self, parent_path, is_dir, scandir)
    531                 if entry.is_dir() and not entry.is_symlink():
    532                     path = parent_path._make_child_relpath(entry.name)
--> 533                     for p in self._iterate_directories(path, is_dir, scandir):
    534                         yield p
    535         except PermissionError:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py in _iterate_directories(self, parent_path, is_dir, scandir)
    531                 if entry.is_dir() and not entry.is_symlink():
    532                     path = parent_path._make_child_relpath(entry.name)
--> 533                     for p in self._iterate_directories(path, is_dir, scandir):
    534                         yield p
    535         except PermissionError:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py in _iterate_directories(self, parent_path, is_dir, scandir)
    531                 if entry.is_dir() and not entry.is_symlink():
    532                     path = parent_path._make_child_relpath(entry.name)
--> 533                     for p in self._iterate_directories(path, is_dir, scandir):
    534                         yield p
    535         except PermissionError:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py in _iterate_directories(self, parent_path, is_dir, scandir)
    529             entries = list(scandir(parent_path))
    530             for entry in entries:
--> 531                 if entry.is_dir() and not entry.is_symlink():
    532                     path = parent_path._make_child_relpath(entry.name)
    533                     for p in self._iterate_directories(path, is_dir, scandir):

OSError: [Errno 62] Too many levels of symbolic links: '.Trash/NETGEARGenie.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/5'

可以让我知道我在想什么吗? 谢谢

2 个答案:

答案 0 :(得分:0)

诚然,该错误非常令人困惑。但是,查看库路径:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7 /

我猜您不是使用通过conda安装的Jupyter,而是使用另一种本地安装。

尝试检查您正在使用哪个Jupyter:

    which jupyter

这应该类似于:

〜/ anaconda3 / bin / jupyter

如果不是,则说明您使用的是另一种jupyter安装,但似乎未安装这些库。

答案 1 :(得分:0)

如果您访问fastai github存储库,则会看到以下内容:“ NB:fastai v1当前仅支持Linux,并且需要PyTorch v1和Python 3.6 ...

因此,您至少可以尝试使用Python 3.6创建环境

或者像Python 3.7一样开始做,就像这篇文章一样:https://medium.com/@plape/how-to-install-fastai-on-mac-a05496670926

使用

conda install -c pytorch -c fastai fastai jupyter

代替

conda install -c pytorch pytorch-nightly-cpu conda install -c fastai torchvision-nightly-cpu

希望这会有所帮助。