How to install module in Jupyter Notebooks for iPython - python

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.

Related

Jupyter unable to use Vartests that’s found in my site-packages

I have Anaconda installed in my system. I have used Jupyter notebook to install vartests package using “!pip install vartests”. In my site-packages folder inside Anaconda/lib, I am able to find a directory for vartests, which means the package has been installed. But when I try to import it in the same jupyter notebook, it says import error.
I’ve tried using “!{sys.executable} -m pip install vartests” but it doesn’t help. I’ve followed things written in “Installing Python Packages from Jupyter Notebook” by Jake VanderPlas as well.
One thing, my “!type -a python” doesn’t give me anything. Is there a way out from this?

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

Missing modules when running Jupyter notebook on aws

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

Problem importing (and installing) NumPy in Jupyter Notebook

I am having major trouble right now trying to use numpy in my jupyter notebook.
When I first tried to simply "import numpy", it came back with the error: "ModuleNotFoundError: No module named 'numpy'"
I then read somewhere that I probably needed to install numpy.
So I did this: "import sys
!conda install --yes --prefix {sys.prefix} numpy"
to which it came back saying: "EnvironmentLocationNotFound: Not a conda environment"
Now when it comes to understanding environments or packages or ANYTHING along those lines, I just have no idea what I'm doing. I am in a very beginner course and just following along.
I wish I could understand all of this environment and versioning stuff.
I have no idea where to go from here.
Any insight here would be GREATLY appreciated!!
Edit: I am in fact using Anaconda to launch Jupyter Notebook. Not sure if that means anything to your understanding of my problem or a potential solution.
Mark
For an easy to use graphical user interface to install Python libraries and manage environments, I would recommend Anaconda. It is well integrated with IPython and Jupyter Notebook in particular.
You could try the line bellow, at the notebook:
!pip install numpy
Or you could open up a terminal inside the jupyter notebook and install there, with:
pip install numpy
Another option is to install python3.7 from the anaconda website:
https://www.anaconda.com/distribution/
With anaconda a lot of packages come together when you install it. It's better for beginners. Good luck!
In my case, inside Jupyter notebook, you need to change Kernel (Anaconda environment). I thought you changed environment using conda activate myEnv, but when launching Jupyter, it defaults to the root environment.
I hope this is in fact true- I am a noob in Anaconda.

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

Categories