[英]install conda package to google colab
我尝试将软件包从 anaconda 安装到 google 的 colab。
但它不起作用。 整个事情都是巫毒魔法。
以下代码位于一个单元格中。
笔记本的单元格:
!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
结果:
ModuleNotFoundError: No module named 'ujson'
如果我使用“!bash”进入 bash shell,然后运行“bash 的”python,我可以在该 python 中导入 ujson。 但是,如果我直接在“笔记本”python 中导入 ujson,则不起作用。
这里的方法似乎不再有效
!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}))
最新的 hack 是什么?
有2个问题必须解决:
对于 1,您需要将python=3.6
添加到conda install
。
对于2,您需要将路径添加到/usr/local/lib/python3.6/site-packages
这是新代码
# 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}))
在 google colab Jupyter IDE 中,尝试执行:
!pip install ujson
这以前对我有用。 让我知道它现在是否有效。
#如果有人想使用google collab实现,只需在编译其他单元格之前运行它
!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
!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/'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.