Skip to content

sreesankarsankarayya/pipenv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 

Repository files navigation

Guide to Pipenv, Pyenv, and Docker in MacOS / WSL on Win 11/10

The same approach without WSL works on MacOS

Refer to the Appendix section for detailed installation and setup instructions for WSL, Docker, Homebrew, and more.

Introduction

Pipenv is a tool for managing Python dependencies, virtual environments, and packaging. It is an alternative to virtualenv and venv, offering a streamlined experience.

Installation of Pipenv

sudo apt update
sudo apt install pipenv

Creating a Pipenv Environment

To initialize a new environment and install dependencies:

pipenv --python 3.11.9
pipenv install fastapi

This will create a Pipfile and Pipfile.lock, managing dependencies.

Additional Package Management in Pipenv

Installing Specific Packages with Categories

pipenv install requests==1.2 --categories="for-Test for-Packaging"
pipenv install numpy --categories="for-ML"

Viewing Installed Packages

pipenv graph

Uninstalling a Package

pipenv uninstall requests --categories="for-Test"

Application Structure

src/app.py

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def first_example():
    """
    First FastAPI Example
    """
    return {"Example": "FastAPI"}

Pipfile

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
fastapi = "*"

[dev-packages]
flask = "*"

[requires]
python_version = "3.11"
python_full_version = "3.11.9"

[for-test]
uvicorn = "*"
flask = "*"
requests = "1.2"

[for-packaging]
uvicorn = "*"
fastapi = "*"

[for-ML]
numpy = "*"

Running the Application

pipenv run uvicorn src.app:app --reload

Managing Multiple Python Versions with Pyenv

Installing Pyenv

brew update
brew install pyenv

Installing and Switching Python Versions

pyenv install 3.11
pyenv shell 3.11
python --version

Installing SQLite and Tkinter Support

sudo apt install libsqlite3-dev python3-tk
brew install python-tk

Using Virtualenv with Pyenv

pyenv exec pip install virtualenv
virtualenv ~/venvs4py/ve4_ms_abc
source ~/venvs4py/ve4_ms_abc/bin/activate

Running Docker Containers in WSL (Kali Linux)

Installing Docker

sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker

Running a Simple Web Server

docker-compose.yml

version: '3'
services:
  example.org:
    image: flashspys/nginx-static
    container_name: example.org
    ports:
      - 8081:80
    volumes:
      - ./path2serve:/static

Running the Container

docker compose up -d

Checking if the Server is Running

curl -v http://localhost:8081

Stopping the Container

docker compose down

Running GUI Applications in WSL (Kali Linux)

Installing Win-KeX

sudo apt install kali-win-kex

Starting the GUI

kex --win -s

Appendix

A) Setting up WSL

back to top

Installing WSL

wsl --install

This installs the default Linux distribution (Ubuntu). To install Kali Linux specifically, use:

wsl --install -d kali-linux

Checking Installed Distributions

wsl -l -v

Setting Default WSL Version

wsl --set-version kali-linux 2

Updating WSL Kernel

wsl --update

Starting WSL

wsl

B) Setting up Homebrew

back to top

Installing Homebrew (Linux)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Configuring Homebrew (Linux)

echo 'eval "$('/home/linuxbrew/.linuxbrew/bin/brew shellenv')"' >> ~/.bashrc
source ~/.bashrc

Verifying Installation (Linux)

brew --version

Installing Homebrew (MacOS)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Configuring Homebrew (MacOS)

echo 'eval "$('/opt/homebrew/bin/brew shellenv')"' >> ~/.zshrc
source ~/.zshrc

Verifying Installation (MacOS)

brew --version

C) Accessing Docker Desktop from Kali Linux WSL

back to top

Enable WSL Integration in Docker Desktop

docker version

If the client connects successfully, it should display version details.

Setting Environment Variable for Docker

export DOCKER_HOST=tcp://localhost:2375

To make this permanent, add it to your ~/.bashrc:

echo 'export DOCKER_HOST=tcp://localhost:2375' >> ~/.bashrc
source ~/.bashrc

Running a Test Docker Container

docker run hello-world

Refer

To execution logs for troubleshoot help here...

About

This is a step by step work walkthrough reference on managing multiple Python versions Env and finally the solution with a combination of pyenv & pipenv

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors