Interview question
What is the difference between pip install and pip install -e (editable install)? pip install और pip install -e (editable install) में क्या अंतर है?
Answer
| Command | Behavior |
|---|---|
| pip install package | Copies a snapshot of the package's code into site-packages |
| pip install -e . | Links to the LOCAL source directory - changes to the code are reflected immediately, no reinstall needed |
# Regular install - copies package files
pip install requests
# Code lives in site-packages, editing it there has no effect on new environments
# Editable install - for developing your OWN package locally
# Given a project structure with setup.py or pyproject.toml:
# my_package/
# setup.py
# my_package/
# __init__.py
# core.py
pip install -e . # installs a LINK to this directory, not a copy
# Now editing my_package/core.py takes effect IMMEDIATELY
# in any other code that imports my_package, without reinstalling
import my_package
my_package.core.some_function() # reflects the latest saved changes
# Why this matters: during development of a library, you'd otherwise
# have to reinstall after every change to test it in a dependent project
# Minimal setup.py needed for editable installs
# setup.py:
# from setuptools import setup, find_packages
# setup(name='my_package', version='0.1', packages=find_packages())| Command | व्यवहार |
|---|---|
| pip install package | Package code का snapshot site-packages में copy करता है |
| pip install -e . | Local source directory को link करता है - code बदलने पर तुरंत reflect होता है |
# Regular install
pip install requests
# Editable install - अपने package को locally develop करने के लिए
# my_package/
# setup.py
# my_package/
# __init__.py
# core.py
pip install -e . # copy नहीं, link install करता है
# अब my_package/core.py edit करना तुरंत effect करता है
import my_package
my_package.core.some_function()
# क्यों important है: library develop करते समय बार-बार reinstall
# नहीं करना पड़ता
# setup.py:
# from setuptools import setup, find_packages
# setup(name='my_package', version='0.1', packages=find_packages())Was this answer clear?