Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions python/pyspark/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
"""

import atexit
import builtins
import os
import platform
import warnings
import sys

import pyspark
from pyspark.context import SparkContext
Expand All @@ -33,6 +35,16 @@
from pyspark.sql.utils import is_remote
from urllib.parse import urlparse

if getattr(builtins, "__IPYTHON__", False):
# (Only) during PYTHONSTARTUP execution, IPython temporarily adds the parent
# directory of the script into the Python path, which results in searching
# packages under `pyspark` directory.
# For example, `import pandas` attempts to import `pyspark.pandas`, see also SPARK-42266.
if "__file__" in globals():
parent_dir = os.path.abspath(os.path.dirname(__file__))
if parent_dir in sys.path:
sys.path.remove(parent_dir)


if is_remote():
try:
Expand Down