用pip打包后出现ModuleNotFoundError

用户3853136

从程序包的根目录ModuleNotFoundError: No module named 'helpers'运行后执行命令提示符脚本时,为什么会收到pip3 install .的位置helpers是,c:\users\username\appdata\local\programs\python\python36-32\lib\site-packages\mypackage\helpers.py所以我如何让程序在那看?

PS C:\> mypackage
Traceback (most recent call last):
  File "C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts\mypackage-script.py", line 11, in <module>
    load_entry_point('mypackage==0.1.2', 'console_scripts', 'mypackage')()
  File "c:\users\username\appdata\local\programs\python\python36-32\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\username\appdata\local\programs\python\python36-32\lib\site-packages\pkg_resources\__init__.py", line 2755, in load_entry_point
    return ep.load()
  File "c:\users\username\appdata\local\programs\python\python36-32\lib\site-packages\pkg_resources\__init__.py", line 2408, in load
    return self.resolve()
  File "c:\users\username\appdata\local\programs\python\python36-32\lib\site-packages\pkg_resources\__init__.py", line 2414, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "c:\users\username\appdata\local\programs\python\python36-32\lib\site-packages\mypackage\__init__.py", line 16, in <module>
    import helpers as h
ModuleNotFoundError: No module named 'helpers'

这是源代码树:

PS C:\Users\username\source\repos\mypackage> tree /F
Folder PATH listing for volume mydisk
Volume serial number is 01234-A321
C:.
│   .gitignore
│   COPYING
│   MANIFEST.in
│   README.rst
│   setup.py
│
├───mypackage
│   │   helpers.py
│   │   __init__.py
│   │
│   └───__pycache__
│           helpers.cpython-36.pyc
│           __init__.cpython-36.pyc
│
└───tests
        itsatrap.py
        __init__.py

这是setup.py:

PS C:\Users\username\source\repos\mypackage> cat setup.py
from setuptools import setup, find_packages
from codecs import open
from os import path

path_to_here = path.abspath(path.dirname(__file__))

with open(path.join(path_to_here, 'README.rst'), encoding='utf-8') as readme_file:
  readme = readme_file.read()

with open(path.join(path_to_here, 'COPYING'), encoding='utf-8') as license_file:
  license = license_file.read()


setup(
  name = 'mypackage',
  version = '0.1.2',
  license=license,
  description = 'Who knows',
  long_description = readme,
  url = 'https://github.com/user/mypackage',
  keywords = ['help!'],
  packages = find_packages(exclude=['contrib', 'docs', 'tests']),
  install_requires = ['matplotlib','numpy'],
  extras_require = {
      'dev': [''],
      'test': [''],
  },
  entry_points = {
      'console_scripts': [
          'mypackage=mypackage:main'
      ],
  },
)

任何帮助表示赞赏。用Python打包对我来说是新领域!python mypackage/__init__.py从程序包的根目录执行此程序时,它可以正确运行

博士

在Python 3中,所有导入都是绝对的。使用完整路径从包中导入模块:

from mypackage import helpers as h

要执行相对导入,请明确地执行此操作:

from . import helpers as h

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在venv上安装pip后出现ModuleNotFoundError

在Python 3.6中使用setuptools打包后出现ModuleNotFoundError

使用 setup.py 从 pip 安装后出现 ModuleNotFoundError

在 Google Colaboratory 中成功安装 pip 后出现 ModuleNotFoundError

pip成功安装后:ModuleNotFoundError

成功 pip 安装后的 ModuleNotFoundError

打包Python代码后出现NameError

pip 安装成功后:ModuleNotFoundError

重新打包最初通过pip安装的修改后的库

在 Docker 构建中使用 pip install 时出现 ModuleNotFoundError

pip ModuleNotFoundError-设置路径后在runpy中

ModuleNotFoundError:pip安装后没有名为“ requests”的模块

升级pip后出现错误消息

成功安装pip后出现ImportError

用pyinstaller打包后在pyside中的qwebview出错

在python中安装后使用tqdm时出现ModuleNotFoundError

使用setuptools打包并用pip安装后,Python代码看不到数据文件

用Chrome执行Selenium后出现错误

重新安装后出现Python-pip错误

在命令行上使用“pip”安装 Python 模块后,来自 Visual Studio 的 ModuleNotFoundError

Ubuntu 18.04“ pip install boto3”之后出现“ ModuleNotFoundError:没有名为'boto3'的模块”吗?

Maven打包后发生错误

TLS打包后的神秘字节

使用venv时出现ModuleNotFoundError

运行 makemigration 时出现 ModuleNotFoundError

打包 Python 項目時出現 ModuleNotFoundError

错误安装KIVY:为什么执行后出现错误:“ python -m pip install kivy”?

使用Cuda 10安装pip tensorflow-gpu后出现错误

在Ubuntu 18.04中删除rabbitmq后使用pip安装python包时出现奇怪的异常