编程语言
首页 > 编程语言> > python – 在setup.py中创建一个轮子需要什么?

python – 在setup.py中创建一个轮子需要什么?

作者:互联网

我有一个Python项目prj,我们可以将其描述为文件夹的集合
和requirements.txt文件:

[prj/fold1, prj/fold2,..., prj/foldN, prj/requirements.txt]

我想打包这个项目,以便它可以很容易地安装在其他计算机上.我的理解是我需要添加一个setup.py文件,但有些东西我不明白.

我应该在setup.py文件中写什么才能创建一个wheel包?您能提供打包项目所需文件和命令的示例吗?

编辑:

我有这个setup.py:

(virtual_env_test) lpuggini@lpuggini-T3420:~/mlp/trunk$cat setup.py                                                                                                                                               

    from setuptools import setup                                                                                                                                                                                       


    setup(name='mlearn',                                                                                                                                                                                               
          version='0.1',                                                                                                                                                                                               
          description='Tool to learn ip addresses on a network.',                                                                                                                                                      
          author='Corvil',                                                                                                                                                                                             
          author_email='...',                                                                                                                                                                                          
          packages=['common', 'iplearning', 'applearning', 'peerspeak'],                                                                                                                                               
          package_dir={                                                                                                                                                                                                
              'common':'common',                                                                                                                                                                                       
              'iplearning': 'iplearning',                                                                                                                                                                              
              'applearning': 'applearning',                                                                                                                                                                            
              'peerspeak':'peers_peak'},                                                                                                                                                                               
          )                                                                                                                                                                                                            
    (virtual_env_test) lpuggini@lpuggini-T3420:~/mlp/trunk$   

我跑了:

   (virtual_env_test) lpuggini@lpuggini-T3420:~/mlp/trunk$python setup.py bdist_wheel                                                                                                                                
    running bdist_wheel                                                                                                                                                                                                
    running build                                                                                                                                                                                                      
    running build_py                                                                                                                                                                                                   
    package init file 'iplearning/__init__.py' not found (or not a regular file)                                                                                                                                       
    package init file 'applearning/__init__.py' not found (or not a regular file)                                                                                                                                      
    package init file 'peers_peak/__init__.py' not found (or not a regular file)                                                                                                                                       
    creating build/lib/peerspeak                                                                                                                                                                                       
    copying peers_peak/peers_peak.py -> build/lib/peerspeak                                                                                                                                                            
    copying peers_peak/peers_peak_report.py -> build/lib/peerspeak                                                                                                                                                     
    installing to build/bdist.linux-x86_64/wheel                                                                                                                                                                       
    running install                                                                                                                                                                                                    
    running install_lib                                                                                                                                                                                                
    creating build/bdist.linux-x86_64                                                                                                                                                                                  
    creating build/bdist.linux-x86_64/wheel                                                                                                                                                                            
    creating build/bdist.linux-x86_64/wheel/peerspeak                                                                                                                                                                  
    copying build/lib/peerspeak/peers_peak.py -> build/bdist.linux-x86_64/wheel/peerspeak                                                                                                                              
    copying build/lib/peerspeak/peers_peak_report.py -> build/bdist.linux-x86_64/wheel/peerspeak                                                                                                                       
    creating build/bdist.linux-x86_64/wheel/iplearning                                                                                                                                                                 
    copying build/lib/iplearning/iplearning_report.py -> build/bdist.linux-x86_64/wheel/iplearning                                                                                                                     
    copying build/lib/iplearning/learnips.py -> build/bdist.linux-x86_64/wheel/iplearning                                                                                                                              
    copying build/lib/iplearning/disttest.py -> build/bdist.linux-x86_64/wheel/iplearning                                                                                                                              
    copying build/lib/iplearning/detect_new_ips.py -> build/bdist.linux-x86_64/wheel/iplearning                                                                                                                        
    copying build/lib/iplearning/setup.py -> build/bdist.linux-x86_64/wheel/iplearning                                                                                                                                 
    creating build/bdist.linux-x86_64/wheel/applearning                                                                                                                                                                
    copying build/lib/applearning/detect_new_apps.py -> build/bdist.linux-x86_64/wheel/applearning                                                                                                                     
    creating build/bdist.linux-x86_64/wheel/common                                                                                                                                                                     
    copying build/lib/common/__init__.py -> build/bdist.linux-x86_64/wheel/common                                                                                                                                      
    copying build/lib/common/utils.py -> build/bdist.linux-x86_64/wheel/common                                                                                                                                         
    running install_egg_info                                                                                                                                                                                           
    running egg_info                                                                                                                                                                                                   
    creating mlearn.egg-info                                                                                                                                                                                           
    writing top-level names to mlearn.egg-info/top_level.txt                                                                                                                                                           
    writing mlearn.egg-info/PKG-INFO                                                                                                                                                                                   
    writing dependency_links to mlearn.egg-info/dependency_links.txt                                                                                                                                                   
    writing manifest file 'mlearn.egg-info/SOURCES.txt'                                                                                                                                                                
    reading manifest file 'mlearn.egg-info/SOURCES.txt'                                                                                                                                                                
    writing manifest file 'mlearn.egg-info/SOURCES.txt'                                                                                                                                                                
    Copying mlearn.egg-info to build/bdist.linux-x86_64/wheel/mlearn-0.1-py3.5.egg-info                                                                                                                                
    running install_scripts                                                                                                                                                                                            
    creating build/bdist.linux-x86_64/wheel/mlearn-0.1.dist-info/WHEEL                                                                                                                                                 
    (virtual_env_test) lpuggini@lpuggini-T3420:~/mlp/trunk$      

但我没有看到任何whl文件.怎么了?

解决方法:

您无需在setup.py中编写任何特殊内容即可创建轮子.只要你的setup.py使用的是setuptools(无论如何都是这样),你只需编写一个正常的setup.py,在你的系统上安装wheel包,然后运行python setup.py bdist_wheel.

标签:python,setup-py,python-wheel
来源: https://codeday.me/bug/20190608/1197698.html