macOS上运行python及配置相应环境

背景:我们希望在macOS上完成一些初级的数据处理及增扩,例如图像旋转,名称更改及写入文件夹等等这些基本操作。这些操作交互性交强,且需要看到实时的结果,没必要放在服务器上使流程更加复杂。因此直接运用macOS运行即可。

本文在于实现简单的数据增扩,还没有用到anaconda管理环境,如果需要用到anaconda管理环境的话,可以参考这篇:

macOS上PyCharm配置Anaconda环境

成果:安装完成,可实现一定的数据增扩。后续如果需要的环境我们就在这里安装,并且补充更新安装的方法。

目录

一、安装pycharm

二、安装pip

2.1 直接通过python安装

2.2 参考

2.3 安装后升级

三、安装依赖项

3.1 PIL

3.2 自带的安装好的安装包


一、安装pycharm

pycharm为目前最好的python IDE,无论从编辑程序的角度,还是看代码的角度,安装pycharm是十分必要的。并且pycharm自带python,直接装好在终端敲击命令行即可。

至于anaconda,如果仅仅是初级的数据处理以及批处理等等的操作,完全没必要在macOS装anaconda使问题复杂化。anaconda的长处在于管理显卡及其环境,对于初级的数据批处理并无太大帮助。

http://www.360doc.com/content/18/0324/07/34445812_739728933.shtml

安装后,macbook因为自带的python,在usr/bin文件夹内,如果是windows用户,还需要安装和配置相应的python环境,参考:

windows上配置pycharm与python环境并运行

MacBook-Pro:Desktop $ python
Python 2.7.10 (default, Aug 17 2018, 19:45:58)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

二、安装pip

2.1 直接通过python安装

python3以上版本默认安装pip,但是此版本内并没有安装。

pip可用于安装各种包

sudo python -m ensurepip --default-pip

2.2 参考(可不看)

https://packaging.python.org/tutorials/installing-packages/#ensure-you-can-run-python-from-the-command-line

Additionally, you’ll need to make sure you have pip available. You can check this by running:

pip --version

If you installed Python from source, with an installer from python.org, or via Homebrew you should already have pip. If you’re on Linux and installed using your OS package manager, you may have to install pip separately, see Installing pip/setuptools/wheel with Linux Package Managers.

If pip isn’t already installed, then first try to bootstrap it from the standard library:

python -m ensurepip --default-pip

If that still doesn’t allow you to run pip:

  • Securely Download get-pip.py [1]

  • Run python get-pip.py. [2] This will install or upgrade pip. Additionally, it will install setuptools and wheel if they’re not installed already.

    Warning

    Be cautious if you’re using a Python install that’s managed by your operating system or another package manager. get-pip.py does not coordinate with those tools, and may leave your system in an inconsistent state. You can use python get-pip.py --prefix=/usr/local/ to install in /usr/local which is designed for locally-installed software.

2.3 安装后升级

如果用旧版本pip总是出现一些问题,所以我们用新版本pip

sudo python -m pip install --upgrade --force pip
sudo pip install setuptools==33.1.1

(下面那个命令行安装时报错,也不影响PIL的安装)

三、安装依赖项

很多包可以通过pycharm安装,我们暂时不研究那些,只通过pip安装,终端敲击命令行即可。

至此,只要没有安装过的包,都可以通过pip指令安装。

3.1 PIL

PIL(Python Imaging Library)是Python常用的图像处理库,

PIL依赖于multiprocessing,所以我们需要先安装multiprocessing(如果不安装这个模块,则安装时会出现报错)

sudo pip install multiprocessing

sudo pip install Pillow

3.2 自带的安装好的安装包

import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
import os

此时已经可以实现初步的数据增扩。

你可能感兴趣的:(python,机器学习,macOS)