Missing modules when running Jupyter notebook on aws - python

I'm running a Jupyter notebook on a virtual machine on AWS, and I am having issues loading modules. Apparently the notebook doesn't find the modules (see image below), but these are listed if I give the command !conda list. Does anyone have suggestions on how to fix this? Thanks!

Try:
import sys
!{sys.executable} -m pip install <your package>
Here’s a link that might help you find some more information on how to install python packages in jupyter

Related

Installing Rasterio

I tried installing Rasterio library using command- pip install rasterio and also used conda commands in anaconda cmd, both are didn't worked and it's taking too long to install so I aborted the process. Let me know in detail how to install raserio library for python?
I tried with installing GDAL and raterio whl file by using pip commands. It got installed, but when I tried to import module- it's giving me an error saying No module found. Please help to fix this.
Thanks in advance
I just had the similar problem, and tl:dr the issue for me was multiple environments, like Ameya said. Here's a longer version of Ameya's spot-on answer with steps to diagnose and fix.
Without realizing it, I had two environments going on: my jupyter notebook was running python 3.10 and my global python was running 3.9, and each was looking for site-packages in different locations (/opt/homebrew/Cellar/jupyterlab/3.4.7/libexec/lib/python3.10/site-packages vs /Users//Library/Python/3.9/lib/site-packages).
This happened because I had trouble with getting python and specifically jupyterlab running on Monterey and the only fix for me was using homebrew to manage the packages. Anything I installed with brew from the command line, went into /opt/homebrew/Cellar... etc and could be seen by my jupyter notebook. Anything I used pip install to get from within an open notebook also went onto this path that my notebook could see. But anything I used pip install from the command line to get, went to the path of the global environment's site packages. Then, my jupyter notebook couldn't see them.
You don't mention that you are using jupyter notebook but perhaps something analogous could happen between multiple environments for you.
You can check if this is the case for you by doing the following:
start python from the command line
import sys
run sys.path
start jupyter notebook, or start python from your other environment
same thing, import sys, run sys.path
Are they the same? If not, probably pip is putting your rasterio in other python env site-packages.
To fix, you can either pip install from within your preferred environment, or copy and paste the site packages corresponding to rasterio from one site-packages location to the other.

Why can't I import pybacktest package?

I checked the method of importing this package on the Internet, and I also entered the pip command in cmd, but it still cannot be imported. May I ask why?
Probably because the kernel of your jupyterhub has not the right environment.
Try to reinstall the package using the terminal of jupyter hub (see new drop box) it will do the trick once you have installed the package and refreshed the kernel.
Try this on your Jupyter cell:
pip install git+https://github.com/ematvey/pybacktest.git
Link to github https://github.com/ematvey/pybacktest
Edit for your comment:
run the below command on your Jupyter cell.
pip install pandas_datareader

How to install module in Jupyter Notebooks for iPython

I am using an iPython note in Jupyter Notebooks and need to use the import lmfit. How can I import it such that it will become available in my jupyter notebook?
I should clarify this question applies to multiple modules (really anything you could install using pip or conda). I am trying to determine how to install modules in a Jupyter Notebook.
Run ! pip install <package> within the jupyter notebook.
The ! tells the notebook to run the command in bash, just make sure the pip you are using is the same interpreter the notebook is using
Please check the installation guide for lmfit here.
There is some problem with this package. Even after installation, import to lmfit is not possible. My advise is to ask for support here or check the git repository and raise an issue.

Cannot run fastai library on Jupyter Notebook

I hope this question is not redundant, but I couldn’t find a solution on the internet so far. I’ve followed the github guide (https://github.com/fastai/fastai) to install the fastai library on my Anaconda environment. I want to use this library to tackle the ML course and solve other Kaggle competitions with it.
As per below, I’m opening my conda environment, selecting fastai and opening Jupyter Notebook:
When trying to run the packages in Jupyter, I still get an Import Error with No module named ‘fastai’. Any suggestions on what I’m doing wrong?
Had same issue. It looks like the problem is with "softlinks" fastai which are not working on Windows.
I fixed it with replacing that soflinks with real module fastai from root of repository. Just copied it to courses\dl1, courses\dl2, courses\dm1 and tutorials folders.
Prerry dirty. But works. Let me know how to fix it without copying.
Add a cell to the beginning of the notebook, !python -m pip install git+https://github.com/fastai/fastai.git
Edit:
Now that fastai is 1.0 and on pip, you probably just want to !python -m pip install fastai.
I prefer the !python -m pip syntax over just calling pip when mixing anaconda and pip, but it probably just reflects my system's python being messed up.
I had trouble making fastai_v1 work in jupyter lab, however it was working on the terminal. So the problem was with the virtual environment not being selected in the jupyter lab when it was launched.
I used the below code to make it work. Replace 'myenv' with your virtual environment name.
source activate myevn
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
jupyter lab
more info here: Conda environments not showing up in Jupyter Notebook

Jupyter Notebooks Python Modules Not Found

I am trying to run some modules in Jupyter Notebooks using different libraries but I always get a No Module error, but when I check pip list, the module is there. How do I fix this?
Pip List:
Python Version Output:
on your terminal -
python --version
on your jupyter notebook
import sys
sys.version
Do they match?
Okay next step:
on your terminal
which jupyter
again on your terminal
pip -V
See if they running in the same environment.
Post the output if you aren't able to make sense of it
I think you have used different kernal/env to run this ipynb. So you can check it by typing !pip list to check if matplotlib is in it.
If not you can install it on this env, or switch your env.

Categories