How to import modules from site-packages when in a different directory? How to import modules from site-packages when in a different directory? python-3.x python-3.x

How to import modules from site-packages when in a different directory?


There is two ways to make python find your module:

  1. add the path where you module reside in your PYTHONPATH as suggested by bmat
  2. add the path where you module reside in your script like this:
    import syssys.path.insert(0, '/root/Downloads/Python-3.5.2/Lib/site-packages')


Instead of moving the module I would suggest you add the location of the module to the PYTHONPATH environment variable. If this is set then the python interpreter will know where to look for your module.

e.g. on Linux

export PYTHONPATH=$PYTHONPATH:<insert module location here>


Instead of moving the module I would suggest you add the location of the module to the PYTHONPATH environment variable. If this is set then the python interpreter will know where to look for your module.

e.g. on Linux

export PYTHONPATH=$PYTHONPATH: