0

I'm using a package named PDFMiner(http://www.unixuser.org/~euske/python/pdfminer/) to convert pdf to html.

Once I installed the package, I can run the pdf2txt.py anywhere, not only limited inside where the package located.

Could anyone explain to me how this happen? If I have written some python script, how could I run some script anywhere? Thanks

1 Answers1

-1

Read up on the module search path. To quote the documentation:

When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path. sys.path is initialized from these locations:

  • the directory containing the input script (or the current directory).
  • PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).
  • the installation-dependent default.

After initialization, Python programs can modify sys.path. The directory containing the script being run is placed at the beginning of the search path, ahead of the standard library path. This means that scripts in that directory will be loaded instead of modules of the same name in the library directory. This is an error unless the replacement is intended. See section Standard Modules for more information.

See section 6.1.2 of the Module documentation: located here

What is probably going on is the module was installed somewhere that your python interpreter will search when looking for modules to import. The places your interpreter will search are defined by the sys.path variable.

pje
  • 2,458
  • 1
  • 25
  • 26