是否可以在Google-colab中激活virtualenv? (/bin/sh:1:来源:找不到) [英] Is it possible to activate virtualenv in Google-colab? (/bin/sh: 1: source: not found)

查看:416
本文介绍了是否可以在Google-colab中激活virtualenv? (/bin/sh:1:来源:找不到)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Google Colab中安装theano进行测试.我已经安装了virtualenv并创建了一个环境:

I am trying to install theano in Google Colab for testing. I have installed virtualenv and created an environment:

!pip3 install virtualenv
!virtualenv theanoEnv

但是即使明确提到了"activate"命令的位置,也无法激活虚拟环境.

But am not able to activate the virtual environment even explicitly mentioned the location of 'activate' command.

!source /content/theanoEnv/bin/activate theanoEnv

错误消息是:

/bin/sh: 1: source: not found

有可能做吗?:

source /[SomeVirtualEnv]/bin/activate SomeVirtualEnv

推荐答案

简短的回答,尽管您总是可以运行,但我认为这是不可能的

Short answer, I don't believe it is possible, although you can always run

!pip3 install theano

我能够激活virtualenv,但是我不相信您可以切换当前笔记本以使用新创建的virtualenv.

I was able to activate the virtualenv, but I don't believe you can switch the current notebook to use the newly created virtualenv.

!pip3 install virtualenv
!virtualenv theanoEnv
!echo '#!/bin/bash \n . ./theanoEnv/bin/activate theanoEnv \n which python3'  > source_theanoEnv.sh && chmod +x source_theanoEnv.sh && ./source_theanoEnv.sh && which python3
!which python3

我将哪个python3"放在3个地方,结果是

I have put "which python3" in 3 places and the results are

/content/theanoEnv/bin/python3
/usr/bin/python3
/usr/bin/python3

所以看起来激活"只是暂时的,而Colaboratory/Jupyter仍在使用/usr/bin/python3

So it looks like the "activate" is only temporary and Colaboratory/Jupyter are using /usr/bin/python3 still

基本上每个!命令在自己的外壳中运行,而协作实验室不知道环境已更改

Basically each ! command runs in its own shell, and Colaboratory does not know the environment changed

我希望我可以按照以下步骤进行操作 https://help.pythonanywhere.com/pages/IPythonNotebookVirtualenvs/

I was hoping I could follow these steps https://help.pythonanywhere.com/pages/IPythonNotebookVirtualenvs/

/content/theanoEnv/bin/pip3 install ipykernel
/content/theanoEnv/bin/python3 -m ipykernel install --user --name=theanoEnv

但是我不知道将kernel_class设置为什么

But I don't know what to set the kernel_class to

%config IPKernelApp.kernel_class='???'

而且,即使以上方法可行,我也不认为有一种方法可以重新启动笔记本计算机以使用新内核.

Also, even if the above worked, I don't believe there is a way to restart the notebook to use the new kernel.

也许更精通Jupyter/Colaboratory的人可以解释这是否可能.

Perhaps someone more versed in Jupyter/Colaboratory could explain if this would be possible.

这篇关于是否可以在Google-colab中激活virtualenv? (/bin/sh:1:来源:找不到)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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