Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What needs to be in a setup.py to create a wheel?

I have a Python project prj that we can describe as a collection of folders and a requirements.txt file:

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

I want to package this project so that it can be easily installed on other computers. My understanding is that I need to add a setup.py file, but there are few things that I do not understand.

What should I write in the setup.py file in order to create a wheel package? Can you provide an example of the file and of the commands required to pack the project?

EDIT:

I have this 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$    

and I have run:

   (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$       

but I do not see any whl file. What's wrong?

like image 352
Donbeo Avatar asked Feb 21 '17 13:02

Donbeo


People also ask

What should setup py contain?

The setup.py file may be the most significant file that should be placed at the root of the Python project directory. It primarily serves two purposes: It includes choices and metadata about the program, such as the package name, version, author, license, minimal dependencies, entry points, data files, and so on.

What does a Python wheel contain?

A Python . whl file is essentially a ZIP ( . zip ) archive with a specially crafted filename that tells installers what Python versions and platforms the wheel will support. A wheel is a type of built distribution.


1 Answers

You don't need to write anything special in your setup.py to be able to create a wheel. As long as your setup.py is using setuptools (which it should be anyway), you just write a normal setup.py, install the wheel package on your system, and run python setup.py bdist_wheel.

like image 198
jwodder Avatar answered Oct 16 '22 10:10

jwodder