Vivek
Vivek

Reputation: 175

Installing Python Libraries in VM Instance

I have created a VM Instance on Google Cloud, and wrote some code in it. I import a library in my code which has not been installed in the VM instance. How can I install the library in the VM Instance now?

Google searches show links to install python packages in notebooks but none of them explain how to do it in VM Instances.

Upvotes: 1

Views: 3001

Answers (1)

sllopis
sllopis

Reputation: 2368

Google Cloud Shell

If you are trying to install Python dependencies within your GCE instance, I would just SSH into your instance, then once inside the Cloud Shell, install pip, which is Python's package manager, using the following commands:

sudo curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
sudo python get-pip.py

After this, for example, if you would like to import Beautifulsoup library (or any other library) in your code, you would run the following command in the command line to install the library:

sudo pip install beautifulsoup4

In your code

Just import the following in your Python code to have access to the library:

from bs4 import BeautifulSoup

Upvotes: 2

Related Questions