如何在虚拟环境中运行全局安装的Jupyter? [英] How do I run globally installed Jupyter from within virtual environments?

查看:194
本文介绍了如何在虚拟环境中运行全局安装的Jupyter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在虚拟环境中使用全局安装的Jupyter版本运行Jupyter笔记本电脑(使用virtualenvwrapper,因为我想管理已安装软件包的版本).而且我不使用Anaconda.

I'm trying to run Jupyter notebooks with a globally installed version of Jupyter from within virtual environments (using virtualenvwrapper, because I want to manage versions of installed packages). And I do not what to use Anaconda.

问题是,当我从virtualenv中运行jupyter notebook时,它找不到在env中安装的软件包,而仅找到全局安装的软件包.

The problem is when I run jupyter notebook from within the virtualenv, it cannot find the packages installed in the env, it only finds the packages installed globally.

如何设置Jupyter来检查安装在虚拟环境中而不是全局安装的软件包?

How do I set up Jupyter to check for packages installed within the virtual environment instead of globally?

这是我运行which pythonwhich jupyter时得到的:

Here is what I get when I run which python and which jupyter:

全局:

which python  >>> /usr/local/bin/python
which jupyter >>> /usr/local/bin/jupyter

在virtualenv中:

from within virtualenv:

which python  >>> /Users/brianclifton/.virtualenvs/test/bin/python
which jupyter >>> /usr/local/bin/jupyter

在virtualenv中运行jupyter notebook:

running jupyter notebook from within the virtualenv:

which python  >>> /usr/local/bin/python
which jupyter >>> /usr/local/bin/jupyter

另外,这是我的.bash_profile:

export VISUAL=vim
export EDITOR="$VISUAL"

export PS1="\\[\[\e[38;5;94m\][\u] \[\e[38;5;240m\]\w:\[\e[m\] \$(__git_ps1 '(%s)')$ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
export PATH=/usr/local/bin/python:/usr/local/bin:$PATH

alias ls='ls -GFh'
alias pserv="python -m SimpleHTTPServer"
alias ipynb="jupyter notebook"

export WORKON_HOME=/Users/brianclifton/.virtualenvs
export PROJECT_HOME=/Users/brianclifton/dev
source /usr/local/bin/virtualenvwrapper.sh

if [ -f $(brew --prefix)/etc/bash_completion ]; then
    . $(brew --prefix)/etc/bash_completion
fi

alias branch='git rev-parse --abbrev-ref HEAD'

function frameworkpython {
   if [[ ! -z "$VIRTUAL_ENV" ]]; then
      PYTHONHOME=$VIRTUAL_ENV /usr/local/bin/python "$@"
   else
      /usr/local/bin/python "$@"
   fi
}

推荐答案

一种可能的解决方案是在您的virutalenv的bin目录前添加路径.这样,jupyter将找到virtualenv的库.激活环境后,可以通过运行export PATH:`which python`:$PATH来执行此操作.别名将很容易.

One possible solution is to prefix your virutalenv's bin directory to your path. This way jupyter will find the virtualenv's libraries. You can do this by running export PATH:`which python`:$PATH after you activate your environment. It would be easy enough to alias.

但是,更好的解决方案可能是将此行添加到 postactivate钩子/script .要找到此脚本的位置,请在激活virtualenvwrapper并编辑$WORKON_HOME/<virtualenv_name>/bin/postactivate之后执行ls $WORKON_HOME.

However, a better solution may be to add this line to the postactivate hook/script. To find the location of this script do ls $WORKON_HOME after activate virtualenvwrapper and edit $WORKON_HOME/<virtualenv_name>/bin/postactivate.

这篇关于如何在虚拟环境中运行全局安装的Jupyter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