Trouble importing necessary libraries in Google Cloud VM running jupyter - python

I just got Jupyter running in python 3 on Google Cloud but I have a lot of trouble getting the libraries installed while working on a tutorial online. How exactly am I supposed to install libraries on the cloud Vm?(Numpy, mathplotlib) I tried using !pip install numpy and even the jupyter terminal to install libraries but noting seems to work. I even tried installing before I got the server running in the SSH because after it starts I dont have any control to do anything beside exit the server. I really need some python libraires can anyone help?
ImportError Traceback (most recent call last)
<ipython-input-7-cdbc221dd3db> in <module>()
1 import numpy as np
----> 2 import matplotlib.pyplot as plt
3 from sklearn.datasets import load_digits
4 digits=load_digits()
5 import pylab as pl
ImportError: No module named matplotlib.pyplot

You can install dependencies on your Jupyter Notebooks by following this doc.
You can choose one of these options:
Run %pip install LIBRARY in a Notebook's cell and restart the AI Platform Notebook's Kernel. Doing this will allow you to the import and use the "LIBRARY" in your code.
Run pip install LIBRARY from a Jupyter Notebook's terminal. This way is the most similar as installing the libraries on your local computer.
In the provided doc, you will find how to reach the terminal or how to restart your AI Platrofm Notebook's kernel.
Hope this is helpful! :)

Related

VSCode - import errors and interpreter errors

I have several imports in my current code:
from flask import Flask
import datetime as dt
import numpy as np
import pandas as pd
When I run this in VSCODE I am getting this error:
However, running this in jupyter notebook has no problems. When I looked online it said to use python interpreter but when I go to do that I get this error:
And another error:
Anaconda prompt says modules/packages are installed but when I run pip install in default windows terminal it says pip has no module:
Delete and reinstall Python extensions according to the same problem on github.
The second problem is related to the location of your Python interpreter. You need to choose the correct interpreter. I still recommend using one Python version in one environment. You can use other Python versions in virtual environment, so it won't lead to confusion.

Unable to Import Pandas, Numpy, etc When Using Github Desktop for Accessing Group Repo

I am using Github Desktop to access a group Github repo, while running the code below on a ipynb file in VS Code. When I run the following code, I am unable to import pandas even though I have it installed. When I comment out pandas, I am unable to import numpy, even though I have had that installed as well. And so on...
Any reason as to why this may be the case? Thank you.
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-4-01bc08e5df4c> in <module>
1 # Dependences
----> 2 import pandas as pd
3 import numpy as np
4 import matplotlib.pyplot as plt
5
ModuleNotFoundError: No module named 'pandas'
Check if modules were installed in Jupyter current used environment.
After selecting python interpreter, open a new integrated Terminal and run pip show pandas, then see if the module is in folder lib/site-packages under the current environment. If not, please reinstall them.
Reference: Using Python Environment in VS Code.

Conda - VS Code: ModuleNotFoundError: No module named 'geopandas'

I'm kind a new Python user - using Anaconda Python and VS code. I'm trying to launch my jupyter notebook, but I'm not able to import geopandas.
import geopandas
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
in
----> 1 import geopandas
ModuleNotFoundError: No module named 'geopandas'
I can see geopandas in 'conda list' in myenv, but still if I want to check it in my jupyter notebook I get negative response
import sys
'geopandas' in sys.modules
False
enter image description here
I already tried a lots of advices from here and git hub, but I'm not able to figure it out.
Am I missing something?
Thanks a lot for help!
Did you install the geopandas library before? If you don't do this before Please open your anaconda prompt form start menu and command the below lines
conda install -c conda-forge geopandas
and then press the enter button.
After that, You may apply below the line on your code
Update Code:
from geopy import geocoders # For matching the buildings' cities with time zones
from geopy.exc import GeocoderTimedOut # Catch timeouts while using Google geocoding API
from geopy.exc import GeocoderUnavailable # Catch other network problems
As long as you are sure that you can access the environment on jupyter,
What you have to do is to to manually install the packages.
Go to https://www.lfd.uci.edu/~gohlke/pythonlibs/, to download the compatible version for GDAL, Pyproj, Fiona, Shapely and Geopandas.
Then manually installed each using:
pip install the_file_path_to_the_downloaded_file
I hope this helps!
I ran into a similar problem with visual studio code. For me there is a button in the upper right corner of the VS Code window with the current environment selected. I clicked it and it allows me to change the kernel for the notebook :
This is assuming you have the dependencies installed.

PyCharm does not run – Project Interpreter problems

First of all, I want to note that I've read a lot of links related to my problem.
I have some problems with running the code when I want to import a module.
Here is an example of the code:
import numpy as np
Then PyCharm gives me an exception:
Traceback (most recent call last):
File "/Users/Alexander 1
2/PycharmProjects/Coursera/Week1/Vectors/Vecors.py", line 1, in
import numpy as np
ModuleNotFoundError: No module named 'numpy'
Process finished with exit code 1
I have read this and did all what was written. However, it hasn't been working. I've reloaded the PyCharm – no result.
Help me, please! I'm using MacOS 10.13.5, PyCharm 2018.1.4 CE.
You probably have created a new project using virtualenv, read about it here.
It basically creates a new project specific environment, so the libraries inside won't cause a conflict with python2 and python3 packages. So, inside Pycharm, open terminal by pressing alt+f12 , which will open a terminal inside Pycharm, and install numpy usually by pip install numpy
I don't know why, but when I rebooted the computer and created a new project, this problem has disappeared.

How to install a library to use on a virtual platform like Docker/jupyter?

I'm using anaconda 2 for python 2.7, I'm trying to use QuantLib for python and to do so, I've installed Docker container platform in order to import QuantLib library for python
Unfortunately, even so I may be able to use QuantLib and import the library, I'm unable to use matplotlib.
When I used to code with anaconda, matplotlib is imported correctly but when I'm trying to code on the notebook, matplotlib seems not to be installed
this is the message i get after typing import matplotlib in a Jupyter/Docker notebook:
ImportErrorTraceback (most recent call last)
<ipython-input-25-3d3962ebf68c> in <module>()
1 #! C:/users/[...]/anaconda2/lib/site-packages
----> 2 import matplotlib
ImportError: No module named matplotlib
As docker doesn't have any folder on my computer, how can I install any missing library in order to use them in my Docker notebook ?
All explanations are used for Linux but I'm using windows 7 I coudn't find documentation about library setup in Docker.
I know Docker works with containers but I don't really understand the documentation, does anybody know how do we handle those containers to get libraries we need to install for our project ?
Thank you very much for your attention,
In fact, you are NOT using your python installation when doing this, you are using the python installation from your docker container.
Since you are on Windows, this looks a bit like this :
Windows -> Virtual linux -> Another (smaller) virtual linux (your docker container) -> python
This python cannot see the libraries installed on your windows.
Normally, you should modify your dockerfile in order to add missing libraries, however, I think you could use one of Jupyter's feature to open a terminal directly in your docker, and run pip commands directly from there.
IIRC, you can use the "new" menu when on the file browser in jupyter to do this

Categories

Resources