问题描述
将系统升级到 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/
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)