Mac的终端配置

参考教程

https://juejin.cn/post/6983697673257746440

硬件

最好用有线网络,相当于200-300m,而无线只有20-30m

包管理工具 - Homebrew

brew进行安装包

llama3 git:(main) brew install wget md5sha1sum

==> Auto-updating Homebrew...
Adjust how often this is run with HOMEBREW_AUTO_UPDATE_SECS or disable with
HOMEBREW_NO_AUTO_UPDATE. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
beakerlib                  lexido                     morpheus                   sysaidmin
beancount-language-server  liblc3                     oj                         uni-algo
descope                    llvm@17                    parsedmarc
ffmpeg@6                   logdy                      rustcat
kubecolor                  mdformat                   superfile
==> New Casks
arm-performance-libraries  darkmodebuddy              hhkb-studio                toneprint
automattic-texts           ente-auth                  obs-backgroundremoval      yandex-music
boltai                     flox                       outfox

You have 4 outdated formulae installed.

==> Downloading https://ghcr.io/v2/homebrew/core/wget/manifests/1.24.5
################################################################################################### 100.0%
==> Fetching dependencies for wget: libunistring, gettext and libidn2
==> Downloading https://ghcr.io/v2/homebrew/core/libunistring/manifests/1.2
################################################################################################### 100.0%
==> Fetching libunistring
==> Downloading https://ghcr.io/v2/homebrew/core/libunistring/blobs/sha256:e9a705a5442b3ee55f054a695bfbca7
################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/gettext/manifests/0.22.5
################################################################################################### 100.0%
==> Fetching gettext
==> Downloading https://ghcr.io/v2/homebrew/core/gettext/blobs/sha256:13492dddf82cad8dcb20d1c6375138a0712c
################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/libidn2/manifests/2.3.7
################################################################################################### 100.0%
==> Fetching libidn2
==> Downloading https://ghcr.io/v2/homebrew/core/libidn2/blobs/sha256:32aec190642166c2081088f424cd39cc8b82
################################################################################################### 100.0%
==> Fetching wget
==> Downloading https://ghcr.io/v2/homebrew/core/wget/blobs/sha256:034528edb247df85f90997aca6a51ddb988a880
################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/md5sha1sum/manifests/0.9.5_1-1
################################################################################################### 100.0%
==> Fetching md5sha1sum
==> Downloading https://ghcr.io/v2/homebrew/core/md5sha1sum/blobs/sha256:5f3870382f7bfa8e95a952fb263d0225a
################################################################################################### 100.0%
==> Installing dependencies for wget: libunistring, gettext and libidn2
==> Installing wget dependency: libunistring
==> Downloading https://ghcr.io/v2/homebrew/core/libunistring/manifests/1.2
Already downloaded: /Users/wangfeng/Library/Caches/Homebrew/downloads/48ac60445a77a63996cf15f6414f68a620d544fb683031b14eb3aea95c3064f6--libunistring-1.2.bottle_manifest.json
==> Pouring libunistring--1.2.sonoma.bottle.tar.gz
🍺  /usr/local/Cellar/libunistring/1.2: 59 files, 5.1MB
==> Installing wget dependency: gettext
==> Downloading https://ghcr.io/v2/homebrew/core/gettext/manifests/0.22.5
Already downloaded: /Users/wangfeng/Library/Caches/Homebrew/downloads/447e45b77bb47ede0377f7eab1863825298ecaaaeed0bbd84aca3bd300b00508--gettext-0.22.5.bottle_manifest.json
==> Pouring gettext--0.22.5.sonoma.bottle.tar.gz
🍺  /usr/local/Cellar/gettext/0.22.5: 2,043 files, 23.8MB
==> Installing wget dependency: libidn2
==> Downloading https://ghcr.io/v2/homebrew/core/libidn2/manifests/2.3.7
Already downloaded: /Users/wangfeng/Library/Caches/Homebrew/downloads/45d1d4d2930c4782bf53e761a1c0166cd8a40f4193ac8c44e86f0b6708e80354--libidn2-2.3.7.bottle_manifest.json
==> Pouring libidn2--2.3.7.sonoma.bottle.tar.gz
🍺  /usr/local/Cellar/libidn2/2.3.7: 80 files, 1MB
==> Installing wget
==> Pouring wget--1.24.5.sonoma.bottle.tar.gz
🍺  /usr/local/Cellar/wget/1.24.5: 91 files, 4.5MB
==> Running `brew cleanup wget`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Pouring md5sha1sum--0.9.5_1.sonoma.bottle.1.tar.gz
🍺  /usr/local/Cellar/md5sha1sum/0.9.5_1: 8 files, 58.7KB
==> Running `brew cleanup md5sha1sum`...
➜  llama3 git:(main) pip3 list
Package Version
------- -------
pip     24.0
wheel   0.42.0
➜  llama3 git:(main) md5sum --version

