gpt4 book ai didi

python - Windows python setup.py install 不分发模块 python 文件

转载 作者:行者123 更新时间:2023-12-01 08:37:18 24 4
gpt4 key购买 nike

我已经在网上搜索了几个小时,但我无法找出我做错了什么。我通过 python setup.py install 安装我自己的包。这是可行的,尽管我无法在系统上的任何地方导入 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")

设置.py

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

命令行:python setup.py安装

这样做不会引发任何错误。但是当我查看站点包中安装的.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.pydevelop它似乎确实有效。然后我就可以在整个系统中访问该包。

最佳答案

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

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

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

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

from setuptools import setup, find_packages

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

关于python - Windows python setup.py install 不分发模块 python 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53656037/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com