跳至主要內容
python 获取本机IP地址

Python 获取本机 IP 地址

方法一:

通常使用 socket.gethostbyname() 方法即可获取本机 IP 地址,但有时候获取不到(比如没有正确设置主机名称),示例代码如下:

import socket

# 获取本机计算机名称
hostname = socket.gethostname()
# 获取本机ip
ip = socket.gethostbyname(hostname)
print(ip)

AndersonHJB原创...大约 1 分钟brewdebugbrewdebug
Error No such file or directory@rb_sysopen亲测成功

Error: No such file or directory @ rb_sysopen

Error: No such file or directory @ rb_sysopen - /HOME/tmp/github_api_headers20170113-4608-17yraui

Perhaps either the environment variables TMPDIR or HOMEBREW_TEMP is set incorrectly. Does the directory /HOME/tmp exist? Is HOME meant to be capitalized? Try perhaps


AndersonHJB原创...大约 1 分钟brewdebugbrewdebug
ImportError:No module named 'Tkinter'

For some reason, I can't use the Tkinter or tkinter module. After running the following command in the python shell

import Tkinter

AndersonHJB原创...大约 1 分钟tkinterdebugtkinterdebug
更换和重置Mac Homebrew的默认源

你好,我是悦创。

Homebrew 作为 Mac os 系统的包管理器,给软件的安装和更新等带来了极大地便利,但使用过程中总会遇到软件下载特别慢的问题,通过将默认源更改为国内的镜像地址,可以极大地提高下载速度。下面是收集的一些最新的更改默认源的操作(在终端里执行代码):

更换为清华源

更换 brew.git

cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

AndersonHJB原创...大约 3 分钟brewdebugbrewdebug