Windows python setup.py 安装不分发模块 python 文件

Windows python setup.py install does not distribute module python files

我在网上搜索了几个小时,但我无法找出我做错了什么。 我通过 python setup.py install 安装自己的包。这有效,虽然我无法 import mymodule 系统上的任何地方。

目录如下所示:

C:\PyDev\simple_test\mymodule
C:\PyDev\simple_test\setup.py
C:\PyDev\simple_test\mymodule\__init__.py

有:__init__.py

def sayhello():
    print("Hello")

setup.py

from setuptools import setup
setup(
    name='mymodule'
)

命令行: python setup.py install

它没有引发任何错误。但是当我查看站点包中已安装的 .egg 文件时,它只包含一个 EGG-INFO 目录,没有任何源文件...

这是安装命令的输出:

(venv) C:\PyDev\simple_test>python setup.py install
running install
running bdist_egg
running egg_info
creating mymodule.egg-info
writing mymodule.egg-info\PKG-INFO
writing dependency_links to mymodule.egg-info\dependency_links.txt
writing top-level names to mymodule.egg-info\top_level.txt
writing manifest file 'mymodule.egg-info\SOURCES.txt'
reading manifest file 'mymodule.egg-info\SOURCES.txt'
writing manifest file 'mymodule.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
warning: install_lib: 'build\lib' does not exist -- no Python modules to install

creating build
creating build\bdist.win-amd64
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\EGG-INFO
copying mymodule.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying mymodule.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying mymodule.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying mymodule.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist\mymodule-0.0.0-py3.7.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing mymodule-0.0.0-py3.7.egg
Copying mymodule-0.0.0-py3.7.egg to c:\pydev\simple_test\venv\lib\site-packages
Adding mymodule 0.0.0 to easy-install.pth file

Installed c:\pydev\simple_test\venv\lib\site-packages\mymodule-0.0.0-py3.7.egg
Processing dependencies for mymodule==0.0.0
Finished processing dependencies for mymodule==0.0.0

如果我 运行 python setup.py develop 它似乎确实有效。然后我就可以在我的整个系统中访问这个包了。

我不太确定原因是什么,但有两点很突出:

  • 您没有在 setup.py
  • 中指定 packages
  • 模块目录的名称与主目录的名称不同

我可以想象这两个因素的结合会导致 setuptools 无法找到您的来源。

您可以尝试重命名您的 src 目录或将您的 setup.py 更改为

from setuptools import setup, find_packages

setup(name='mymodule',
      packages=find_packages()
)