如何在Google的Colab中安装Python软件包? [英] How do I install Python packages in Google's Colab?

查看:1884
本文介绍了如何在Google的Colab中安装Python软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个项目中,我有两个不同的软件包,如何使用setup.py在Google的Colab中安装这两个软件包,以便导入这些软件包?

In a project, I have e.g. two different packages, How can I use the setup.py to install these two packages in the Google's Colab, so that I can import the packages?

推荐答案

您可以使用!setup.py install来做到这一点.

You can use !setup.py install to do that.

Colab就像Jupyter笔记本一样.因此,我们可以在此处使用!运算符在Colab中安装任何软件包. !实际执行的操作是告诉笔记本单元格此行不是Python代码,而是命令行脚本.因此,要在Colab中运行任何命令行脚本,只需在该行之前添加! .

Colab is just like a Jupyter notebook. Therefore, we can use the ! operator here to install any package in Colab. What ! actually does is, it tells the notebook cell that this line is not a Python code, its a command line script. So, to run any command line script in Colab, just add a ! preceding the line.

例如:!pip install tensorflow.这会将该行(此处为pip install tensorflow)视为命令提示符行,而不是某些Python代码.但是,如果您在未在行前添加!的情况下执行此操作,则会抛出错误,提示语法无效".

For example: !pip install tensorflow. This will treat that line (here pip install tensorflow) as a command prompt line and not some Python code. However, if you do this without adding the ! preceding the line, it'll throw up an error saying "invalid syntax".

但是请记住,您必须先将setup.py文件上传到驱动器(最好将其上传到笔记本所在的文件夹中).

But keep in mind that you'll have to upload the setup.py file to your drive before doing this (preferably into the same folder where your notebook is).

希望这能回答您的问题:)

这篇关于如何在Google的Colab中安装Python软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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