MAC 安装python3.6的 ipython,安装成功后还是报错找不到 ipython 的问题

本文详细介绍了在Mac上安装ipython的过程,包括解决安装过程中可能遇到的错误提示,以及如何设置环境变量使得可以在终端正常使用ipython。此外还解释了设置环境变量的原因。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、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 文件


### 如何在 Termux 中安装 Python 3.6 要在 Termux 上安装特定版本的 Python(如 Python 3.6),可以通过以下方法实现: #### 方法一:通过 `pointless` 存储库安装 Python 3.6 1. 配置 `pointless` 存储库以便获取较新的。 ```bash curl -LO https://its-pointless.github.io/setup-pointless-repo.sh && bash setup-pointless-repo.sh ``` 2. 使用 `pkg` 命令安装 Python 3.6 版本。注意,某些存储库可能直接提供 `python` 或者带有具体版本号的名。 ```bash pkg install python=3.6.* ``` 如果无法到精确匹配的版本号,则可以尝试仅指定主要版本: ```bash pkg install python3.6 ``` 此过程依赖于存储库中的可用性以及网络连接状况[^4]。 --- #### 方法二:手动编译 Python 3.6 源码 如果官方存储库未提供所需的 Python 3.6 版本,可以选择从源代码自行编译并安装。 1. 安装必要的构建工具和依赖项。 ```bash pkg install clang make git autoconf automake libtool openssl perl ncurses-utils ``` 2. 下载 Python 的源代码压缩。 ```bash cd ~ wget https://www.python.org/ftp/python/3.6.x/Python-3.6.x.tgz tar xf Python-3.6.x.tgz cd Python-3.6.x/ ``` 3. 编译前配置环境变量以适配 Android 平台。 ```bash export PYTHON_CONFIGURE_OPTS="--enable-shared" ./configure --prefix=$PREFIX make make install ``` 完成以上操作后,应该能够在 Termux 中成功部署自定义版本的 Python 解释器[^3]。 --- #### 方法三:切换国内镜像加速安装流程 对于国外资源访问缓慢的情况,推荐更换为清华大学 TUNA 镜像源提升下载效率。 编辑 APT 数据源列表文件替换默认地址: ```bash export EDITOR=nano # 可选 vi/vim/nano 等文本编辑程序 apt edit-sources # 修改 sources.list 文件内容 ``` 将原有行改为如下形式指向新站点: ``` deb [arch=all,i686] http://mirrors.tuna.tsinghua.edu.cn/termux stable main ``` 保存更改后再同步索引数据表: ```bash apt update # 更新本地缓存数据库 apt upgrade # 升级现有组件至最新状态 ``` 随后按照前述方式重新执行安装指令即可[^4]。 --- ### 注意事项 - **Clang 支持**:为了确保兼容性和稳定性,在安装 IPython 或其他高级功能之前,请务必确认已正确设置 Clang 工具链[^1]。 - **模块冲突处理**:当遇到 NumPy、SciPy 类似科学计算扩展加载失败时,需验证基础依赖是否齐全,并考虑采用预编译二进制替代纯 pip 方式解决性能瓶颈问题。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值