External libraries and dependencies: Difference between revisions
m (Software requirements stated with versions) |
No edit summary |
||
Line 22: | Line 22: | ||
# Do not forget to add licence files for each packages you added yourself | # Do not forget to add licence files for each packages you added yourself | ||
== Environment variables PATH and PYTHONPATH == | |||
Often, you have to add the folder and subfolders of a DeviceClass to the environment variable PATH or to PYTHONPATH to allow for importing libraries and dlls (dynamic link libraries). | |||
We created a convenience function that adds all folders and subfolders of your DeviceClass script to both environment variables, so that all further imports should work immediately. | |||
Just add the following two lines of code to your DeviceClass before you import external libraries that do not included to SweepMe! | |||
{{syntaxhighlight|lang=python|code= | |||
from FolderManager import addFolderToPATH | |||
addFolderToPATH() | |||
}} | |||
=== Adding a folder to PYTHONPATH === | |||
Of course, you can add folders yourself, e.g. to load a python package that comes with your DeviceClass being in the subfolder "libs", you can use | |||
{{syntaxhighlight|lang=python|code= | |||
# Add the path of your libs within your Device Class to the variable sys.path: | # Add the path of your libs within your Device Class to the variable sys.path: | ||
import os | |||
import sys | |||
libpath = os.path.dirname(__file__) + os.sep + "libs" | |||
if not libpath in sys.path: | |||
sys.path.append(libpath) | |||
# Now import your libs as usual | # Now import your libs as usual | ||
import *name of the lib* | |||
}} | |||
=== Adding a folder to PATH === | |||
In case you like to add a folder to environment variable PATH, use the following lines of code | |||
{{syntaxhighlight|lang=python|code= | |||
# Add the path of your libs within your Device Class to the variable sys.path: | |||
import os | |||
import sys | |||
libpath = os.path.dirname(__file__) + os.sep + "libs" | |||
if not libpath in os.environ["PATH"].split(os.pathsep): | |||
os.environ["PATH"] = libpath + os.pathsep + os.environ["PATH"] | |||
}} | |||
== DLL == | == DLL == | ||
== .Net DLL == | == .Net DLL == |
Revision as of 13:51, 5 February 2019
Python modules
Not all available packages for Python can be part of SweepMe!. Still, you can add these packages to your Device Class and load them from a subfolder. In that case, it might be that sub-dependencies will be shipped twice, once with SweepMe! and once with your Device Class.
For that reason, we recommnend to use our Library Builder which adds all missing packages to a folder which you can copy into your Device Class folder. The Library Builder is available through your sweep-me.net user account. Please contact us to get one (contact@sweep-me.net).
Requirements
- Python 3.6
- All packages installed you need for your Device Class
- pyinstaller 3.3.1 [1] (newer versions will not work)
Extracting the missing packages
- Goto LibraryBuilder folder
- Open build_library.py and change sweepme_path to your installation path of SweepMe!
- Open required_modules.py and import all packages which are missing in SweepMe!
- Run build_library.py
- Copy the folder libs_required_modules to your DC and rename as desired
- Do not forget to add licence files for each packages you added yourself
Environment variables PATH and PYTHONPATH
Often, you have to add the folder and subfolders of a DeviceClass to the environment variable PATH or to PYTHONPATH to allow for importing libraries and dlls (dynamic link libraries). We created a convenience function that adds all folders and subfolders of your DeviceClass script to both environment variables, so that all further imports should work immediately.
Just add the following two lines of code to your DeviceClass before you import external libraries that do not included to SweepMe!
from FolderManager import addFolderToPATH
addFolderToPATH()
Adding a folder to PYTHONPATH
Of course, you can add folders yourself, e.g. to load a python package that comes with your DeviceClass being in the subfolder "libs", you can use
# Add the path of your libs within your Device Class to the variable sys.path:
import os
import sys
libpath = os.path.dirname(__file__) + os.sep + "libs"
if not libpath in sys.path:
sys.path.append(libpath)
# Now import your libs as usual
import *name of the lib*
Adding a folder to PATH
In case you like to add a folder to environment variable PATH, use the following lines of code
# Add the path of your libs within your Device Class to the variable sys.path:
import os
import sys
libpath = os.path.dirname(__file__) + os.sep + "libs"
if not libpath in os.environ["PATH"].split(os.pathsep):
os.environ["PATH"] = libpath + os.pathsep + os.environ["PATH"]