我有一个具有以下目录结构的 python 项目
foo
|--MANIFEST.in
|--requirements.txt
|--setup.py
|--foo.py
|--templates/
|--bar.tmpl
Run Code Online (Sandbox Code Playgroud)
setup.pypython脚本在哪里。以前,我使用安装脚本将脚本符号链接到我的用户私有bin(并成功使用它),但决定将其打包(第一次这样做)。我能够使用$ pip install .项目的根目录在 virutalenv 中成功安装包,并且我能够执行大部分脚本,直到我生成带有jinja2. 似乎templates目录没有与软件包的其余部分一起安装,或者我的脚本没有templates正确找到目录的路径。
摘自foo.py:
from jinja2 import Environment, ModuleLoader
def generate_readme(template_file):
template_env = Environment(loader=PackageLoader('foo','templates'))
template = template_env.get_template(template_file)
template_vars = {"title": get_title()}
output = template.render(template_vars)
return output
Run Code Online (Sandbox Code Playgroud)
注意:'bar.tmpl'作为传递给这个函数template_file
摘自setup.py:
from setuptools import setup
setup(name='foo',
py_modules=['foo'],
entry_points={'console_scripts': ['foo = foo:foo']}
include_package_data=True,
zip_safe=False)
Run Code Online (Sandbox Code Playgroud)
内容MANIFEST.in:
include templates/*
Run Code Online (Sandbox Code Playgroud)
相关回溯:
File …Run Code Online (Sandbox Code Playgroud)