Skip to content

Commit

Permalink
Check if site.getuserbase() exists
Browse files Browse the repository at this point in the history
Apparently virtualenv often does not have site.getuserbase(), so we check for its existence first.

Fixes #246
  • Loading branch information
jasongrout committed Oct 27, 2021
1 parent 9aee793 commit 067a230
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions jupyter_core/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,13 @@ def jupyter_path(*subdirs):
# Next is environment or user, depending on the JUPYTER_PREFER_ENV_PATH flag
user = [jupyter_data_dir()]
if site.ENABLE_USER_SITE:
userdir = os.path.join(site.getuserbase(), 'share', 'jupyter')
# Check if site.getuserbase() exists to be compatible with virtualenv,
# which often does not have this method.
if hasattr(site, 'getuserbase'):
userbase = site.getuserbase()
else:
userbase = site.USER_BASE
userdir = os.path.join(userbase, 'share', 'jupyter')
if userdir not in user:
user.append(userdir)

Expand Down Expand Up @@ -231,7 +237,14 @@ def jupyter_config_path():
# Next is environment or user, depending on the JUPYTER_PREFER_ENV_PATH flag
user = [jupyter_config_dir()]
if site.ENABLE_USER_SITE:
userdir = os.path.join(site.getuserbase(), 'etc', 'jupyter')
# Check if site.getuserbase() exists to be compatible with virtualenv,
# which often does not have this method.
if hasattr(site, 'getuserbase'):
userbase = site.getuserbase()
else:
userbase = site.USER_BASE

userdir = os.path.join(userbase, 'etc', 'jupyter')
if userdir not in user:
user.append(userdir)

Expand Down

0 comments on commit 067a230

Please sign in to comment.