Mac下安装pip,virtualenv,IPython等 mac上安装matplotlib和numpy等python库 Mac 打开、编辑 .bash_profile 文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/maosilu_ICE/article/details/79851845

一、Mac安装ipython的步骤我主要参考的博客是:

Mac下安装pip,virtualenv,IPython等

但是这里请注意:

1. mac自带了python2.7版本,但是我新装了python3.6.5的版本,所以如果你要使用python3.6版本,在安装ipython的时候就需要使用pip3 install --user ipython (此处我使用了上面链接博客中比较优雅的安装方法)

2. 安装ipython的时候可能会出现类似的错误:

prompt-toolkit 1.0.15 has requirement six>=1.9.0, but you'll have six 1.4.1 which is incompatible.

matplotlib 1.3.1 has requirement numpy>=1.5, but you'll have numpy 1.8.0rc1 which is incompatible.

这时你就需要安装相应的python库,参考以下博客:

mac上安装matplotlib和numpy等python库

3. 这时你再执行 pip3 install --user ipython 进行ipython的安装就可以成功了。

二、安装ipython成功后,终端输入ipython或者使用 python -m  ipython 还是报错找不到ipython的问题

对这个问题我开始以为是自己没有安装成功ipython,于是重复执行  pip3 install --user ipython,但结果显示已经安装过:

Requirement already satisfied: ipython in ./Library/Python/3.6/lib/python/site-packages

Requirement already satisfied: setuptools>=18.5 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from ipython)

Requirement already satisfied: appnope; sys_platform == "darwin" in ./Library/Python/3.6/lib/python/site-packages (from ipython)

Requirement already satisfied: simplegeneric>0.8 in ./Library/Python/3.6/lib/python/site-packages (from ipython)

Requirement already satisfied: traitlets>=4.2 in ./Library/Python/3.6/lib/python/site-packages (from ipython)

Requirement already satisfied: decorator in ./Library/Python/3.6/lib/python/site-packages (from ipython)

Requirement already satisfied: jedi>=0.10 in ./Library/Python/3.6/lib/python/site-packages (from ipython)

Requirement already satisfied: backcall in ./Library/Python/3.6/lib/python/site-packages (from ipython)

Requirement already satisfied: pexpect; sys_platform != "win32" in ./Library/Python/3.6/lib/python/site-packages (from ipython)

Requirement already satisfied: prompt-toolkit<2.0.0,>=1.0.15 in ./Library/Python/3.6/lib/python/site-packages (from ipython)

Requirement already satisfied: pickleshare in ./Library/Python/3.6/lib/python/site-packages (from ipython)

Requirement already satisfied: pygments in ./Library/Python/3.6/lib/python/site-packages (from ipython)

Requirement already satisfied: six in ./Library/Python/3.6/lib/python/site-packages (from traitlets>=4.2->ipython)

Requirement already satisfied: ipython-genutils in ./Library/Python/3.6/lib/python/site-packages (from traitlets>=4.2->ipython)

Requirement already satisfied: parso==0.1.1 in ./Library/Python/3.6/lib/python/site-packages (from jedi>=0.10->ipython)

Requirement already satisfied: ptyprocess>=0.5 in ./Library/Python/3.6/lib/python/site-packages (from pexpect; sys_platform != "win32"->ipython)

Requirement already satisfied: wcwidth in ./Library/Python/3.6/lib/python/site-packages (from prompt-toolkit<2.0.0,>=1.0.15->ipython)

最终在这个问题的第二个回答中我找到了答案:

unable to install ipython on mac

第二个回答 :

Had similar issues when trying to install ipython and jupyter on my mac (El Capitan v10.11.6)

Tried various combinations including sudo -H--ignore <whatever people suggested> etc.

The only thing that worked for me:

You would also need to add your 'user python modules' to your path. One way is using nano to edit your .bash_profile:

export PATH=$PATH:/Users/YOUR USER ID/Library/Python/2.7/bin

Then just open a new terminal or use source command to apply it in the open terminal.

You can find a different approach here.

Hope it helps!

本人英语不好,但这段话大体意思就是说,需要设置ipython的环境变量(即访问路径)后,才可以正常使用ipython,具体的操作就是

1. 在  ~/.bash_profile  文件中添加 export PATH=$PATH:/Users/YOUR USER ID/Library/Python/2.7/bin 这句话,当然具体的路径你需要根据自己的安装来设定,例如我的是:

export PATH=$PATH:/Users/ice/Library/python/3.6/bin

2. 更新刚配置的环境变量:source .bash_profile,这样这个刚更新的文件就可以立即生效


三、为什么需要设置ipython的环境变量

本着理解问题要透彻的原则,查了一下,ipython命令并不属于bash命令,所以需要设置环境变量并生效后才可以使用ipython


四、.bash_file 文件的位置在哪里?如何进行编辑、修改?

参考博客:

Mac 打开、编辑 .bash_profile 文件


猜你喜欢

转载自blog.csdn.net/maosilu_ICE/article/details/79851845