MAC系统机器学习环境配置常见问题

MAC系统机器学习环境配置常见问题

  • 1. zsh: command not found: conda
  • 2. conda安装软件包提示:EnvironmentNotWritableError
  • 3. 安装pip失败的解决办法
  • 4. cannot import name 'imresize' from 'scipy.misc'
  • 5. anaconda 中matplotlib中文字体问题

自从换了Apple M1后,配置机器学习环境的过程中经常遇到各种问题,在此一并记录,会持续更新,希望大家收藏点赞。

系统环境: macOS BigSur v11.2.2

1. zsh: command not found: conda

问题

安装anaconda后,在终端输入conda后,显示

zsh: command not found: conda

原因

未配置环境路径

解决方法

  • 切换到超级用户
sudo su
  • 编辑.zprofile(在/Users/mac系统的用户名文件夹下,Mac OS Catalina版本需要编辑.zshrc)
vi .zprofile 
  • 加入以下代码
export PATH=/opt/anaconda3/bin:$PATH
  • 保存后退出,执行
source .zprofile 
  • 关闭Terminal,重新打开Terminal,输入
conda --version

确认配置成功。

2. conda安装软件包提示:EnvironmentNotWritableError

问题

使用conda 安装包时提示

EnvironmentNotWritableError

原因

用户权限不足

解决方法

  • Windows下Mac以管理员身份打开Anaconda Prompt (Anaconda3)
  • Mac下sudo su切换为超级管理员

3. 安装pip失败的解决办法

问题

在终端输入以下安装命令后

sudo easy_install pip

报错如下:
在这里插入图片描述
原因

Mac系统自带的为Python2,需手动安装Python3。

解决方法

  • 使用homebrew安装python3
brew install python3
  • 再次安装pip
sudo easy_install pip
  • 关闭Terminal,重新打开Terminal,输入
pip -V

确认配置成功。

4. cannot import name ‘imresize’ from ‘scipy.misc’

问题

执行

from scipy.misc import imread, imresize

报错如下:

cannot import name 'imresize' from 'scipy.misc'

原因

scipy版本问题:scipy是1.3.0以上不再支持函数imreadimresize

官网解释如下:

imresize is deprecated! imresize is deprecated in SciPy 1.0.0, and will be removed in 1.3.0. Use Pillow instead: numpy.array(Image.fromarray(arr).resize()).

解决方法

使用PILimageio库解决。

将原代码

from scipy.misc import imread, imresize
img1 = imread('test.png', mode='RGB')
img1 = imresize(img1, (224, 224))

替换如下

from PIL import Image
from imageio import imread
img1 = imread('test.jpg', pilmode='RGB')
img1 = np.array(Image.fromarray(img1).resize((224, 224)))

5. anaconda 中matplotlib中文字体问题

问题
matplotlib画图,中文字体乱码。
MAC系统机器学习环境配置常见问题_第1张图片
原因

Mac系统下中文字体与Windows不同。

解决方法

使用Mac下的中文字体:

plt.rcParams['font.sans-serif'] = ['Arial Unicode MS'] 

你可能感兴趣的:(#,Mac使用手记,万花筒,macos,机器学习,conda,pip)