- Open terminal or command prompt.
- Navigate to location where you want to create your project directory.
- Create main directory (replace
<main_directory>
with desired directory name):mkdir <main_directory> cd <main_directory>
- Create subdirectory with same name as code file (replace
<code_file_name>
with desired code file name):mkdir <code_file_name> cd <code_file_name>
- Create Python code file inside subdirectory (replace
<code_file_name>.py
with actual code file name):touch <code_file_name>.py
- Inside subdirectory, create
__init__.py
file:touch __init__.py
- Open
__init__.py
and add all necessary imports from your code. For example:from .<code_file_name> import *
- Navigate back to main directory:
cd ..
- Create
setup.py
file:touch setup.py
- Open
setup.py
and add the following content (replace placeholders with actual values):from setuptools import setup, find_packages setup( name='<program_name>', version='<version_of_the_code>', packages=find_packages(), description='<description_of_what_the_package_is_doing>', author='<organization_or_person>', author_email='<email_of_creator>', install_requires=[ # List your package dependencies here '', ], )
- Open command prompt as an administrator.
- Install
wheel
andsetuptools
:pip install wheel setuptools
- Change to main directory of code:
cd <main_directory>
- Run following command to build the distribution:
python setup.py bdist_wheel
After running the build command, you should see the following directories in your main directory:
build
dist
<projectname>.egg-info
- ModuleNotFoundError: If you encounter an error like
ModuleNotFoundError: No module named [package_name]
, ensure that the package is installed in your Python environment. You can verify with:pip show [package_name]
Congrats! You've structured a Python project for distribution!