【发布时间】:2022-11-21 13:59:18
【问题描述】:
我有包含多个文件的示例 python 项目:
源代码/common.py:
def toint(x):
return int(x)
源代码/foo1.py:
import common
def add(a,b):
return common.toint(a) + common.toint(b)
源代码/foo2.py:
import common
def sub(a,b):
return common.toint(a)-common.toint(b)
安装程序.py:
from setuptools import setup
setup (name = 'test_py_project',
version = '1.0',
author='Vladislav Tsendrovskii',
description = 'test python modules',
package_dir = {'': 'src'}
)
现在我想安装这个项目。我运行 python3 setup.py install --user 并安装。
但是它的安装方式不是我想要的。
当我尝试使用它时,我遇到了问题。
我做不到import test_py_project.foo1
但我可以做到import foo1
我应该如何修改我的项目,将所有内容放入test_py_project 命名空间?
我试图用谷歌搜索解决方案。但是我失败了(
【问题讨论】:
标签: python namespaces