Title: Python pip — Container ImportError from Global Packages
Open Graph Title: Python pip — Container ImportError from Global Packages
Description: Container exited with ImportError: cannot import name 'Session' from 'requests' due to global packages. Fix by using venv and pip-compile pinning.
Open Graph Description: Container exited with ImportError: cannot import name 'Session' from 'requests' due to global packages. Fix by using venv and pip-compile pinning.
Opengraph URL: https://thecodeforge.io/python/python-packaging-pip/
Domain: thecodeforge.io
{
"@context": "https://schema.org",
"@type": "TechArticle",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://thecodeforge.io/python/python-packaging-pip/"
},
"headline": "Python pip — Container ImportError from Global Packages",
"description": "Container exited with ImportError: cannot import name 'Session' from 'requests' due to global packages. Fix by using venv and pip-compile pinning.",
"keywords": "Python pip — Container ImportError from Global Packages, Python, Intermediate, Advanced Python, Container exited with ImportError: cannot import name 'Session' from 'requests' due to global packages. Fix by using venv and pip-compile pinning.",
"proficiencyLevel": "Intermediate",
"author": {
"@type": "Person",
"@id": "https://thecodeforge.io/about/#naren",
"name": "Naren",
"url": "https://thecodeforge.io/about/"
},
"publisher": {
"@type": "Organization",
"@id": "https://thecodeforge.io/#org",
"name": "TheCodeForge",
"url": "https://thecodeforge.io",
"logo": {"@type": "ImageObject", "url": "https://thecodeforge.io/assets/og-image.png"}
},
"datePublished": "2026-03-05T00:00:00+00:00",
"dateModified": "2026-09-26T00:00:00+00:00",
"url": "https://thecodeforge.io/python/python-packaging-pip/",
"inLanguage": "en",
"educationalLevel": "Intermediate",
"image": "https://thecodeforge.io/assets/og-image.png",
"isPartOf": {"@id": "https://thecodeforge.io/#website"}
}
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{"@type": "ListItem", "position": 1, "name": "Home", "item": "https://thecodeforge.io/"},
{"@type": "ListItem", "position": 2, "name": "Python", "item": "https://thecodeforge.io/python/"},
{"@type": "ListItem", "position": 3, "name": "Python pip — Container ImportError from Global Packages", "item": "https://thecodeforge.io/python/python-packaging-pip/"}
]
}
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "What is the difference between pip install and pip install -e?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Regular `pip install .` copies your package files into site-packages — any changes you make to your source code after that are not reflected until you reinstall. `pip install -e .` (editable mode) installs the package in development mode by creating a link that points directly to your source folder — edit a file and the change is immediately live without reinstalling. Use -e during active development so you can test changes instantly. Use regular install for final testing and production deployments to ensure you're testing the actual installed package rather than a live source tree."
}
},
{
"@type": "Question",
"name": "Should I commit my virtual environment folder to Git?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Never. The venv folder contains compiled binary files that are specific to your operating system and CPU architecture — a venv created on macOS will not work on Linux, and vice versa. It can easily exceed 500MB for projects with heavy dependencies. It bloats your repository and will cause binary merge conflicts. Add 'venv/' and '.venv/' to your .gitignore immediately when starting any project. Commit requirements.txt or pyproject.toml instead — any developer can recreate the identical environment with two commands."
}
},
{
"@type": "Question",
"name": "What is the difference between install_requires in setup.py and dependencies in pyproject.toml?",
"acceptedAnswer": {
"@type": "Answer",
"text": "They're functionally equivalent — both declare the packages your library needs to work. The difference is in the file format and what it enables. pyproject.toml is the modern standard endorsed by PEP 517/518 and understood by all current build tools including pip, hatch, flit, poetry, and uv. setup.py's install_requires is the legacy approach and is actively being deprecated. For any project started in 2024 or later, use pyproject.toml. For existing projects using setup.py, migration is straightforward and the Python Packaging Authority recommends it."
}
},
{
"@type": "Question",
"name": "What is a wheel (.whl) file and why is it faster than installing from source?",
"acceptedAnswer": {
"@type": "Answer",
"text": "A wheel is a pre-built binary distribution in ZIP format (.whl) that pip can install by simply extracting files into site-packages — no compilation, no running setup code, no build tools required. Installing from a source distribution requires the build backend to compile the code on the user's machine, which takes seconds for pure Python packages and potentially minutes for packages with C or Rust extensions like numpy, pandas, or pydantic. Wheels make the typical install experience nearly instant and eliminate the need for users to have a compiler installed."
}
},
{
"@type": "Question",
"name": "How do optional dependency groups work in pyproject.toml?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Define them under [project.optional-dependencies] with a group name. For example: `dev = ['pytest>=7.0', 'black>=24.0']`. Users install the group with `pip install weather-fetcher[dev]`. Multiple groups are supported and can be combined: `pip install weather-fetcher[dev,docs]`. This keeps development and documentation tools out of your main dependency list, so end users only install what they actually need to use your package — not your testing framework or code formatter."
}
}
]
}
| og:type | website |
| og:image | https://thecodeforge.io/assets/og-image.png |
| og:image:width | 1200 |
| og:image:height | 630 |
Links:
Viewport: width=device-width, initial-scale=1.0
Robots: max-image-preview:large