Skip to main content
 首页 » 编程设计

python之pip 安装抛出错误之没有 setup.py

2025年04月02日13soundcode

我通过以下结构的 setup.py 在 pypi.python.org 上创建了包:

from setuptools import setup, find_packages 
setup( 
name='my_project', 
version='1.0.0', 
packages=find_packages(), 
long_description='My project', 
package_data={ 
    "MyProject.libraries": [ 
        "darwin/lib.so", 
        "linux/lib.so", 
        "windows/lib.pyd", 
    ], 
}, 

)

我的目录结构是

myproject/ 
--libraries/ 
----__init__.py 
----darwin/ 
------lib.so 
----linux/ 
------lib.so 
----windows/ 
------lib.pyd 
readme 
setup.py  
other files 

使用pip安装时:

pip install my_project 

我得到错误

  Failed building wheel for myproject 
  Running setup.py clean for myproject 
  Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-fsZH4w/myproject/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" clean --all: 
  Traceback (most recent call last): 
    File "<string>", line 1, in <module> 
  IOError: [Errno 2] No such file or directory: '/private/tmp/pip-build-fsZH4w/myproject/setup.py' 

但是软件包已安装并且工作正常。

我发现了类似的问题 pip installation throws IOerror - no setup.py但是我的 setup.py 在根包目录中,所以我认为这不是同一个问题。

请您参考如下方法:

看起来是关于具有以下规则的命名约定

  • 全部小写
  • 在pypi上应该是唯一的
  • 下划线分隔或根本没有单词分隔符(不要使用连字符)

这是 python 包的示例结构

uniq_package/ 
  uniq_package/ 
    __init__.py 
  linux/ 
    lib.so 
  darwin/ 
    lib.so 
  windows/ 
    lib.pyd 
  setup.py