muncherelli
muncherelli

Reputation: 2903

Difference between installing and importing modules

New to Python, so excuse my lack of specific technical jargon. Pretty simple question really, but I can't seem to grasp or understand the concept.

It seems that a lot of modules require using pip or easy_install and running setup.py to "install" into your python installation or your virtualenv. What is the difference between installing a module and simply taking it and importing the into another script? It seems that you access the modules the same way.

Thanks!

Upvotes: 2

Views: 8439

Answers (2)

Darien
Darien

Reputation: 3592

It's like the difference between:

  • Uploading a photo to the internet
  • Linking the photo URL inside an HTML page

Installing puts the code somewhere python expects those kinds of things to be, and the import statement says "go look there for something named X now, and make the data available to me for use".

Upvotes: 9

Tim Peters
Tim Peters

Reputation: 70592

For a single module, it usually doesn't make any difference. For complicated webs of modules, though, an installation program may do many things that wouldn't be immediately obvious. For example, it may also copy data files into locations the new modules can find them, put executables (binary libraries, or DLLs on Windws, for example) where the new modules can find them, do different things depending on which version of Python you have, and so on.

If deploying a web of modules were always easy, nobody would have written setup programs to begin with ;-)

Upvotes: 1

Related Questions