当我在mac上安装了Python3.5时,终端运行Python2.7。

2024-04-25 02:17:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我在mac上安装、卸载和重新安装pythons, 我觉得事情搞砸了。

最初默认情况下,终端在我输入

$python

,但是在做了一些事情之后,它安装了2.7,现在终端运行的是Python2.7而不是3.5

我安装了python 3.5表单http://python.org/

当我打开bashúu配置文件时

$vim ~/.bash_profile

这就是出现的

# virtualenv
export WORKON_HOME=~/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh


# Setting PATH for Python 3.5
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH

现在当我输入:

$ python

这将显示:

Python 2.7.11 (default, Jun 23 2016, 17:25:20) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

如何将所有python内容(删除旧版本等)重置为我第一次购买Mac(python3.5)时的出厂版本?


Tags: pathorgbashhttp终端表单forbin
3条回答

要查看在提示符下键入python时实际运行的命令,请检查以下命令的顶部结果:

type -a python

这将列出所有别名,并考虑完整的PATH定义。要弄清楚为什么python 2优先于python 3,请确保检查您的~/.bashrc文件(如果它存在)以及您的~/.bash_profile

这对我有效:

Python 3.x

python3

Python 2.x

python

in terminal

要检查Python二进制文件,请运行:

$ which -a python python2 python3

然后检查首先是哪个python路径。

然后设置$PATH$PYTHONPATH(然后重新加载shell),或者使用python2python3命令。

您还可以使用以下解决方法:

PATH="/usr/bin:$PATH" ./python_script.py

其中/usr/bin指向正确的Python二进制文件。

相关问题 更多 >