I mostly use these tools below so this post will be updated frequently. My favorite runtime version manager(or tool version manager) is asdf nowadays 🙂
Continue readingCLI
How to create AWS Lambda with AWS SAM CLI
According to my experience, if you want to create an AWS Lambda without interactive mode, 15 templates below don't exists for each runtime, for example,
Data processing
template only exists fordotnet
andnodejs
.
Notice that third template name isHello World Example with Powertools for AWS Lambda
in below output, but if you want to create a project with python runtime and third template in the belowsam init
output, you have to usehello-world-powertools-python
as a template name. But it is not mentioned in help. So, i just usedsam init
in interactive mode and output of this command showed me template name.sam init --name my-data-processing-app --runtime python3.9 --dependency-manager pip --app-template hello-world-powertools-python
$ sam init
You can preselect a particular runtime or package type when using the `sam init` experience.
Call `sam init --help` to learn more.
Which template source would you like to use?
1 - AWS Quick Start Templates
2 - Custom Template Location
Choice: 1
Choose an AWS Quick Start application template
1 - Hello World Example
2 - Data processing
3 - Hello World Example with Powertools for AWS Lambda
4 - Multi-step workflow
5 - Scheduled task
6 - Standalone function
7 - Serverless API
8 - Infrastructure event management
9 - Lambda Response Streaming
10 - Serverless Connector Hello World Example
11 - Multi-step workflow with Connectors
12 - Full Stack
13 - Lambda EFS example
14 - DynamoDB Example
15 - Machine Learning
Template: 1
Use the most popular runtime and package type? (Python and zip) [y/N]:
Continue reading How to create AWS Lambda, Azure Function, Google Cloud Function with Serverless Framework CLI
Serverless framework is a CLI to build cloud applications. There are more than 10 Serverless Infrastructure Providers like AWS, Azure and GCP as shown below screenshot.
Find more Serverless Framework CLI command in Azure Serverless TypeScript project in GitHub
According to my experience, Serverless Framework gives a better support for AWS provider, for example, if you see project template below, there are many project templates for AWS but very less support for other providers.
Find more details in https://www.serverless.com/framework/docs/getting-started
Continue readingHow to install .NET with dotnet-install script
Find more details in Microsoft scripted installation
- .NET SDK (Software Development Kit): The SDK includes everything you need to build and run .NET applications. This means it includes the runtime, but also includes other tools for developing, building, running, and testing .NET applications. This includes the .NET CLI (Command Line Interface), compilers, and libraries. You need the SDK to develop and build .NET applications.
- .NET Runtime: The runtime includes just the resources required to run existing .NET applications. It does not include the tools and libraries used for building applications. It's a smaller installation package compared to the SDK. When you deploy a .NET application to a server or a client machine, you usually only need to have the appropriate .NET Runtime installed on that machine, not the full SDK.
All .NET Core and .NET Versions Available for Installation via dotnet-install
Installation
$ curl -sSL https://dot.net/v1/dotnet-install.sh > dotnet-install.sh
$ chmod +x dotnet-install.sh
$ echo 'export DOTNET_ROOT=$HOME/.dotnet' >> ~/.zshrc
$ echo 'export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools' >> ~/.zshrc
dotnet-install Script Reference
find reference for dotnet-install script reference in dotnet-install script reference
find options for dotnet-install script in dotnet-install script options
Continue readingPython listing virtual environments for conda, pipenv, pyenv-virtualenv
Conda
$ conda env list
# conda environments:
#
base /opt/homebrew/Caskroom/miniconda/base
python_azure_function_conda_virtual_env-3.9 * /opt/homebrew/Caskroom/miniconda/base/envs/python_azure_function_conda_virtual_env-3.9
python_demo-3.9 /opt/homebrew/Caskroom/miniconda/base/envs/python_demo-3.9
test34-3.9 /opt/homebrew/Caskroom/miniconda/base/envs/test34-3.9
test35-3.9 /opt/homebrew/Caskroom/miniconda/base/envs/test35-3.9
test36-3.9 /opt/homebrew/Caskroom/miniconda/base/envs/test36-3.9
Pyenv-virtualenv
$ pyenv virtualenvs
3.10.3/envs/test31-3.10.3 (created from /Users/kenanhancer/.pyenv/versions/3.10.3)
3.10.5/envs/test31-3.10.5 (created from /Users/kenanhancer/.pyenv/versions/3.10.5)
3.10.5/envs/test32-3.10.5 (created from /Users/kenanhancer/.pyenv/versions/3.10.5)
3.11.4/envs/python_demo-3.11.4 (created from /Users/kenanhancer/.pyenv/versions/3.11.4)
3.11.4/envs/test31-3.11.4 (created from /Users/kenanhancer/.pyenv/versions/3.11.4)
3.11.4/envs/test32-3.11.4 (created from /Users/kenanhancer/.pyenv/versions/3.11.4)
3.6.15/envs/test31-3.6.15 (created from /Users/kenanhancer/.pyenv/versions/3.6.15)
3.9.1/envs/test29-3.9.1 (created from /Users/kenanhancer/.pyenv/versions/3.9.1)
3.9.1/envs/test30-3.9.1 (created from /Users/kenanhancer/.pyenv/versions/3.9.1)
3.9.1/envs/test31-3.9.1 (created from /Users/kenanhancer/.pyenv/versions/3.9.1)
3.9.17/envs/python_demo-3.9.17 (created from /Users/kenanhancer/.pyenv/versions/3.9.17)
3.9.17/envs/test29-3.9.17 (created from /Users/kenanhancer/.pyenv/versions/3.9.17)
3.9.17/envs/test30-3.9.17 (created from /Users/kenanhancer/.pyenv/versions/3.9.17)
3.9.17/envs/test31-3.9.17 (created from /Users/kenanhancer/.pyenv/versions/3.9.17)
python_demo-3.11.4 (created from /Users/kenanhancer/.pyenv/versions/3.11.4)
python_demo-3.9.17 (created from /Users/kenanhancer/.pyenv/versions/3.9.17)
test29-3.9.1 (created from /Users/kenanhancer/.pyenv/versions/3.9.1)
test29-3.9.17 (created from /Users/kenanhancer/.pyenv/versions/3.9.17)
test30-3.9.1 (created from /Users/kenanhancer/.pyenv/versions/3.9.1)
test30-3.9.17 (created from /Users/kenanhancer/.pyenv/versions/3.9.17)
test31-3.10.3 (created from /Users/kenanhancer/.pyenv/versions/3.10.3)
test31-3.10.5 (created from /Users/kenanhancer/.pyenv/versions/3.10.5)
test31-3.11.4 (created from /Users/kenanhancer/.pyenv/versions/3.11.4)
test31-3.6.15 (created from /Users/kenanhancer/.pyenv/versions/3.6.15)
test31-3.9.1 (created from /Users/kenanhancer/.pyenv/versions/3.9.1)
test31-3.9.17 (created from /Users/kenanhancer/.pyenv/versions/3.9.17)
test32-3.10.5 (created from /Users/kenanhancer/.pyenv/versions/3.10.5)
test32-3.11.4 (created from /Users/kenanhancer/.pyenv/versions/3.11.4)
Pipenv
$ ls -lat ~/.local/share/virtualenvs/
Python Azure Function Debugging in Pipenv virtual environment
Creating virtual environment
$ mkdir python_demo
$ cd python_demo
$ pyenv local 3.9.6
$ pipenv --python $(pyenv which python)
$ pipenv --venv
$ pipenv install ptvsd -d
Continue reading conda vs pipenv vs virtualenv commands
find more information in conda
Task | Conda package and environment manager command | Pip package manager command | Virtualenv environment manager command |
---|---|---|---|
Install a package | conda install $PACKAGE_NAME | pip install $PACKAGE_NAME | X |
Update a package | conda update --name $ENVIRONMENT_NAME$PACKAGE_NAME | pip install --upgrade$PACKAGE_NAME | X |
Update package manager | conda update conda | Linux/macOS: pip install -Upip Win: python -m pipinstall -U pip | X |
Uninstall a package | conda remove --name $ENVIRONMENT_NAME$PACKAGE_NAME | pip uninstall $PACKAGE_NAME | X |
Create an environment | conda create --name $ENVIRONMENT_NAME python | X | cd $ENV_BASE_DIR; virtualenv$ENVIRONMENT_NAME |
Activate an environment | conda activate $ENVIRONMENT_NAME * | X | source$ENV_BASE_DIR/$ENVIRONMENT_NAME/bin/activate |
Deactivate an environment | conda deactivate | X | deactivate |
Search available packages | conda search $SEARCH_TERM | pip search $SEARCH_TERM | X |
Install package from specific source | conda install --channel $URL $PACKAGE_NAME | pip install --index-url $URL$PACKAGE_NAME | X |
List installed packages | conda list --name $ENVIRONMENT_NAME | pip list | X |
Create requirements file | conda list --export | pip freeze | X |
List all environments | conda info --envs | X | Install virtualenv wrapper, then lsvirtualenv |
Install other package manager | conda install pip | pip install conda | X |
Install Python | conda install python=x.x | X | X |
Update Python | conda update python * | X | X |
How to create virtual environment with conda
Conda is an open-source package management system and virtual environment management system that runs on Windows, macOS, and Linux. It was created for Python programs but it can package and distribute software for any language such as R, Ruby, Lua, Scala, Java, JavaScript, C, C++, FORTRAN.
The two main purposes of Conda are:
- Package management: Conda makes it easy to manage and install packages, even for different versions of Python. In addition, it also supports binary package management, which makes it an efficient way to handle packages and dependencies in your projects.
- Virtual Environment management: Conda allows you to create separate environments containing files, packages, and their dependencies that will not interact with other environments. When switching between Python versions for different projects, Conda makes it simple to use the specific version you need.
While pip can install Python packages, Conda can install packages for any language. Conda packages are binaries, which eliminates the need to compile the code which makes installations faster and more straightforward.
Installing conda
$ brew update
$ brew install --cask miniconda
Checking conda version
$ conda --version
conda 23.3.1
Conda help
$ conda -h
usage: conda [-h] [-V] command ...
conda is a tool for managing and deploying applications, environments and packages.
Options:
positional arguments:
command
clean Remove unused packages and caches.
compare Compare packages between conda environments.
config Modify configuration values in .condarc. This is modeled after the git config command. Writes to the
user .condarc file (/Users/kenanhancer/.condarc) by default. Use the --show-sources flag to display
all identified configuration locations on your computer.
create Create a new conda environment from a list of specified packages.
info Display information about current conda install.
init Initialize conda for shell interaction.
install Installs a list of packages into a specified conda environment.
list List installed packages in a conda environment.
package Low-level conda package utility. (EXPERIMENTAL)
remove (uninstall)
Remove a list of packages from a specified conda environment. Use `--all` flag to remove all packages
and the environment itself.
rename Renames an existing environment.
run Run an executable in a conda environment.
search Search for packages and display associated information.The input is a MatchSpec, a query language for
conda packages. See examples below.
update (upgrade) Updates conda packages to the latest compatible version.
notices Retrieves latest channel notifications.
options:
-h, --help Show this help message and exit.
-V, --version Show the conda version number and exit.
conda commands available from other packages (legacy):
content-trust
env
Continue reading How to create virtual environment with pipenv
Pipenv is a Python tool that aims to bring the best features of multiple other tools into one. It provides an easy way to manage virtual environments and manage package dependencies consistently. Its key goal is to simplify the workflow of managing a Python environment for your project.
Installing pipenv
$ python -m pip install pipenv
Checking pipenv version
$ pipenv --version
pipenv, version 2022.7.4
Checking pipenv version
$ pipenv -h
Usage: pipenv [OPTIONS] COMMAND [ARGS]...
Options:
--where Output project home information.
--venv Output virtualenv information.
--py Output Python interpreter information.
--envs Output Environment Variable options.
--rm Remove the virtualenv.
--bare Minimal output.
--man Display manpage.
--support Output diagnostic information for use in
GitHub issues.
--site-packages / --no-site-packages
Enable site-packages for the virtualenv.
[env var: PIPENV_SITE_PACKAGES]
--python TEXT Specify which version of Python virtualenv
should use.
--three Use Python 3 when creating virtualenv.
--clear Clears caches (pipenv, pip). [env var:
PIPENV_CLEAR]
-q, --quiet Quiet mode.
-v, --verbose Verbose mode.
--pypi-mirror TEXT Specify a PyPI mirror.
--version Show the version and exit.
-h, --help Show this message and exit.
Usage Examples:
Create a new project using Python 3.7, specifically:
$ pipenv --python 3.7
Remove project virtualenv (inferred from current directory):
$ pipenv --rm
Install all dependencies for a project (including dev):
$ pipenv install --dev
Create a lockfile containing pre-releases:
$ pipenv lock --pre
Show a graph of your installed dependencies:
$ pipenv graph
Check your installed dependencies for security vulnerabilities:
$ pipenv check
Install a local setup.py into your virtual environment/Pipfile:
$ pipenv install -e .
Use a lower-level pip command:
$ pipenv run pip freeze
Commands:
check Checks for PyUp Safety security vulnerabilities and against
PEP 508 markers provided in Pipfile.
clean Uninstalls all packages not specified in Pipfile.lock.
graph Displays currently-installed dependency graph information.
install Installs provided packages and adds them to Pipfile, or (if no
packages are given), installs all packages from Pipfile.
lock Generates Pipfile.lock.
open View a given module in your editor.
requirements Generate a requirements.txt from Pipfile.lock.
run Spawns a command installed into the virtualenv.
scripts Lists scripts in current environment config.
shell Spawns a shell within the virtualenv.
sync Installs all packages specified in Pipfile.lock.
uninstall Uninstalls a provided package and removes it from Pipfile.
update Runs lock, then sync.
verify Verify the hash in Pipfile.lock is up-to-date.
Continue reading How to create virtual environment with pyenv-virtualenv plugin
pyenv-virtualenv is a pyenv plugin that provides features to manage virtualenvs and conda environments for Python on UNIX-like systems.
If you don't have pyenv in your system, follow below post;
Installing pyenv-virtualenv
$ brew update
$ brew install pyenv-virtualenv
Setting PATH
Run one of the following commands in terms of your shell's .rc
file.
$ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
$ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zshrc
Creating virtual environment
$ mkdir python_demo
$ cd python_demo
$ pyenv install 3.11.4
$ pyenv virtualenv 3.11.4 python_demo-3.11.4
$ pyenv virtualenvs
$ pyenv prefix python_demo-3.11.4
/Users/kenanhancer/.pyenv/versions/python_demo-3.11.4
$ ls -Llat $(pyenv prefix python_demo-3.11.4)
drwxr-xr-x 14 kenanhancer staff 448 19 Jun 17:36 bin
-rw-r--r-- 1 kenanhancer staff 107 19 Jun 17:36 pyvenv.cfg
drwxr-xr-x 3 kenanhancer staff 96 19 Jun 17:36 lib
drwxr-xr-x 2 kenanhancer staff 64 19 Jun 17:36 include
$ tree -a -L 4 $(pyenv prefix python_demo-3.11.4)
├── bin
│ ├── Activate.ps1
│ ├── activate
│ ├── activate.csh
│ ├── activate.fish
│ ├── pip
│ ├── pip3
│ ├── pip3.11
│ ├── pydoc
│ ├── python -> python3.11
│ ├── python3 -> python3.11
│ └── python3.11 -> /Users/kenanhancer/.pyenv/versions/3.11.4/bin/python3.11
├── include
│ └── python3.11
├── lib
│ └── python3.11
│ └── site-packages
│ ├── _distutils_hack
│ ├── distutils-precedence.pth
│ ├── pip
│ ├── pip-23.1.2.dist-info
│ ├── pkg_resources
│ ├── setuptools
│ └── setuptools-65.5.0.dist-info
└── pyvenv.cfg
Continue reading