美文网首页
解决windows下powershell执行workon不生效问

解决windows下powershell执行workon不生效问

作者: SodaCrush | 来源:发表于2023-11-07 09:26 被阅读0次

    参考自:https://blog.csdn.net/a15561415881/article/details/129545858

    找到python安装路径下的Scripts目录,创建 workon.ps1

    if (-not (Test-Path env:WORKON_HOME))
    {
        $WORKON_HOME = 'D:\py_envs'
    } else {
        $WORKON_HOME = ($env:WORKON_HOME).Replace('"','')
    }
    
    if (-not (Test-Path env:VIRTUALENVWRAPPER_PROJECT_FILENAME)) {
        $VIRTUALENVWRAPPER_PROJECT_FILENAME = '.project'
    } else {
        $VIRTUALENVWRAPPER_PROJECT_FILENAME = ($env:VIRTUALENVWRAPPER_PROJECT_FILENAME).Replace('"','')
    }
    
    if ($args.length -eq 0) {
        echo "Pass a name to activate one of the following virtualenvs:"
        echo ==============================================================================
        (Get-ChildItem -Path $WORKON_HOME).Name
        return
    }
    
    $VENV = $args[0]
    
    if (!(Test-Path -Path ("$($WORKON_HOME)\$($VENV)"))) {
        echo ("virtualenv $($VENV) does not exist")
        echo "Create it with 'mkvirtualenv $($VENV)'"
        return
    }
    
    if (!(Test-Path -Path ("$($WORKON_HOME)\$($VENV)\Scripts\activate.ps1") ))  {
        echo "$($WORKON_HOME)$($VENV)"
        echo "doesn't contain a virtualenv (yet)."
        echo "Create it with 'mkvirtualenv $($VENV)'"
        return
    }
    
    iex ("$($WORKON_HOME)\$($VENV)\Scripts\activate.ps1")
    
    if (Test-Path -Path ("$($WORKON_HOME)\$($VENV)\$($VIRTUALENVWRAPPER_PROJECT_FILENAME)")) {
        iex "cdproject"
    }
    

    相关文章

      网友评论

          本文标题:解决windows下powershell执行workon不生效问

          本文链接:https://www.haomeiwen.com/subject/odtfwdtx.html