setup.py:将src包重命名为项目名称 [英] setup.py: renaming src package to project name
问题描述
假设您有一个名为 proj
的项目,并且在此项目中具有以下结构:
Let's say you have a project called proj
and in this project you have the following structure:
proj/
dists/
doc/
src/
__init__.py
xyz.py
abc.py
test/
setup.py
您可以看到自己所有的内容项目位于 src
子文件夹中。如何从 src
文件夹制作distutils分发包?
As you can see all the content of your project is in the src
subfolder. How to go about making a distutils distribution package out of the src
folder?
我的幼稚想法是紧随教程,本来应该写 setup.py
像这样:
My naive idea, following the tutorial, would've been to write the setup.py
like this:
#omitting basics
setup(
name='proj',
packages=['src'],
package_dir={'proj':'src'}
)
但是将生成的软件包安装到我的系统后,我仍然必须导入 src.xyz
而不是 proj.xyz
,这将是目标和预期结果。
But after installing the resulting package to my system, I still have to import src.xyz
and not proj.xyz
, which would've been the goal and the expected result.
推荐答案
您可以通过将Python软件包文件放入 proj /
来解决此问题目录:
You could fix it by putting Python package files into proj/
directory:
proj/
src/
proj/
__init__.py
xyz.py
abc.py
setup.py
然后更改 setup.py
到:
# ...
setup(
name='proj',
packages=['proj'],
package_dir={'':'src'}
)
distutils不需要,但是其他工具可能希望其父目录名称为 __ init __。py
文件与Python软件包名称相同,即 proj
。
It is not required by distutils but other tools might expect the parent directory name of __init__.py
file to be the same as Python package name i.e., proj
in this case.
这篇关于setup.py:将src包重命名为项目名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!