简体   繁体   English

ModuleNotFoundError: 没有命名模块<modulename> pip安装后

[英]ModuleNotFoundError: No module named <modulename> after pip install

I do my first steps in python package distributions.我在 python 包分发中做了我的第一步。
Unfortunately, I have ModuleNotFoundError after successful install from pip.不幸的是,从 pip 成功安装后,我ModuleNotFoundError

My dirs layout is pretty simple:我的目录布局非常简单:

maindir
   |- setup.py
   |- pysoft
         |- __init__.py
         |- main.py
         |- pylib.py

main.py:主要.py:

import pylib


def main():
    print("main program")
    pylib.libfunc()


if __name__ == '__main__':
    main()

pylib.py: pylib.py:

def libfunc():
    print("lib func")

setup.py:设置.py:

import setuptools


setuptools.setup(
    name='pysoft',
    version='0.0.21',
    author='als',
    author_email='als@gnail.com',
    description='deploy tester',
    py_modules=['pylib'],
    packages=setuptools.find_packages(),
    python_requires='>=3.6',
    entry_points={
        'console_scripts': [
            'pysoft = pysoft.main:main',
        ],
    },
)

I do packaging and uploading to test.pypi.org :我打包并上传到test.pypi.org

python3 setup.py sdist bdist_wheel
python3 -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*

I setup and start new virtualenv and install my package:我设置并启动新的virtualenv并安装我的包:

 python3 -m pip install -i https://test.pypi.org/simple/ pysoft

Then I try to run it, but got error:然后我尝试运行它,但出现错误:

pysoft 
Traceback (most recent call last):
  File "/home/fat/buff/tt/bin/pysoft", line 5, in <module>
    from pysoft.main import main
  File "/home/fat/buff/tt/lib/python3.6/site-packages/pysoft/main.py", line 1, in <module>
    import pylib
ModuleNotFoundError: No module named 'pylib'

Could you figure out where I have wrong step?你能找出我哪里有错误的步骤吗?

You do import pylib as if said pylib is a top-level module or package.您确实import pylib ,就好像pylib是顶级模块或包一样。 But it's not — it's a submodule of the package pysoft .但事实并非如此——它是pysoft包的子模块。 For the proper import do:要正确导入,请执行以下操作:

from pysoft import pylib

py_modules=['pylib'] in your setup.py is ignored because setuptools cannot find top-level pylib.py . py_modules=['pylib']在你的setup.py ,是因为忽略setuptools无法找到顶级pylib.py But packages=setuptools.find_packages() works and include pysoft package into distributions.但是packages=setuptools.find_packages()可以工作并将pysoft包包含到发行版中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ModuleNotFoundError:pip安装后没有名为“请求”的模块 - ModuleNotFoundError: No module named 'requests' after pip install ModuleNotFoundError:使用“pip install numpy”后没有名为“numpy”的模块 - ModuleNotFoundError: No module named 'numpy' after using 'pip install numpy' ModuleNotFoundError:在pip安装pyserial之后,没有名为“ serial”的模块 - ModuleNotFoundError: No module named 'serial' after pip install pyserial pip安装后出现“ ModuleNotFoundError:没有名为“ PyQt5”的模块” - “ModuleNotFoundError: No module named 'PyQt5'” after pip install ModuleNotFoundError: 执行 pip install xyz 后没有名为“xyz”的模块 - ModuleNotFoundError: No module named 'xyz' " after doing pip install xyz pip安装错误:ModuleNotFoundError没有名为“ setuptools”的模块 - pip install error: ModuleNotFoundError No module named 'setuptools' Python 错误:ModuleNotFoundError:没有名为“的模块”<moduleName> &#39; - Python Error: ModuleNotFoundError: No module named '<moduleName>' ModuleNotFoundError:pip安装后没有名为“ tensorflow”的模块-遵循TF官方安装文档 - ModuleNotFoundError: No module named 'tensorflow' after pip install — following TF official install docs pip 安装后 ModuleNotFoundError。 (自定义模块) - ModuleNotFoundError after pip install . (custom module) Ubuntu 18.04“ModuleNotFoundError:在“pip install boto3”之后没有名为“boto3”的模块? - Ubuntu 18.04 "ModuleNotFoundError: No module named 'boto3'" after "pip install boto3"?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM