Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I import a third party module in Python?

I've found a third party module which I would like to use. How do I technically import that module?

Particularly, I want to use a module called context_manager. obviously, I cannot just import garlicsim.general_misc.context_managerbecause it won't find garlicsim. So what should I write to import the thing?

EDIT: I'm using both Python 3.x and Python 2.x and I'd like to get answers relevant to both versions.

like image 233
snakile Avatar asked Feb 01 '11 22:02

snakile


People also ask

How do I install a third party module in Python?

The primary way to install third-party modules is to use Python's pip tool. This tool securely downloads and installs Python modules onto your computer from https://pypi.python.org/, the website of the Python Software Foundation. PyPI, or the Python Package Index, is a sort of free app store for Python modules.

What are third party imports in Python?

Imports should be divided according to what is being imported. There are generally three groups: standard library imports (Python's built-in modules) related third party imports (modules that are installed and do not belong to the current application)

Can you manually import a module in Python?

append() Function. This is the easiest way to import a Python module by adding the module path to the path variable. The path variable contains the directories Python interpreter looks in for finding modules that were imported in the source files.


1 Answers

In garlicsim's case you'd want to install it following garlicsim's installation instructions. You could also download the code and in the right directory run python setup.py install for this and almost any other library.

One note, since you may be new to python, is that that's a python 3 library. If you're using python 2 (more likely if you don't know) it won't work right. You'll want to install the python 2 version.

like image 193
chmullig Avatar answered Sep 28 '22 07:09

chmullig