pip & venv & conda
This commit is contained in:
33
environment.yml
Normal file
33
environment.yml
Normal file
@ -0,0 +1,33 @@
|
||||
name: ani2
|
||||
channels:
|
||||
- defaults
|
||||
dependencies:
|
||||
- brotlicffi=1.0.9.2=py39h5da7b33_1
|
||||
- bzip2=1.0.8=h2bbff1b_6
|
||||
- ca-certificates=2025.7.15=haa95532_0
|
||||
- certifi=2025.8.3=py39haa95532_0
|
||||
- cffi=1.17.1=py39h827c3e9_1
|
||||
- charset-normalizer=3.3.2=pyhd3eb1b0_0
|
||||
- expat=2.7.1=h8ddb27b_0
|
||||
- idna=3.7=py39haa95532_0
|
||||
- libffi=3.4.4=hd77b12b_1
|
||||
- openssl=3.0.17=h35632f6_0
|
||||
- pip=25.1=pyhc872135_2
|
||||
- pycparser=2.21=pyhd3eb1b0_0
|
||||
- pysocks=1.7.1=py39haa95532_0
|
||||
- python=3.9.23=h716150d_0
|
||||
- requests=2.32.4=py39haa95532_0
|
||||
- setuptools=78.1.1=py39haa95532_0
|
||||
- sqlite=3.50.2=hda9a48d_1
|
||||
- tk=8.6.15=hf199647_0
|
||||
- tzdata=2025b=h04d1e81_0
|
||||
- ucrt=10.0.22621.0=haa95532_0
|
||||
- urllib3=2.5.0=py39haa95532_0
|
||||
- vc=14.3=h2df5915_10
|
||||
- vc14_runtime=14.44.35208=h4927774_10
|
||||
- vs2015_runtime=14.44.35208=ha6b5a95_10
|
||||
- wheel=0.45.1=py39haa95532_0
|
||||
- win_inet_pton=1.1.0=py39haa95532_0
|
||||
- xz=5.6.4=h4754444_1
|
||||
- zlib=1.2.13=h8cc25b3_1
|
||||
prefix: C:\Users\anivk\miniconda3\envs\ani2
|
13
requirements.txt
Normal file
13
requirements.txt
Normal file
@ -0,0 +1,13 @@
|
||||
brotlicffi==1.0.9.2
|
||||
certifi==2025.8.3
|
||||
cffi==1.17.1
|
||||
charset-normalizer==3.3.2
|
||||
idna==3.7
|
||||
pip==25.1
|
||||
pycparser==2.21
|
||||
PySocks==1.7.1
|
||||
requests==2.32.4
|
||||
setuptools==78.1.1
|
||||
urllib3==2.5.0
|
||||
wheel==0.45.1
|
||||
win-inet-pton==1.1.0
|
165
src/intermediate/enviroinment.md
Normal file
165
src/intermediate/enviroinment.md
Normal file
@ -0,0 +1,165 @@
|
||||
Instead of polluting global Python, you create an isolated environment for each project:
|
||||
|
||||
```bash
|
||||
# Create
|
||||
python -m venv venv
|
||||
|
||||
# Activate
|
||||
source venv/bin/activate # Linux/Mac
|
||||
venv\Scripts\activate # Windows
|
||||
|
||||
# Install inside venv (isolated)
|
||||
pip install flask
|
||||
|
||||
pip show flask
|
||||
|
||||
```
|
||||
|
||||
it will give location as
|
||||
|
||||
```bash
|
||||
Location: c:\users\anivk\ccs_work\python-study-plan\study-plan-kuttan\.venv\lib\site-packages
|
||||
```
|
||||
|
||||
Exit from venv
|
||||
|
||||
```bash
|
||||
deactivate
|
||||
```
|
||||
|
||||
pip show flask
|
||||
|
||||
```bash
|
||||
Location: c:\users\anivk\.pyenv\pyenv-win\versions\3.10.5\lib\site-packages
|
||||
```
|
||||
|
||||
Creating environments with Conda:
|
||||
|
||||
```bash
|
||||
conda create -n <env-name>
|
||||
```
|
||||
|
||||
To activate this environment, use
|
||||
|
||||
```bash
|
||||
conda activate <env-name>
|
||||
```
|
||||
|
||||
To deactivate an active environment, use
|
||||
|
||||
```bash
|
||||
conda deactivate
|
||||
```
|
||||
|
||||
To see a list of all your environments:
|
||||
|
||||
```bash
|
||||
conda env list
|
||||
conda info --envs
|
||||
```
|
||||
|
||||
```bash
|
||||
conda create -n ani2 python=3.9
|
||||
```
|
||||
|
||||
when run pip freeze inside conda env
|
||||
|
||||
```bash
|
||||
pip freeze > requirements.txt
|
||||
```
|
||||
|
||||
Why does pip freeze show paths like file:///C:/b/abs...?
|
||||
|
||||
Conda installs many packages from pre-built binaries stored in its cache.
|
||||
|
||||
Instead of a simple package==version, pip records the exact location of the wheel or source (file:///...) to make the environment reproducible.
|
||||
|
||||
This happens especially with packages installed via Conda but visible to pip.
|
||||
|
||||
Option 1
|
||||
|
||||
```bash
|
||||
pip list --format=freeze > requirements.txt
|
||||
```
|
||||
|
||||
Option 2: Export with Conda
|
||||
|
||||
```bash
|
||||
conda list --export > requirements.txt
|
||||
```
|
||||
|
||||
or even better:
|
||||
|
||||
```bash
|
||||
conda env export > environment.yml
|
||||
|
||||
```
|
||||
|
||||
requirements.txt works for pip-only workflows.
|
||||
|
||||
environment.yml is preferred for Conda because it keeps Python version, Conda channels, and exact package versions.
|
||||
|
||||
|
||||
Then remove one env(example: ani2):
|
||||
```bash
|
||||
conda remove --name ani2 --all
|
||||
```
|
||||
|
||||
|
||||
almost everything in your environment.yml is Conda system/runtime packages, not packages you explicitly use in your project. Let me break it down for you:
|
||||
|
||||
1️⃣ Conda runtime / system packages
|
||||
|
||||
These are installed automatically by Conda when you create an environment or install Python. They support the Python interpreter itself and the OS runtime:
|
||||
|
||||
python=3.9.23 → Python interpreter
|
||||
|
||||
pip=25.1, setuptools, wheel → packaging tools
|
||||
|
||||
`openssl`, `libffi`, `sqlite`, `tk`, `zlib`, `xz`, `ca-certificates` → system libraries
|
||||
|
||||
`vc`, `vc14_runtime`, `vs2015_runtime`, `ucrt` → Windows C/C++ runtime
|
||||
|
||||
`tzdata` → timezone database
|
||||
|
||||
These are needed for Python to run, but your code doesn’t explicitly “use” them.
|
||||
|
||||
2️⃣ Packages you actually use
|
||||
|
||||
`requests`, `urllib3`, `certifi`, `idna`, `charset-normalizer`, `cffi`, `pycparser`, `pysocks`, `brotlicffi`
|
||||
These are Python packages your project may import.
|
||||
|
||||
3️⃣ Why this matters for deployment
|
||||
|
||||
The Conda environment is large because it includes all the runtime libraries and build dependencies.
|
||||
|
||||
If you don’t use Conda for deployment (e.g., you’re deploying via Docker or serverless Python), these packages consume extra disk space unnecessarily.
|
||||
|
||||
⚡ Recommendation for deployment
|
||||
|
||||
Use a minimal requirements.txt with only the packages your project actually imports:
|
||||
```bash
|
||||
requests==2.32.4
|
||||
urllib3==2.5.0
|
||||
certifi==2025.8.3
|
||||
charset-normalizer==3.3.2
|
||||
idna==3.7
|
||||
```
|
||||
|
||||
Then deploy using pip instead of Conda.
|
||||
|
||||
Optional: If you need Python 3.9 specifically:
|
||||
```bash
|
||||
FROM python:3.9-slim
|
||||
COPY requirements.txt .
|
||||
RUN pip install -r requirements.txt
|
||||
COPY . /app
|
||||
```
|
||||
|
||||
This avoids installing all the Conda runtime libraries, saving space.
|
||||
|
||||
✅ In short:
|
||||
|
||||
Most of your environment.yml is Conda runtime dependencies, not your project code.
|
||||
|
||||
For deployment, a minimal pip requirements or Docker with Python slim image is much lighter.
|
27
src/intermediate/pip.md
Normal file
27
src/intermediate/pip.md
Normal file
@ -0,0 +1,27 @@
|
||||
Install directly with pip
|
||||
it installs the package globally into your system’s Python installation (unless you’re inside a virtual environment).
|
||||
```bash
|
||||
pip install requests
|
||||
```
|
||||
|
||||
Check if installed
|
||||
|
||||
```bash
|
||||
pip show requests
|
||||
```
|
||||
|
||||
Save to requirements.txt
|
||||
|
||||
You can manually create requirements.txt
|
||||
or
|
||||
Or generate it automatically:
|
||||
|
||||
```bash
|
||||
pip freeze > requirements.txt
|
||||
```
|
||||
|
||||
Install from requirements.txt (read from requirements file)
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
Reference in New Issue
Block a user