Show More
@@ -181,9 +181,26 b' class InteractiveShellApp(Configurable):' | |||||
181 | self.shell.init_user_ns() |
|
181 | self.shell.init_user_ns() | |
182 |
|
182 | |||
183 | def init_path(self): |
|
183 | def init_path(self): | |
184 |
"""Add current working directory, '', to sys.path |
|
184 | """Add current working directory, '', to sys.path | |
185 | if sys.path[0] != '': |
|
185 | ||
186 | sys.path.insert(0, '') |
|
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 | def init_shell(self): |
|
205 | def init_shell(self): | |
189 | raise NotImplementedError("Override in subclasses") |
|
206 | raise NotImplementedError("Override in subclasses") |
General Comments 0
You need to be logged in to leave comments.
Login now