Python Development Mode: ModuleNotFoundError: No module named xxxx
Python Development Mode: ModuleNotFoundError: No module named xxxx
我在 python 中有一个项目,如果通过 "python do.py" 调用它就可以正常工作,但是当我在开发模式下安装它并且脚本导入我的模块时,我得到一个 "ModuleNotFoundError".这是我的 setup.py
from setuptools import setup, find_packages
with open('README.rst') as f:
readme = f.read()
with open('LICENSE') as f:
license = f.read()
setup(
name='do-pack',
version='0.1dev',
description='A command-line tool to create python packages',
long_description=readme,
author='Carlos Montecinos Geisse',
author_email='carlos.w.montecinos@gmail.com',
url='https://github.com/wilfredinni/do-pack',
license=license,
packages=find_packages(exclude=('tests', 'docs')),
include_package_data=True,
install_requires=['click'],
python_requires='>=3',
entry_points={
'console_scripts': [
'do = do.do:main',
]
},
)
这是结构(主要和模块在 do/ 中):
[树][1]
这是我使用python时的调用 do.py:
(python-cli) λ python do.py
Usage: do.py [OPTIONS] COMMAND [ARGS]...
Simple CLI based script to make your Repository Structure.
Options:
--help Show this message and exit.
Commands:
assistant A step by step assistant.
create creates an empty proyect structure.
并且,这是我 运行 在开发模式下的输出:
(python-cli) λ do
Traceback (most recent call last):
File "C:\Users\carlo\Envs\python-cli\Scripts\do-script.py", line 11, in <module>
load_entry_point('do-pack', 'console_scripts', 'do')()
File "c:\users\carlo\envs\python-cli\lib\site-packages\pkg_resources\__init__.py", line 572, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "c:\users\carlo\envs\python-cli\lib\site-packages\pkg_resources\__init__.py", line 2755, in load_entry_point
return ep.load()
File "c:\users\carlo\envs\python-cli\lib\site-packages\pkg_resources\__init__.py", line 2408, in load
return self.resolve()
File "c:\users\carlo\envs\python-cli\lib\site-packages\pkg_resources\__init__.py", line 2414, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "c:\dropbox\dropbox\projects\python\do-pack\do\do.py", line 3, in <module>
import skeleton
ModuleNotFoundError: No module named 'skeleton'
谢谢。
- 确保
do
文件夹中有一个 __init__.py
文件。
2。将 'do' 添加到 setup.py 中的 packages=
kwarg
看起来你正在处理 find_packages()
工作示例
+ app
|+ do
|+ __init__.py
|+ do.py
setup.py
从设置工具导入设置
setup(
name="cliapp",
version='0.1',
packages=['do'],
entry_points='''
[console_scripts]
do=do.do:run
''',
)
do.py
def run():
print('Completed')
从 app/ 文件夹,安装并 运行:
>>> pip install .
>>> do
Completed
更新
我在本地 运行 你的代码,看起来它可能只是你代码中的一个 python relative/absolute 导入问题。
如果您使用完全绝对导入,它应该可以工作:
do.py
而不是
import skeleton
import licenses
import setup_config
您需要使用绝对或相对包导入
# Absolute
from do import skeleton
from do import licenses
from do import setup_config
# Relative
from . import skeleton
from . import licenses
from . import setup_config
我在 python 中有一个项目,如果通过 "python do.py" 调用它就可以正常工作,但是当我在开发模式下安装它并且脚本导入我的模块时,我得到一个 "ModuleNotFoundError".这是我的 setup.py
from setuptools import setup, find_packages
with open('README.rst') as f:
readme = f.read()
with open('LICENSE') as f:
license = f.read()
setup(
name='do-pack',
version='0.1dev',
description='A command-line tool to create python packages',
long_description=readme,
author='Carlos Montecinos Geisse',
author_email='carlos.w.montecinos@gmail.com',
url='https://github.com/wilfredinni/do-pack',
license=license,
packages=find_packages(exclude=('tests', 'docs')),
include_package_data=True,
install_requires=['click'],
python_requires='>=3',
entry_points={
'console_scripts': [
'do = do.do:main',
]
},
)
这是结构(主要和模块在 do/ 中):
[树][1]
这是我使用python时的调用 do.py:
(python-cli) λ python do.py
Usage: do.py [OPTIONS] COMMAND [ARGS]...
Simple CLI based script to make your Repository Structure.
Options:
--help Show this message and exit.
Commands:
assistant A step by step assistant.
create creates an empty proyect structure.
并且,这是我 运行 在开发模式下的输出:
(python-cli) λ do
Traceback (most recent call last):
File "C:\Users\carlo\Envs\python-cli\Scripts\do-script.py", line 11, in <module>
load_entry_point('do-pack', 'console_scripts', 'do')()
File "c:\users\carlo\envs\python-cli\lib\site-packages\pkg_resources\__init__.py", line 572, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "c:\users\carlo\envs\python-cli\lib\site-packages\pkg_resources\__init__.py", line 2755, in load_entry_point
return ep.load()
File "c:\users\carlo\envs\python-cli\lib\site-packages\pkg_resources\__init__.py", line 2408, in load
return self.resolve()
File "c:\users\carlo\envs\python-cli\lib\site-packages\pkg_resources\__init__.py", line 2414, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "c:\dropbox\dropbox\projects\python\do-pack\do\do.py", line 3, in <module>
import skeleton
ModuleNotFoundError: No module named 'skeleton'
谢谢。
- 确保
do
文件夹中有一个__init__.py
文件。2。将 'do' 添加到 setup.py中的packages=
kwarg 看起来你正在处理find_packages()
工作示例
+ app
|+ do
|+ __init__.py
|+ do.py
setup.py
从设置工具导入设置
setup(
name="cliapp",
version='0.1',
packages=['do'],
entry_points='''
[console_scripts]
do=do.do:run
''',
)
do.py
def run():
print('Completed')
从 app/ 文件夹,安装并 运行:
>>> pip install .
>>> do
Completed
更新
我在本地 运行 你的代码,看起来它可能只是你代码中的一个 python relative/absolute 导入问题。
如果您使用完全绝对导入,它应该可以工作:
do.py
而不是
import skeleton
import licenses
import setup_config
您需要使用绝对或相对包导入
# Absolute
from do import skeleton
from do import licenses
from do import setup_config
# Relative
from . import skeleton
from . import licenses
from . import setup_config