How to install Python packages with pipenv, venv or virtualenv package manager

You can find GitHub repository in https://github.com/python-projects-kenanhancer/python_demo

  • Pyenv – Python Runtime Version Manager
  • Pipenv – Python Package Manager and Virtual environment manager
  • Venv – Virtual environment manager
  • Virtualenv – Virtual environment manager

Installing Python Runtime Versions via Pyenv

In order to test different Python Runtime versions, I have installed some versions.

$ pyenv install 3.10.2

python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.10.2.tar.xz...
-> https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tar.xz
Installing Python-3.10.2...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.10.2 to /Users/kenanhancer/.pyenv/versions/3.10.2

I have 4 Python runtime versions(3.10.2, 3.10.3, 3.10.4, 3.10.5) in my machine.

$ pyenv versions

  system
  3.10.2
  3.10.3
  3.10.4
* 3.10.5 (set by /Users/kenanhancer/.pyenv/version)
Continue reading

How to install AWS and Azure CLI with Homebrew

Homebrew

Installing

Run the following code to install Homebrew if you don't have in your machine.

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

Verifying

Run the following code to verify Homebrew is installed

$ brew --version

Homebrew 3.2.6
Homebrew/homebrew-core (git revision c4d5aac8ec; last commit 2021-08-07)
Homebrew/homebrew-cask (git revision 1169dcb641; last commit 2021-08-07)

AWS

AWS CLI

Installing

$ brew update && brew install awscli

Verifying

$ aws --version

aws-cli/2.2.27 Python/3.9.6 Darwin/20.6.0 source/x86_64 prompt/off

Upgrading

$ brew upgrade awscli

Uninstalling

$ brew uninstall awscli

Using AWS CLI

Create default profile

$ aws configure

AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/EXAMPLEKEY
Default region name [None]: eu-west-2
Default output format [None]: json

Create Named Profiles

$ aws configure --profile kenan-dev

AWS Access Key ID [None]: AKIAI44QH8DHBEXAMPLE
AWS Secret Access Key [None]: je7MtGbClwBF/2Zp9Utk/EXAMPLEKEY
Default region name [None]: eu-west-2
Default output format [None]: json

List AWS Profiles

$ aws configure list-profiles

List AWS Configuration Data

$ aws configure list
$ aws configure list --profile kenan-dev

Set any credential or configuration settings

$ aws configure set aws_access_key_id bar --profile default
$ aws configure set aws_secret_access_key foo --profile kenan-dev

Get any credential or configuration settings

$ aws configure get aws_access_key_id --profile default
$ aws configure get region --profile kenan-dev

AWS SAM CLI

Installing

$ brew tap aws/tap
$ brew install aws-sam-cli

Verifying

$ sam --version

SAM CLI, version 1.27.2

Upgrading

$ brew upgrade aws-sam-cli

Uninstalling

$ brew uninstall aws-sam-cli

Azure

Demo repository is in the following link.

https://github.com/nodejs-projects-kenanhancer/serverless-azure-functions-typescript-demo

Azure CLI

Installing

$ brew update && brew install azure-cli

Verifying

$ az --version

azure-cli                         2.26.1 *

core                              2.26.1 *
telemetry                          1.0.6

Python location '/usr/local/Cellar/azure-cli/2.26.1/libexec/bin/python'
Extensions directory '/Users/kenanhancer/.azure/cliextensions'

Python (Darwin) 3.8.11 (default, Jun 29 2021, 03:08:07) 
[Clang 12.0.5 (clang-1205.0.22.9)]

Legal docs and information: aka.ms/AzureCliLegal


You have 2 updates available. Consider updating your CLI installation with 'az upgrade'

Please let us know how we are doing: https://aka.ms/azureclihats
and let us know if you're interested in trying out our newest features: https://aka.ms/CLIUXstudy

Upgrading

$ brew update && brew upgrade azure-cli

# OR

$ az upgrade

Uninstalling

$ brew uninstall azure-cli

Sign in with Azure CLI

Sign in interactively

$ az login

Sign in with device code flow interactively

If no web browser is available or the web browser fails to open, you may force device code flow with below command.

$ az login --use-device-code

Azure Functions Core Tools

Installing

$ brew tap azure/functions
$ brew install azure-functions-core-tools@3

# if upgrading on a machine that has 2.x installed
$ brew link --overwrite azure-functions-core-tools@3

Verifying

$ func --version

3.0.3477

Upgrading

$ brew upgrade azure-functions-core-tools@3

Uninstalling

$ brew uninstall azure-functions-core-tools@3

How to install Python with pyenv runtime version manager

I am using different programming languages like C#, Java, Node.js etc and need to manage runtime versions in my local. So, I like to use runtime version managers.

For example, there are some runtime version managers in Node.js community like nvm or n. I am very happy to use both of two package managers 🙂

Let's say I work for one Node.js project in dev machine with Node v8.0.0 but other project needs Node v6.0.0

In order to handle, different versions in same machine, we may use runtime version managers.

I just want to find a way to switch between different Python version so that found pyenv runtime version manager.

Pyenv installation

Click pyenv link for more detailed installation.

Installing pyenv with Homebrew

First, ensure that you have Homebrew installed in your system. Homebrew is a package manager for Mac OS. So if you want to learn more details about it, visit my blog below.

Run the following commands in your terminal. But, just copy commands without $ sign.

$ brew update
$ brew install pyenv

Setting PATH

Run the following command for advanced configuration.

$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

Run the following command for basic configuration.

$ echo 'PATH=$(pyenv root)/shims:$PATH' >> ~/.bash_profile

and restart your terminal manually or run the following command to restart automatically.

$ exec "$SHELL"

Upgrading pyenv

$ brew upgrade pyenv

Uninstall pyenv

$ rm -rf $(pyenv root)
$ brew uninstall pyenv

Pyenv commands

List all Python versions installed in system

$ pyenv versions

  system
  3.7.3
* 3.8.2 (set by /Users/kenanhancer/.pyenv/version)

Show current active Python version in system

$ pyenv version

3.8.2 (set by /Users/kenanhancer/.pyenv/version)
Continue reading