mac os安装python全过程
2019-07-02 本文已影响0人
天线嘟嘟茄
最近在mac上安装python和pandas,与windows安装很顺利不同,遇到了不少问题,先记录下来
首先查看当前python版本,这个是mac os自带的python
$ python --version

使用pyenv查看本机上安装的所有python版本(只有通过pyenv安装的python版本才能查到)
$ pyenv versions

查看可以安装的python版本
$ pyenv install --list

尝试安装python 3.7.3
$ pyenv install 3.7.3

缺少zlib库,安装失败

看来要先用homebrew安装zlib
$ brew intall zlib

再次安装python 3.7.3,还是安装失败

原来要先设置环境变量
export LDFLAGS="-L/usr/local/opt/zlib/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include"

再次安装3.7.3,终于成功了

安装pandas,提示需要安装高版本的python才能完成安装
$ pip install pandas

将python版本切换到已经安装的3.7.3
$ pyenv global 3.7.3

重新安装pandas,就搞定了
安装matplotlib报错:
$ pip install matplotlib

切换到pip3安装(推荐,使用
--user
安装的包只安装在当前用户下)
$ pip3 install matplotlib
这样就安装成功了
进入安装过程中,可能会发现python默认的源下载速度是在是太慢了,可以先按Alt+C
停止安装(Windows对应为Ctrl+C
)
切换到清华的python源安装:
$ pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python
或者直接修改pip源,先进入~,再创建文件夹和pip.conf
文件:
$ cd ~
$ mkdir .pip
$ vim pip.conf
进入pip.conf
之后按i
编辑文件,编辑完之后按下Esc
并输入:wq
保存并退出文件:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
重新尝试一下安装python包,就可以感觉到飞一般的下载速度了
Windows:在C:\Users\xxx(当前用户)下新建pip目录,在pip目录下新建pip.ini文件,写入以上两句配置就可以了
安装项目所需的包后,pycharm还是提示No module named 'requests'
首先使用pip3 list
查看已安装的包,如果已经安装响应的包,打开setting
的Project Interpreter
,设置为本地的python3即可