Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPython has no attribute 'user_ns' #13081

Open
BorislavBlagoev opened this issue Aug 4, 2021 · 3 comments
Open

IPython has no attribute 'user_ns' #13081

BorislavBlagoev opened this issue Aug 4, 2021 · 3 comments

Comments

@BorislavBlagoev
Copy link

BorislavBlagoev commented Aug 4, 2021

I connect my IDE to Databricks cluster via databricks-connect and I get this error when I try to execute the following code:
code:

from pyspark.sql import SparkSession

spark = SparkSession.builder.getOrCreate()


def get_dbutils(spark):
    try:
        from pyspark.dbutils import DBUtils
        dbutils = DBUtils(spark)
    except ImportError:
        import IPython
        dbutils = IPython.get_ipython().user_ns["dbutils"]
    return dbutils


dbutils = get_dbutils(spark)
dbutils.widgets

exceptions:
dbutils.widgets
AttributeError: 'DBUtils' object has no attribute 'widgets'

or

dbutils = IPython.get_ipython().user_ns["dbutils"]

AttributeError: 'NoneType' object has no attribute 'user_ns'

depends on which code is executed

@bollwyvl
Copy link
Contributor

bollwyvl commented Aug 4, 2021

get_ipython will only return a shell instance if you are actually running under ipython (or an ipykernel_launcher session). How are you actually executing your code?

You might need to embed IPython to get access to all the goodies.

@BorislavAtBlagoev
Copy link

I execute it with start button in pycharm.

@bollwyvl
Copy link
Contributor

bollwyvl commented Aug 6, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants