Github user buckhx commented on a diff in the pull request: https://github.com/apache/spark/pull/4897#discussion_r40440718 --- Diff: python/pyspark/context.py --- @@ -711,6 +721,30 @@ def addPyFile(self, path): # for tests in local mode sys.path.insert(1, os.path.join(SparkFiles.getRootDirectory(), filename)) + def addRequirementsFile(self, path): + """ + Add a pip requirements file to distribute dependencies for all tasks + on thie SparkContext in the future. An ImportError will be thrown if + a module in the file can't be downloaded. + See https://pip.pypa.io/en/latest/user_guide.html#requirements-files + Raises ImportError if the requirement can't be found + """ + import pip + tar_dir = tempfile.mkdtemp() + try: + for req in pip.req.parse_requirements(path, session=uuid.uuid1()): + if not req.check_if_exists(): + pip.main(['install', req.req.__str__()]) + mod = __import__(req.name) + mod_path = mod.__path__[0] --- End diff -- Indeed mod.__path__[0] does not work for namespace packages. Working on supporting them by bundling all paths in mod.__path__ into a single tar.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org