Я думаю, проблема в том, как Python-режим Emacs запускает Python. Если я наберу M-x run-python
, то увижу это:
>>> import sys
>>> '' in sys.path
False
>>>
тогда как, если я запускаю интерпретатор python из оболочки, я вижу:
>>> import sys
>>> '' in sys.path
True
>>>
Это, вероятно, из-за следующего кода в run-python
из progmodes / python.el:
(let* ((cmdlist
(append (python-args-to-list cmd)
'("-i" "-c" "import sys; sys.path.remove('')")))
, который не имеет комментариев, и следующая полезная запись в ChangeLog:
2008-08-24 Romain Francoise <romain@orebokech.com>
* progmodes/python.el (run-python): Remove '' from sys.path.
Я бы сказал, что это ошибка в Emacs. Вот обходной путь, который вы можете поместить в свой файл .emacs:
(defun python-reinstate-current-directory ()
"When running Python, add the current directory ('') to the head of sys.path.
For reasons unexplained, run-python passes arguments to the
interpreter that explicitly remove '' from sys.path. This means
that, for example, using `python-send-buffer' in a buffer
visiting a module's code will fail to find other modules in the
same directory.
Adding this function to `inferior-python-mode-hook' reinstates
the current directory in Python's search path."
(python-send-string "sys.path[0:0] = ['']"))
(add-hook 'inferior-python-mode-hook 'python-reinstate-current-directory)