python安装教程(mac版)-python安装步骤

Python020

python安装教程(mac版)-python安装步骤,第1张

一、 安装python3.x步骤:

1.首先检查下自己的电脑是否安装了python3 尝试在终端输入以下代码(第一行为输入的代码,第二行为返回的结果):

2.如果mac上没有安装 python3 ,介绍两种安装方式:

(1)第一种方法:通过brew 安装python3 环境

在终端输入如下代码:

它会安装最新版本对python3,现在mac 安装的是python3.7。

(2)第二种方法:通过官网下载。

选择mac下载区地址:https://www.python.org/downloads/macos/

打开链接,可以看到各个版本的 Python:

下载 macOS 64 位 Intel 安装程序

点击该链接,下载完成后得到一个Python 3.9.6 - 2021 年 6 月 28 日安装包。

双击Python 3.9.6就进入了 Python 安装向导,然后按照向导一步一步向下安装,一切保持默认即可。

到此,python3安装完成!

首先声明,我本人还没有研究出来问题的究竟。此处只是写下我本人的一点小心得,大家一起进步。

因为我发现,使用uuid库得到的mac地址,总有最后一位不对。所以,我就查看了python官方的uuid文档,找到了问题的关键是调用UUID()的时候,会调用getnode()函数以得到物理地址。

这个是getnode()函数的定义:

我把它摘出来,考到下面。

def getnode(*, getters=None):

"""Get the hardware address as a 48-bit positive integer.

The first time this runs, it may launch a separate program, which could

be quite slow.  If all attempts to obtain the hardware address fail, we

choose a random 48-bit number with its eighth bit set to 1 as recommended

in RFC 4122.

"""

global _node

if _node is not None:

return _node

if sys.platform == 'win32':

getters = _NODE_GETTERS_WIN32

else:

getters = _NODE_GETTERS_UNIX

for getter in getters + [_random_getnode]:

try:

_node = getter()

except:

continue

if (_node is not None) and (0 <= _node <(1 <<48)):

return _node

assert False, '_random_getnode() returned invalid value: {}'.format(_node)

我正在试图通过研究这个问题来试图研究。但同样,我觉得我们可以直接让python调用系统库,从而执行系统自带的命令:(类似于windows下cmd里面"ipconfig -all"命令,或者ubuntu下terminal中"ifconfig"命令)。实现物理地址。之后,根据“短时间内该机器的网卡不会出现过大的变动这个前提”,我们可以根据返回内容,切片出我们需要的部分即可。

mac自带的python安装在/usr/bin/python目录下

进入终端直接键入python即可进入交互模式

或是python xxx.py 运行 写好的python程序