Microbrew md5sum/sha1sum/ripemd160sum 0.9.5 (Wed Dec  6 12:48:56 EST 2006)
  Compiled Dec  6 2006 at 17:48:56
Written by Bulent Yilmaz

Copyright (C) 2004,2006 Microbrew Software
➜  llama3 git:(main) wget --version

出现的问题

 sft_data pip3 install pandas
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try brew install
    xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a non-brew-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip.
    
    If you wish to install a non-brew packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

用虚拟环境

# -m是用来运行Python模块的命令行选项
python3 -m venv myenv\n
source myenv/bin/activate\n
pip install pandas\n

并且也配置了python的解释器,并进行了重启,为什么还是找不到pandas这个库呢?

解决方案:直接将解释器的路径放过去

which python
/Users/wangfeng/Desktop/sft_data/myenv/bin/python

在这里插入图片描述

容易产生错误的地方

输入路径之后,直接按enter之后,就变成了create virtural environment
在这里插入图片描述

错误方法:用find查找到虚拟环境安装的路径,其链接的是brew安装的python路径

在这里插入图片描述

编辑器没有报错,但是运行过程中仍然找不到pandas

但是在终端中运行就可以
ModuleNotFoundError: No module named 'openpyxl'

在这里插入图片描述

得改成专门的运行python文件的按钮

在这里插入图片描述

一定要学会看官方文档

https://code.visualstudio.com/docs/python/python-tutorial

pip安装(安装python就可以)

出现如下问题:

pip命令也找不到,只有pip3

wangfeng@MBP-2FT1NGMD6P-0219 ~ % which python
python not found
wangfeng@MBP-2FT1NGMD6P-0219 ~ % which python3
/usr/local/bin/python3
wangfeng@MBP-2FT1NGMD6P-0219 ~ % python
zsh: command not found: python
wangfeng@MBP-2FT1NGMD6P-0219 ~ % python -V
zsh: command not found: python
wangfeng@MBP-2FT1NGMD6P-0219 ~ % python3 -V
Python 3.12.2
wangfeng@MBP-2FT1NGMD6P-0219 ~ % pip list
zsh: command not found: pip
wangfeng@MBP-2FT1NGMD6P-0219 ~ % pip3 --version
pip 24.0 from /usr/local/lib/python3.12/site-packages/pip (python 3.12)
wangfeng@MBP-2FT1NGMD6P-0219 ~ % pip3 list     
Package Version
------- -------
pip     24.0
wheel   0.42.0

将其进行重命名

wangfeng@MBP-2FT1NGMD6P-0219 ~ % history 10
   10  brew install python
   11  pip uninstall hope -y
   12  pip list
   13  pip list
   14  python -V
   15  brew help
   16  history
   17  brew list | grep python
   18  echo $PATH
   19  brew link python@3.12
   20  which python
   21  which python3
   22  python
   23  python -V
   24  python3 -V
   25  pip list
   26  pip3 --version
   27  pip3 list
   28  nano ~/.zshrc
   29  source ~/.zshrc
   30  pip --version
   31  nano ~/.zshrc
   32  source ~/.zshrc
   33  python -V

在vscode中遇到同样的问题

采用软链接的方式

sudo ln -s /usr/local/bin/python3 /usr/local/bin/python

pip install -e ‘.[all]’

命令 pip install -e ‘.[all]’ 的作用是:

  1. 从当前工作目录(‘.’)安装一个 Python 包;
  2. 以可编辑模式(-e)安装,使得对源码目录中的代码所做的任何修改能够即时影响到已安装的包;
  3. 同时安装该包定义的所有可选依赖(‘[all]’),确保获得项目完整功能所需的全部软件包。

安装anaconda

安装之后进行初始化
https://docs.anaconda.com/free/miniconda/

(base) ➜  ~ echo $PATH
/opt/miniconda3/bin:/opt/miniconda3/condabin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
(base) ➜  ~ cd /opt/miniconda3
(base) ➜  miniconda3 ls
_conda     bin        cmake      conda-meta condabin   envs       etc        include    lib        man        pkgs       python.app sbin       share      shell      ssl
(base) ➜  miniconda3 /opt/miniconda3/bin/conda init zsh
no change     /opt/miniconda3/condabin/conda
no change     /opt/miniconda3/bin/conda
no change     /opt/miniconda3/bin/conda-env
no change     /opt/miniconda3/bin/activate
no change     /opt/miniconda3/bin/deactivate
no change     /opt/miniconda3/etc/profile.d/conda.sh
no change     /opt/miniconda3/etc/fish/conf.d/conda.fish
no change     /opt/miniconda3/shell/condabin/Conda.psm1
no change     /opt/miniconda3/shell/condabin/conda-hook.ps1
no change     /opt/miniconda3/lib/python3.12/site-packages/xontrib/conda.xsh
no change     /opt/miniconda3/etc/profile.d/conda.csh
no change     /Users/wangfeng/.zshrc
No action taken.
(base) ➜  miniconda3 conda -V
conda 24.4.0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值