Mac下安装python3的基本操作

1.安装opencv

简单的命令就行了:pip3 install opencv-contrib-python

测试是否安装成功

import cv2

import numpy as np

from matplotlib import pyplot as plt

img = cv2.imread('road.png',0)

plt.imshow(img, cmap='gray', interpolation='bicubic')

plt.xticks([]), plt.yticks([])# to hide tick values on X and Y axis

plt.show()

2.卸载python

删除Python框架

sudo rm -rf /Library/Frameworks/Python.framework/Versions/x.x

删除Python程序

sudo rm -rf “/Applications/Python x.x”

删除/usr/local/bin目录下的Python连接

x.x为Python的版本号

3.切换默认python

直接在.profile加一个alias就可以了。如果你的Terminal运行的shell是bash(默认),可以修改~/.bash_profile,添加下行(具体的path取决于你的python3安装路径):

alias python="Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4"

然后重启一下Terminal或者直接

source ~/.bash_profile

----

作者:知乎用户

链接:https://www.zhihu.com/question/30941329/answer/51489517

来源:知乎

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

4.确定当前Python环境中的site-packages目录位置

from distutils.sysconfig import get_python_lib

print(get_python_lib())

5.更改安装源

目前国内靠谱的 pip 镜像源有:

清华: https://pypi.tuna.tsinghua.edu.cn/simple

豆瓣: http://pypi.douban.com/simple/

阿里: http://mirrors.aliyun.com/pypi/simple/

pypi.python.org    官方源

pypi.douban.com    豆瓣源,福州

pypi.hustunique.com    华中科技大学源,武汉

pypi.tuna.tsinghua.edu.cn  清华源,北京



在 pip 命令中使用镜像源很简单,在执行 install 命令时,使用 -i 参数加上源地址就可以了,例如,如果不是https,需要加trusted-host

pip3 install h5py -i --trusted-host http://pypi.douban.com/simple/

你可能感兴趣的:(Mac下安装python3的基本操作)