Skip to content

Commit be863e3

Browse files
author
Steven Silvester
authored
Merge pull request #247 from jasongrout/virtualenv
Check if site.getuserbase() exists
2 parents 9aee793 + 067a230 commit be863e3

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

jupyter_core/paths.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,13 @@ def jupyter_path(*subdirs):
168168
# Next is environment or user, depending on the JUPYTER_PREFER_ENV_PATH flag
169169
user = [jupyter_data_dir()]
170170
if site.ENABLE_USER_SITE:
171-
userdir = os.path.join(site.getuserbase(), 'share', 'jupyter')
171+
# Check if site.getuserbase() exists to be compatible with virtualenv,
172+
# which often does not have this method.
173+
if hasattr(site, 'getuserbase'):
174+
userbase = site.getuserbase()
175+
else:
176+
userbase = site.USER_BASE
177+
userdir = os.path.join(userbase, 'share', 'jupyter')
172178
if userdir not in user:
173179
user.append(userdir)
174180

@@ -231,7 +237,14 @@ def jupyter_config_path():
231237
# Next is environment or user, depending on the JUPYTER_PREFER_ENV_PATH flag
232238
user = [jupyter_config_dir()]
233239
if site.ENABLE_USER_SITE:
234-
userdir = os.path.join(site.getuserbase(), 'etc', 'jupyter')
240+
# Check if site.getuserbase() exists to be compatible with virtualenv,
241+
# which often does not have this method.
242+
if hasattr(site, 'getuserbase'):
243+
userbase = site.getuserbase()
244+
else:
245+
userbase = site.USER_BASE
246+
247+
userdir = os.path.join(userbase, 'etc', 'jupyter')
235248
if userdir not in user:
236249
user.append(userdir)
237250

0 commit comments

Comments
 (0)