Is it possible to use a module without installing it on your computer? Is it possible to use a module without installing it on your computer? selenium selenium

Is it possible to use a module without installing it on your computer?


You're looking for sys.path which will do exactly what you want.

When you try to load a module, Python searches in the current directory for a module with that name. If it doesn't find something there, it searches other places in some order and if it isn't found anywhere it is allowed to look, it'll raise an ImportError. By adding your path to the folder on your USB where you have a version of the module, it should work.

import syssys.path.append("/path/to/your/folder")import selenium

You can also print sys.path to see in which directories Python searches for modules.


Yes it is possible and there are a couple ways to do it.

One way would be to place it in the same directory as the script and import it.

Another way would be to set your system path:

import sysscript_path = "path/to/selenium"if script_path in sys.path:    print "oops, it's already in there."else:    sys.path.insert(0, script_path)# proceed to import selenium here


Beside modification sys.path in a script, you can use PYTHONPATH environment variable. According to The Module Search Path in documentation:

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.

On Windows for example:

set PYTHONPATH=c:\path\to\modules;d:\another\pathpython script.py

On Linux for example:

export PYTHONPATH=/path/to/modules:/another/path./script.py