LISE-B26 / pylabcontrol

pylabcontrol: Laboratory Equipment Control for Scientific Experiments.
GNU General Public License v3.0
9 stars 9 forks source link

Change export and import to work for an arbitrary path not necessarily in the python path #145

Open akabcenell opened 6 years ago

akabcenell commented 6 years ago

Right now we export and import from, for example, scripts.set_laser. However, this assumes that b26_toolkit (or whatever toolkit) is in the python path. If it isn't, then the export and import functions won't be able to find any of the scripts. To fix this, we can change import_module to:

import importlib.util spec = importlib.util.spec_from_file_location("module.name", "/path/to/file.py") foo = importlib.util.module_from_spec(spec) spec.loader.exec_module(foo)

This will allow importing based on the the absolute path.