[英]install conda package to google colab
I try to install packages from anaconda to google's colab.我尝试将软件包从 anaconda 安装到 google 的 colab。
But it doesn't work.但它不起作用。 The whole thing is voodoo magic.
整个事情都是巫毒魔法。
The following code is in one cell.以下代码位于一个单元格中。
Notebook's cell:笔记本的单元格:
!wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
!bash Miniconda3-latest-Linux-x86_64.sh -b -f -p /usr/local/
!rm Miniconda3-latest-Linux-x86_64.sh
!conda install -y --prefix /usr/local/ ujson aiohttp tqdm
import sys
os.environ['PYTHONPATH'] = "/usr/local/miniconda3"
os.environ['PATH'] = '/usr/local/miniconda3/bin:' + os.environ['PATH']
sys.path.append('/usr/local/lib/python3.6/site-packages/')
import ujson
Result:结果:
ModuleNotFoundError: No module named 'ujson'
If I go into a bash shell with "!bash" and then run the "bash's" python, I can import ujson in that python.如果我使用“!bash”进入 bash shell,然后运行“bash 的”python,我可以在该 python 中导入 ujson。 But, if I directly import ujson in the "notebook's" python, it doesn't work.
但是,如果我直接在“笔记本”python 中导入 ujson,则不起作用。
The methods here doesn't seem to work anymore这里的方法似乎不再有效
!wget -c https://repo.anaconda.com/miniconda/Miniconda3-4.5.4-Linux-x86_64.sh
!chmod +x Miniconda3-4.5.4-Linux-x86_64.sh
!bash ./Miniconda3-4.5.4-Linux-x86_64.sh -b -f -p /usr/local
!conda install -q -y --prefix /usr/local ujson
import sys
sys.path.append("/usr/local/conda/lib/python3.6/site-packages/")
print(ujson.dumps({1:2}))
What is the latest hack that would work?最新的 hack 是什么?
There are 2 problems that must be solved:有2个问题必须解决:
For 1, you need to add python=3.6
to conda install
.对于 1,您需要将
python=3.6
添加到conda install
。
For 2, you need to add path to /usr/local/lib/python3.6/site-packages
对于2,您需要将路径添加到
/usr/local/lib/python3.6/site-packages
Here's the new code这是新代码
# same
!wget -c https://repo.anaconda.com/miniconda/Miniconda3-4.5.4-Linux-x86_64.sh
!chmod +x Miniconda3-4.5.4-Linux-x86_64.sh
!bash ./Miniconda3-4.5.4-Linux-x86_64.sh -b -f -p /usr/local
# update 1
!conda install -q -y --prefix /usr/local python=3.6 ujson
# update 2
import sys
sys.path.append('/usr/local/lib/python3.6/site-packages')
# test it
import ujson
print(ujson.dumps({1:2}))
In the google colab, Jupyter IDE, try executing:在 google colab Jupyter IDE 中,尝试执行:
!pip install ujson
This worked for me before.这以前对我有用。 Let me know if it works now.
让我知道它现在是否有效。
#If any one want to implement using google collab just run this before compiling other cells #如果有人想使用google collab实现,只需在编译其他单元格之前运行它
!wget https://repo.anaconda.com/miniconda/Miniconda3-py37_4.8.2-Linux-x86_64.sh !wget https://repo.anaconda.com/miniconda/Miniconda3-py37_4.8.2-Linux-x86_64.sh
!chmod +x Miniconda3-py37_4.8.2-Linux-x86_64.sh !chmod +x Miniconda3-py37_4.8.2-Linux-x86_64.sh
!bash ./Miniconda3-py37_4.8.2-Linux-x86_64.sh -b -f -p /usr/local import sys !bash ./Miniconda3-py37_4.8.2-Linux-x86_64.sh -b -f -p /usr/local 导入系统
sys.path.append('/usr/local/lib/python3.7/site-packages/' sys.path.append('/usr/local/lib/python3.7/site-packages/'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.