【发布时间】:2021-06-24 11:27:31
【问题描述】:
我最近开始使用带有 oh-my-zch 的 zsh。然后我遇到了无法简单地执行 pip install 命令的麻烦。我检查了版本:'python --version' 显示 2.7.16,'python3 --version' 显示 '3.8.2'。 当我输入“pip install ipython”时,它给了我这个错误 'zsh: 将 'ipython' 更正为 '.ipython' [nyae]? ' 然后我输入'n',它给了我如下:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 11, in <module>
load_entry_point('pip==21.0.1', 'console_scripts', 'pip')()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 489, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2843, in load_entry_point
return ep.load()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2434, in load
return self.resolve()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2440, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/Library/Python/2.7/site-packages/pip-21.0.1-py2.7.egg/pip/_internal/cli/main.py", line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
然后当我输入“pip3 install ipython”时,它给了我如下:
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: ipython in ./Library/Python/3.8/lib/python/site-packages (7.21.0)
Requirement already satisfied: setuptools>=18.5 in ./Library/Python/3.8/lib/python/site-packages (from ipython) (50.3.0)
Requirement already satisfied: pickleshare in ./Library/Python/3.8/lib/python/site-packages (from ipython) (0.7.5)
Requirement already satisfied: jedi>=0.16 in ./Library/Python/3.8/lib/python/site-packages (from ipython) (0.18.0)
Requirement already satisfied: backcall in ./Library/Python/3.8/lib/python/site-packages (from ipython) (0.2.0)
Requirement already satisfied: traitlets>=4.2 in ./Library/Python/3.8/lib/python/site-packages (from ipython) (5.0.5)
Requirement already satisfied: decorator in ./Library/Python/3.8/lib/python/site-packages (from ipython) (4.4.2)
Requirement already satisfied: appnope in ./Library/Python/3.8/lib/python/site-packages (from ipython) (0.1.2)
Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in ./Library/Python/3.8/lib/python/site-packages (from ipython) (3.0.18)
Requirement already satisfied: pexpect>4.3 in ./Library/Python/3.8/lib/python/site-packages (from ipython) (4.8.0)
Requirement already satisfied: pygments in ./Library/Python/3.8/lib/python/site-packages (from ipython) (2.8.1)
Requirement already satisfied: parso<0.9.0,>=0.8.0 in ./Library/Python/3.8/lib/python/site-packages (from jedi>=0.16->ipython) (0.8.1)
Requirement already satisfied: ptyprocess>=0.5 in ./Library/Python/3.8/lib/python/site-packages (from pexpect>4.3->ipython) (0.7.0)
Requirement already satisfied: wcwidth in ./Library/Python/3.8/lib/python/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython) (0.2.5)
Requirement already satisfied: ipython-genutils in ./Library/Python/3.8/lib/python/site-packages (from traitlets>=4.2->ipython) (0.2.0)
在升级到 big sur 之前我没有这个问题。升级后我直到现在都没有使用python。我试过 bash,同样的问题。
这是我的 zshrc 文件。
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir vcs virtualenv)
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/Users/dandan/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="agnoster"
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# Caution: this setting can cause issues with multiline prompts (zsh 5.7.1 and newer seem to work)
# See https://github.com/ohmyzsh/ohmyzsh/issues/5765
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=( git zsh-syntax-highlighting zsh-autosuggestions )
source $ZSH/oh-my-zsh.sh
if [ -x "$(command -v colorls)" ]; then
alias ls="colorls"
alias la="colorls -al"
fi
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
# source ~/powerlevel10k/powerlevel10k.zsh-theme
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# Find python file
alias pyfind='find . -name "*.py"'
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
# Remove python compiled byte-code and mypy/pytest cache in either the current
# directory or in a list of specified directories (including sub directories).
function pyclean() {
ZSH_PYCLEAN_PLACES=${*:-'.'}
find ${ZSH_PYCLEAN_PLACES} -type f -name "*.py[co]" -delete
find ${ZSH_PYCLEAN_PLACES} -type d -name "__pycache__" -delete
find ${ZSH_PYCLEAN_PLACES} -depth -type d -name ".mypy_cache" -exec rm -r "{}" +
find ${ZSH_PYCLEAN_PLACES} -depth -type d -name ".pytest_cache" -exec rm -r "{}" +
}
# Add the user installed site-packages paths to PYTHONPATH, only if the
# directory exists. Also preserve the current PYTHONPATH value.
# Feel free to autorun this when .zshrc loads.
function pyuserpaths() {
local targets=("python2" "python3") # bins
# Get existing interpreters.
local interps=()
for target in $targets; do
[ `command -v $target` ] && interps+=($target)
done
# Check for a non-standard install directory.
local user_base="${HOME}/.local"
[ $PYTHONUSERBASE ] && user_base=$PYTHONUSERBASE
# Add version specific paths, if:
# it exists in the filesystem;
# it isn't in PYTHONPATH already.
for interp in $interps; do
# Get minor release version.
local ver=`$interp -V 2>&1`
ver=`echo ${ver:7} | cut -d '.' -f 1,2` # The patch version is variable length, truncate it.
local site_pkgs="${user_base}/lib/python${ver}/site-packages"
[[ -d $site_pkgs && ! $PYTHONPATH =~ $site_pkgs ]] && export PYTHONPATH=${site_pkgs}:$PYTHONPATH
done
}
# Grep among .py files
alias pygrep='grep -nr --include="*.py"'
alias python=/usr/local/bin/python3
# Run proper IPython regarding current virtualenv (if any)
alias ipython="python -c 'import IPython; IPython.terminal.ipapp.launch_new_instance()'"
谁能告诉我如何解决它?谢谢!
【问题讨论】:
-
在 python 2.7 中尝试
python -m pip install -U pip && python -m pip install ipython,在 python 3.8 中尝试python3 -m pip install -U pip && python3 -m pip install ipython。 -
成功了!非常感谢!