Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install dependencies from requirements.txt in Google Colaboratory

How to install python dependencies using a requirements file in Google Colab?

Like the equivalent of pip install -r requirements.txt

like image 875
Nitin Avatar asked May 16 '18 21:05

Nitin


People also ask

Do I have to install packages needed each time when I start Google Colab?

The accepted answer is indeed correct, you will need to install your packages to the virtual machine every time you run it.

Can you import libraries in Google Colab?

To import a library that's not in Colaboratory by default, you can use !pip install or ! apt-get install .


1 Answers

With Daniel's hint above, I was able to solve it.

Using the "uploading files from local computer script" I uploaded my requirements.txt file onto Google Colab platform. Script is found here. This is the script,

from google.colab import files

uploaded = files.upload()

for fn in uploaded.keys():
  print('User uploaded file "{name}" with length {length} bytes'.format(
      name=fn, length=len(uploaded[fn])))

The output on executing, clearly says that, it is saving this file as 'requirements.txt'. I couldn't however find this file in Google Drive, which is fine by me. Then,

!pip install -r requirements.txt

worked!

like image 181
Nitin Avatar answered Sep 28 '22 00:09

Nitin