mhoq
mhoq

Reputation: 159

import in jupyter notebook to use a method from another file

I am using jupyter notebook. I have 3 jupyter source files written in python in a folder in the same directory: parser, preprocess, and temp. I am trying to import parser and import preprocess in the temp file so that I can use the methods written in those files. Example: there is method named extract in parser file. I want to use that from temp file. How can I do that?

Upvotes: 5

Views: 1384

Answers (3)

batman
batman

Reputation: 60

The easiest way is to change the files you need to import as py files. As an example, parser.ipynb can be converted to a python file parser.py, and you can import it from another notebook file. If you want to use a function named extract() from parser.py, just import

from parser import extract

Upvotes: 2

Jafar Isbarov
Jafar Isbarov

Reputation: 1562

You can run pip install preprocess from the terminal (or CMD, if you are using Windows). Alternatively, you can run ! pip install preprocess from Jupyter Notebook itself, which will do the same thing. You may need the second one if you are working on Google Colab.

Upvotes: 0

Anubhav
Anubhav

Reputation: 365

You can use pip for installing packages. Open command propmpt (cmd) and type this below command

pip install preprocess

Upvotes: 1

Related Questions