我使用elpy配置了我的emacs,如下所示:
;;; for python
(elpy-enable)
(setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
(add-hook 'elpy-mode-hook 'flycheck-mode)
(pyenv-mode)
(setq elpy-shell-use-project-root nil)
(setq python-shell-interpreter "python3")然而,在编写一个简单的python脚本时,如果我试图在同一目录中添加一个自定义的python模块。通过键入ctrl-c ctrl-c在elpy-shell中求值,报告模块不在那里。
import restaurant
ImportError: No module named restaurant如果我直接在终端中评估python脚本,它会工作得很好。不知何故,它没有正确配置elpy shell,似乎在当前目录中找不到python模块。
任何帮助都是非常感谢的。
发布于 2020-06-25 17:04:19
从你的restuarant.py中创建一个定制的包。
最快的方法:
# in terminal
mkdir -p restaurant/restaurant
cd restaurant
touch setup.py复制粘贴到setup.py中:
from setuptools import setup
setup(
name="restaurant",
version="0.0.1",
description="<describe what it does here>",
packages=["restaurant"],
author="yourname",
author_email="youremail",
keywords=["restaurant"],
url="<url in github or bitbucket? - not necessary>"
)省省吧。然后
# in terminal
cd restaurant # the inner folder
# put into the inner restaurant folder your restaurant.py
touch __init__.py # python package needs it to recognize restaurant.py
# put there in:from .restaurant import *
# or import each function/variable/dict etc what should be visible outside
# of package因此,现在您可以从控制台python3使用pip进行本地安装:
# in terminal
pip install -e /path/to/your/outer/folder/restaurant从现在开始重新启动python3,它应该可以在任何地方使用
import restaurant无论何时您将更改放入restaurant.py,使用相同的命令重新安装!
创建自定义包非常简单。我应该很久以前就开始使用它,集中我的代码,让它从任何地方都可以使用。
https://stackoverflow.com/questions/62544358
复制相似问题