最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]CentOS中virtualenvwrapper出错:zsh command not found workon

CentOS crifan 4202浏览 0评论

折腾:

[已解决]CentOS中退出了virtualenv之后如何再进入之前virtualenv

出现:

 ~ export WORKON_HOME=~/Envs
 ~ workon
zsh: command not found: workon

搜:

command not found: workon

参考:

linux – Virtualenv: workon command not found – Stack Overflow

virtualenvwrapper commands aren’t working – Stack Overflow

去:

vi .zshrc

然后在最后加上:

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

 然后再去让其生效:

 ~ source .zshrc 
virtualenvwrapper.user_scripts creating /root/.virtualenvs/premkproject
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postmkproject
virtualenvwrapper.user_scripts creating /root/.virtualenvs/initialize
virtualenvwrapper.user_scripts creating /root/.virtualenvs/premkvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postmkvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/prermvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postrmvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/predeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postdeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/preactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/get_env_details

然后就可以看到了workon了:

 ~ wor
WORDCHARS         work_in_progress  workon            WORKON_HOME  
 ~ workon –help
Usage: workon env_name
           Deactivate any currently activated virtualenv
           and activate the named environment, triggering
           any hooks in the process.
       workon
           Print a list of available environments.
           (See also lsvirtualenv -b)
       workon (-h|–help)
           Show this help message.
       workon (-c|–cd) envname
           After activating the environment, cd to the associated
           project directory if it is set.
       workon (-n|–no-cd) envname
           After activating the environment, do not cd to the
           associated project directory. 

但是发现去用workon列表是空的,且无法切换到我之前就创建好的虚拟环境中了:

 ~ workon
 ~ workon SIPEnvents
ERROR: Environment ‘SIPEnvents’ does not exist. Create it with ‘mkvirtualenv SIPEnvents’.

感觉是路径有误

所以去改为之前的:

#export WORKON_HOME=$HOME/.virtualenvs
export WORKON_HOME=$HOME/Envs
source /usr/local/bin/virtualenvwrapper.sh
 ~ source .zshrc

然后就可以看到之前就创建好的虚拟环境了:

 ~ workon
SIPEvents

[总结]

之前安装好了virtualenvwrapper,但是找不到workon:

zsh: command not found: work

的原因是:

没有执行到对应的环境变量和脚本

解决办法是:

把对应的环境变量和脚本,放到当前帐号启动脚本中,确保每次都执行到,即可:

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

对于此处,设置好之后,无需重启bash终端,而可以通过source直接让其立刻生效:

source .zshrc

注:

如果你是bash,则是:.bashrc

转载请注明:在路上 » [已解决]CentOS中virtualenvwrapper出错:zsh command not found workon

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
89 queries in 0.170 seconds, using 22.14MB memory