[英]Python package installed but content from __init__ isn't importable
我有以下包結構:
module_installer/
|-- module_installer
| `-- __init__.py
`-- setup.py
設置文件
from setuptools import setup
setup(name='module_installer')
模塊安裝程序/__init__.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)
Grepping pip freeze
for module-installer
顯示軟件包已成功安裝。
瀏覽文件包不會顯示已安裝的包:
$ 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
:
setup(
# ...
packages=['module_installer'],
# ...
)
為了避免手動列出軟件包, setuptools提供了以下實用功能:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.