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.
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
Related
I have set up a GPU Jupyter Notebook VM using the AI platform on Google Cloud. The server runs Debian stretch.
I want to mount a bucket I've created called example onto a folder called /home/jupyter/transfer. I've been following the instructions outlined here but when I run gsfuse example /home/jupyter/transfer I get the error:
ModuleNotFoundError: No module named 'fuse'
I've installed fuse with:
sudo apt-get install fuse
which is successful but the gsfuse code still doesn't run. I then installed the pip package with:
pip install fuse-python
And it still wouldn't work.
Any ideas?
After a lot of trial and error I managed to figure this out. The problem was the python package and where I was installing it.
If you do:
sudo apt-get install fuse
pip install -U fusepy --user
gsfuse example /home/jupyter/transfer --background
It'll work (where --background) runs the mount in the backgroud.
I'm using one of the deep leaning images but am really only familiar with installing packages using conda which appears to not be used in the image. How do I pip install a package to my jupyter notebook kernel?
You can install python packages from Jupyter Kernel like this:
# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install numpy
You can have a look at this document for more detailed information.
I have tried installing scipy in Google Cloud Shell. The package is installed, but a python import is giving "ImportError: No module named scipy". Screenshot
I have problem only with scipy. Tensorflow and numpy are all working fine.
This problem should be similar to Installed packages disappeared in Google Cloud Shell.
The problem here is that scipy has not been installed. The process got killed at 99%. This is caused by how pip tries to install the package. I suspect that you're using a small VM instance which has memory limitations when pip tries to load the whole file to memory before installing it.
The solution is to install scipy with this command:
pip --no-cache-dir install scipy
Here you ask pip not to cache the file which should do the trick to install scipy on your Google Cloud VM. After the successful installation you should be able to import the scipy module as intended.
I am trying to install the python package tqdm on a linux server.
However, the said server has no internet access. Hence, I am unable to install it using pip. I am also unable to find the tqdm package in Debian's package index.
However, what I am able to do is scp files from my local machine to the server. My local has full internet and sudo access.
Any leads please?
Note: I have sudo access on the server.
You could install it with pip. Just use the available commandline options as follows:
pip --no-index --find-links /path/to/directory/with/egg tqdm
Documentation:
https://pip.pypa.io/en/stable/reference/pip_wheel/#no-index
https://pip.pypa.io/en/stable/reference/pip_wheel/#find-links
I'm on their github page: https://github.com/GoogleCloudPlatform/google-cloud-python
Their first command is pip install --upgrade google-cloud
this gives me:
Collecting google-cloud
Could not find a version that satisfies the requirement google-cloud (from versions: )
No matching distribution found for google-cloud
I downloaded their SDK and which installed their google cloud SDK and I did gcloud init, but I can't seem to have their python library imported into mine. Starting python and typing:
from google.cloud import datastore
gives me an error that it doesn't exist as a module... This is all from their github so I'm not sure what I'm doing wrong
The issue is that the team is trying to transition from gcloud to google-cloud which is still somewhere incomplete.
All you need to do is install gcloud using pip and you should be fine.
Pro Tip: python -m pip install --upgrade gcloud using this command will install it for your python version.
First, make sure you have installed gcloud on your system then run the commands like this:
First: gcloud components update in your terminal.
then: pip install google-cloud
And for the import error:
I had a similar problem. Adding "--ignore-installed" to my pip command made it work for me.
This might be a bug in pip - see this page for more details: https://github.com/pypa/pip/issues/2751