Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Imported package not available in Jupyter-Python

Importing pysftp into Jupyter Notebook

While importing pysftp into Jupyter Notebook, ModuleNotFoundError is shown.

JupyterSnapshot


Checking import of pysftp on device?

I have verified the package installation with

pip list and pip show pysftp

Had imported pysftp package(v0.2.9) and installed it in the below location

C:\users\xxxxxx\appdata\roaming\python\python37\site-packages

pysftp_lib

Check : Package installed OKAY


Check about package correct path linking from cmd prompt?

I'm using Python 3.7.0 on a WIN machine, verifyed the site package location using

import sys and sys.path

image confirms linking of PATH to correct location and the package is successfully executed when python is run through cmd prompt

Python Snapshot

Check : Path link and cmd run OKAY


Now could anyone help me solve why the package import in Jupyter Notebook is throwing an error?

Thank you


Edit 1: Check for different environment installed? added based on one of the answer

Conda Environment

Only one environment is present in the machine

like image 352
Anudeep S Avatar asked Sep 21 '18 06:09

Anudeep S


People also ask

How do I import packages into a Jupyter notebook?

Type in jupyter notebook in the terminal. Open a new notebook and import sys . The important step is to add the path of your virtual environment site packages to the system path. The ./ is a relative path and assumes that you are currently in your virtual environment directory.

Can we install Python packages in Jupyter notebook?

To use python environments you've created on the command line in a Jupyter notebook, you'll need to create what is known as a 'kernel' for the environment. This allows Jupyter to see and use the corresponding environment.


2 Answers

I got the same. I solved by installing directly within Jupyter using the following command:

import sys
!{sys.executable} -m pip install dice-ml
like image 83
Gabriel Avatar answered Oct 14 '22 08:10

Gabriel


Are you running the notebook through a virtual environment?

You can try running the same commands as you did on CMD by preceding it with ! as follows:

!pip list

Ideally this should list the same contents as shown in CMD. However the results may be different if you are running Jupyter notebook in a virtual environment. If you are unable to see pysftp, you need to install it within the virtual environment. This can be done from within your notebook as:

!pip install pysftp

like image 34
Anoop R Desai Avatar answered Oct 14 '22 08:10

Anoop R Desai