Deep Dive into Python Package Management: setup.py install vs develop Commands

Nov 28, 2025 · Programming · 26 views · 7.8

Keywords: Python Package Management | setuptools | Development Mode

Abstract: This article provides an in-depth analysis of the core differences and application scenarios between setup.py install and develop commands in Python package management. Through detailed examination of both installation modes' working principles, combined with setuptools official documentation and practical development cases, it systematically explains that install command suits stable third-party package deployment while develop command is specifically designed for development phases, supporting real-time code modification and testing. The article also demonstrates practical applications of develop mode in complex development environments through NixOS configuration examples, offering comprehensive technical guidance for Python developers.

Fundamental Concepts of Python Package Management

In the Python development ecosystem, package management serves as a core component of project construction and deployment. setuptools, as Python's standard packaging toolset, provides various installation commands to meet different scenario requirements. Among these, python setup.py install and python setup.py develop are two commands with similar functionalities but distinct purposes. Understanding their fundamental differences is crucial for efficient development practices.

install Command: Stable Environment Deployment

The python setup.py install command is designed for production environments or stable dependency installations. When executing this command, setuptools performs a complete package installation process: first building the package distribution files, then copying the package files to the Python environment's site-packages directory. This process creates a static copy of the package, completely separating the installed package from the source code.

From a technical implementation perspective, the core operations of the install command include:

# Simulating core logic of install command
import shutil
import os
from distutils.core import setup

# Build package files
setup(name='example_package',
      version='1.0',
      packages=['example'])

# Copy to site-packages
site_packages_path = get_python_lib()
build_dir = 'build/lib'
if os.path.exists(build_dir):
    for item in os.listdir(build_dir):
        src_path = os.path.join(build_dir, item)
        dst_path = os.path.join(site_packages_path, item)
        if os.path.isdir(src_path):
            shutil.copytree(src_path, dst_path)
        else:
            shutil.copy2(src_path, dst_path)

This installation approach is suitable for deploying stable versions of third-party libraries. Once installed, modifications to the source code do not affect the installed package, ensuring environment stability.

develop Command: Development Mode Innovation

The python setup.py develop command is specifically designed for development phases, employing a completely different installation strategy. Unlike the copy operation of the install command, develop command creates special link files (.egg-link) in the site-packages directory that point to the project's source code directory.

The technical implementation mechanism of development mode is as follows:

# Simulating core logic of develop command
import os
import site

# Get project source code path
project_path = os.path.abspath('.')

# Create .egg-link file in site-packages
site_packages = site.getsitepackages()[0]
egg_link_path = os.path.join(site_packages, 'example_package.egg-link')

with open(egg_link_path, 'w') as f:
    f.write(project_path + '\n')
    f.write('.')

# Update easy-install.pth file to include project path
pth_file = os.path.join(site_packages, 'easy-install.pth')
with open(pth_file, 'a') as f:
    f.write(project_path + '\n')

This linking mechanism allows the Python interpreter to directly read files from the source code directory when importing packages. Any modifications made by developers take effect immediately without requiring repeated installation commands. This real-time feedback characteristic significantly improves development efficiency, particularly suitable for projects requiring frequent modifications and testing.

Comparative Analysis of Application Scenarios

Based on the technical characteristics of both commands, their applicable scenarios demonstrate clear differences:

install Command Application Scenarios:

develop Command Application Scenarios:

Modern Package Management Best Practices

While directly calling setup.py remains valid in certain scenarios, modern Python development increasingly recommends using pip for package management operations:

# Standard installation (equivalent to setup.py install)
pip install .

# Development mode installation (equivalent to setup.py develop)
pip install -e .

The advantages of using pip include better dependency resolution, version conflict handling, and uninstallation management. pip can properly process package metadata, avoiding dependency issues that may arise from directly calling setup.py.

Practical Case in Complex Environments

Referencing practical applications in NixOS environments, develop mode demonstrates unique value in complex development workflows. Within NixOS's declarative configuration environment, combining buildPythonPackage with local source code paths enables similar development mode installation:

# Nix expression configuration example
with import <nixpkgs> {};
let
  mypkg = python37Packages.buildPythonPackage rec {
    name = "mypkg";
    src = ./.;  # Pointing to local source code directory
    propagatedBuildInputs = with python37Packages; [pandas];
  };
in mypkg

This configuration automatically activates development mode in nix-shell environments, generating .egg-link files pointing to project source code. However, practice requires attention to path configuration completeness, ensuring Python can correctly resolve package import paths.

Technical Details and Considerations

Development mode implementation relies on Python's path resolution mechanism. .egg-link files contain absolute paths to source code directories, which Python checks preferentially during package imports. While this mechanism provides convenience, it also introduces potential issues:

In practical development, combining develop mode with virtual environments is recommended to ensure project dependency isolation and reproducibility.

Conclusion and Future Outlook

The python setup.py install and develop commands represent two different philosophies in Python package management: stable deployment versus agile development. Understanding their underlying mechanisms and applicable scenarios enables developers to choose appropriate tools based on specific requirements. As Python's packaging ecosystem continues to evolve, although direct setup.py usage scenarios are gradually decreasing, these core concepts remain fundamental to understanding modern Python development toolchains.

Looking forward, with the proliferation of new tools like python -m build, the concept of development mode will continue to evolve, but its core value—providing rapid development feedback cycles—will remain a key element of efficient software development.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.