我有以下包结构:
module_installer/
|-- module_installer
| `-- __init__.py
`-- setup.py
setup.py
from setuptools import setup
setup(name='module_installer')
模块安装程序/\uuuuu初始化.py
class ImportMe():
pass
在包的“根目录”中,类ImportMe
是可导入的:
module_installer$ tree --charset=ASCI
|-- module_installer
| `-- __init__.py
`-- setup.py
python -c "from module_installer import ImportMe"
# This makes sense. The current dir is in python path and the `module_installer` has `__init__.py.
但是,如果我安装它并尝试从其他目录运行它,则会失败:
module_installer$ pip install .
module_installer$ cd /some_other_dir
some_other_dir$ python -c "from module_installer import ImportMe"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: cannot import name 'ImportMe' from 'module_installer' (unknown location)
对module-installer
的pip freeze
进行灰显显示已成功安装的软件包
在包中查找文件时,不会显示已安装的包:
$ pip show -f module-installer
...
Location: /home/user/Envs/se_ena/lib/python3.7/site-packages
...
Files:
module_installer-0.0.0.dist-info/INSTALLER
module_installer-0.0.0.dist-info/METADATA
module_installer-0.0.0.dist-info/RECORD
module_installer-0.0.0.dist-info/WHEEL
module_installer-0.0.0.dist-info/top_level.txt
# No traces of module_installer/__init__.py?
__init__.py
安装是否正确,类是否不可导入
在我看来
setup.py
中的setuptools.setup
函数调用缺少作为packages
参数参数的包列表setup.py
:为避免手动列出软件包,setuptools提供以下实用程序功能:
相关问题 更多 >
编程相关推荐