Show More
@@ -181,9 +181,26 b' class InteractiveShellApp(Configurable):' | |||
|
181 | 181 | self.shell.init_user_ns() |
|
182 | 182 | |
|
183 | 183 | def init_path(self): |
|
184 |
"""Add current working directory, '', to sys.path |
|
|
185 | if sys.path[0] != '': | |
|
186 | sys.path.insert(0, '') | |
|
184 | """Add current working directory, '', to sys.path | |
|
185 | ||
|
186 | Unlike Python's default, we insert before the first `site-packages` | |
|
187 | or `dist-packages` directory, | |
|
188 | so that it is after the standard library. | |
|
189 | ||
|
190 | .. versionchanged:: 7.2 | |
|
191 | Try to insert after the standard library, instead of first. | |
|
192 | """ | |
|
193 | if '' in sys.path: | |
|
194 | return | |
|
195 | for idx, path in enumerate(sys.path): | |
|
196 | parent, last_part = os.path.split(path) | |
|
197 | if last_part in {'site-packages', 'dist-packages'}: | |
|
198 | break | |
|
199 | else: | |
|
200 | # no site-packages or dist-packages found (?!) | |
|
201 | # back to original behavior of inserting at the front | |
|
202 | idx = 0 | |
|
203 | sys.path.insert(idx, '') | |
|
187 | 204 | |
|
188 | 205 | def init_shell(self): |
|
189 | 206 | raise NotImplementedError("Override in subclasses") |
General Comments 0
You need to be logged in to leave comments.
Login now