为什么之后`设置.py开发新的子模块不可用?

2024-09-21 02:54:32 发布

您现在位置:Python中文网/ 问答频道 /正文

为什么要在添加新脚本/子模块等之后再次运行setup.py develop?在

例如,我这样做:

pyvenv venv
. venv/bin/activate

现在,创建以下文件:

^{pr2}$

在(设置.py很简单,而且傻瓜包含一个功能) 然后

python setup.py develop

现在,如果启动python,就可以导入testpkg.foo。在

但是现在,加上棒.py公司名称:

/
| setup.py
| testpkg
|  | __init__.py
|  | foo.py
|  | bar.py      <---
|  |__
|__

无法导入testpkg.bar

除非你再跑一次

python setup.py develop

为什么?(为什么它不起作用,为什么要选择这种行为,如果它是预期的行为?)在

注释(和编辑)

在我的计算机上,运行python setup.py develop之后,我注意到链接指向build/lib/[…].egg信息

在egg信息中,我看到源代码指向这个build/lib。这里的文件不是链接,那么它应该如何工作??在


Tags: 文件pybuild脚本信息venvfoo链接
1条回答
网友
1楼 · 发布于 2024-09-21 02:54:32

检查是否设置了use TO3标志。然后,正如医生所说:

If you have enabled the use_2to3 flag, then of course the .egg-link will not link directly to your source code when run under Python 3, since that source code would be made for Python 2 and not work under Python 3. Instead the setup.py develop will build Python 3 code under the build directory, and link there. This means that after doing code changes you will have to run setup.py build before these changes are picked up by your Python 3 installation.

相关问题 更多 >

    热门问题