在 MacOS 中更改 Pip 路径

将系统升级到 MacOS Mojave 并在 Emacs 中启动 shell 后,出现以下错误:

/Users/user/miniconda3/bin/python: Error while finding module specification for 'virtualenv
wrapper.hook_loader' (ModuleNotFoundError: No module named 'virtualenvwrapper')                 
virtualenvwrapper.sh: There was a problem running the initialization hooks.

If Python could not import the module virtualenvwrapper.hook_loader,check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/Users/user/miniconda3/bin/python and that PATH is set properly.

看来原因如下:

bash-3.2$ which python
/Users/user/miniconda3/bin/python
bash-3.2$ which pip
/usr/local/bin/pip

也就是说,它从 Miniconda 获取 Python,但从 OS 位置获取 Pip。

重新安装 Pip 并没有解决这个问题。

如何更改路径,以便使用的 Python 和 Pip 都来自 Miniconda?

编辑:

以下互动说明了之前和之后

(base) MacBook-Pro:envs user$ which pip
/Users/user/miniconda3/bin/pip
(base) MacBook-Pro:envs user$ which python
/Users/user/miniconda3/bin/python
(base) MacBook-Pro:envs user$ conda activate env-test
(env-test) MacBook-Pro:envs selfishman$ which python
/Users/user/miniconda3/envs/env-test/bin/python
(env-test) MacBook-Pro:envs user$ which pip
/Users/user/miniconda3/envs/env-test/bin/pip
(env-test) MacBook-Pro:envs user$ source ~/.bashrc
/Users/user/miniconda3/envs/env-test/bin/python: Error while finding module specification for 'virtualenvwrapper.hook_loader' (ModuleNotFoundError: No module named 'virtualenvwrapper')
virtualenvwrapper.sh: There was a problem running the initialization hooks.

If Python could not import the module virtualenvwrapper.hook_loader,check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/Users/user/miniconda3/envs/env-test/bin/python and that PATH is
set properly.
(env-test) MacBook-Pro:envs user$ which python
/Users/user/miniconda3/envs/env-test/bin/python
(env-test) MacBook-Pro:envs user$ which pip
/usr/local/bin/pip
(env-test) MacBook-Pro:envs user$ 

也就是说,当我启动一个新的 shell 时,似乎一切正常。但是,如果我在那之后手动获取 .bashrc ,它似乎破坏了 Pip 路径。我不确定这是 Bash、OS 还是 Conda 问题。任何帮助表示赞赏。

.bashrc 如下

export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting

export NVM_DIR="/Users/user/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm

export PATH=/usr/local/bin:$PATH #adding this to make cURL work from the brew install

export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

export VIRTUALENVWRAPPER_PYTHON=/Users/user/miniconda3/bin/python3
#source $HOME/miniconda3/bin/virtualenvwrapper.sh
export PATH="$PATH:$HOME/miniconda3/bin"

#export PATH=/Users/user/miniconda3/bin/python:/Users/user/miniconda3/bin:/usr/local/bin:/usr/bin

export PATH=$PATH:/usr/local/Cellar/postgresql@12/12.6_2/bin/
elegantseven 回答:在 MacOS 中更改 Pip 路径

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/500417.html

大家都在问