mac写python用什么软件,Mac上使用什么版本的Python?

本文指导如何在Mac OS上定位Python 2.7.6的位置,同时介绍如何处理不同Python版本(如2.7和3.3)的共存问题,包括使用`which`, `python`, 和 `brew` 等工具,以及Homebrew安装包管理和环境变量设置。
摘要由CSDN通过智能技术生成

I have a mac, when I do:

python --version

I got:

Python 2.7.6

but when I got to:

/System/Library/Frameworks/Python.framework/Versions/3.3

where is 2.7.6 located ?

any advice what should I do?

UPDATE:

$ which -a python python3

/usr/bin/python

/usr/local/bin/python3

$ brew list python python3

Error: No such keg: /usr/local/Cellar/python

$ locate python

WARNING: The locate database (/var/db/locate.database) does not exist.

To create the database, run the following command:

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist

Please be aware that the database can take some time to generate; once

the database has been created, this message will no longer appear.

in PyCharm editor, the default settings interpreter shows:

e5459fcef7abff2d99b6c895d72135a9.png

解决方案

You could have multiple Python versions on your macOS.

You may check that by command, type or which command, like:

which -a python python2 python2.7 python3 python3.6

Or type python in Terminal and hit Tab few times for auto completion, which is equivalent to:

compgen -c python

By default python/pip commands points to the first binary found in PATH environment variable depending what's actually installed. So before installing Python packages with Homebrew, the default Python is installed in /usr/bin which is shipped with your macOS (e.g. Python 2.7.10 on High Sierra). Any versions found in /usr/local (such as /usr/local/bin) are provided by external packages.

It is generally advised, that when working with multiple versions, for Python 2 you may use python2/pip2 command, respectively for Python 3 you can use python3/pip3, but it depends on your configuration which commands are available.

It is also worth to mention, that since release of Homebrew 1.5.0+ (on 19 January 2018), the python formula has been upgraded to Python 3.x and a python@2 formula will be added for installing Python 2.7. Before, python formula was pointing to Python 2.

For instance, if you've installed different version via Homebrew, try the following command:

brew list python python3

or:

brew list | grep ^python

it'll show you all Python files installed with the package.

Alternatively you may use apropos or locate python command to locate more Python related files.

To check any environment variables related to Python, run:

env | grep ^PYTHON

To address your issues:

Error: No such keg: /usr/local/Cellar/python

Means you don't have Python installed via Homebrew. However double check by specifying only one package at a time (like brew list python python2 python3).

The locate database (/var/db/locate.database) does not exist.

Follow the advice and run:

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist

After the database is rebuild, you can use locate command.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值