RIDE
RIDE copied to clipboard
Add Project path into sys.path
I add MyLibrary/MyLibrary.py in my project path, when open the path, get ModuleNotFoundError: No module named 'MyLibrary', I add the project path into sys.path and solved this. Can RIDE add the project path into the sys.path when open it?
below is the patch for project.py
+++ "D:\\Python37_venv\\robot\\Lib\\site-packages\\robotide\\controller\\project.py" 2021-07-23 09:32:20.902912300 +0800
@@ -17,6 +17,9 @@
import shutil
import tempfile
+import sys
+import copy
+
from robotide.context import LOG
from robotide.controller.ctrlcommands import NullObserver, SaveFile
from robotide.publish.messages import RideOpenSuite, RideNewProject, RideFileNameChanged
@@ -48,6 +51,18 @@
self.external_resources = []
self._resource_file_controller_factory = ResourceFileControllerFactory(namespace, self)
self._serializer = Serializer(settings, LOG)
+ self._update_sys_path(self.default_dir)
+
+ def _update_sys_path(self, path):
+ """add by linb.wu"""
+ __name = '_old_sys_path_'
+ if not hasattr(self, __name):
+ setattr(self, __name, copy.deepcopy(sys.path))
+ sys.path = copy.deepcopy(getattr(self, __name))
+ abspath = os.path.abspath(path)
+ if abspath not in sys.path:
+ sys.path.insert(1, abspath)
+ print(sys.path)
def _construct_library_manager(self, library_manager, settings):
return library_manager or \
@linbwu A long time has passed, and now is time to re-check this on new version 2.0b2.
If you add the path to libraries in PYTHONPATH (Tools->Preferences->Importing) would solve the problem? Then we don't need to modify code.
Thanks.
Closing because of no response from author.