Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Tuesday, April 16, 2024

pip install packages where multiple python versions installed

This is mainly targeted to developers like me who are coming to Python from other technologies. For seasoned Python developers managing packages from multiple versions would be muscle memory.

The main concern of this video is to address how we can manage the packages in a machine having multiple python versions installed.

Tuesday, October 24, 2023

Enable Python preview in Polyglot notebook

It is a big difference if anyone ever tried the Jupyter Notebook. Once we experience, we need that experience everywhere including .Net. That experience was there in terms of a Jupyter kernel for .Net¹. That requires Jupyter installed in the machine already. Finally, more native experience came for .Net in the form of a VS Code extension. That was called .Net Interactive Notebooks² which uses .Net Interactive (formerly Try.Net) behind the scene. That started supporting many languages such as PowerShell, JavaScript, SQL etc... which is kinda out of the .Net world. Finally, in Nov 2022, .Net Interactive was renamed to Polyglot notebooks³ to reflect its purpose.

Is Python supported by Polyglot Notebooks?

The Polyglot notebooks didn't have the support for Python. We had to switch to Jypyter to work with Python and come back. Now Polyglot Notebooks has Python support as a preview.

How to enable Python in Polyglot Notebook?

Obviously, we should have Polyglot notebooks up and running. The first step to enable Python preview is that we need to install Jupyter on the machine and make sure the Python kernel spec is available. Run the below command to make sure it is there.
Once this is done, we can see 2 Kernel options at the Notebook level in Visual Studio Code.

The enabling preview feature requires the below command to be run on the notebook cell.

#!connect jupyter --kernel-name pythonkernel --kernel-spec python3

The command output shows it is in preview mode.
Command is - #!connect jupyter --kernel-name pythonkernel --kernel-spec python3

Once we add support, we can start having Python cells alongside C#. The cell kernel type needs to be the name we have given in the connect command. Below is the final state. Here we can learn C# and Python side by side.

We can even set up R language in Polyglot Notebooks. Hereafter don't waste time creating an entire project to confirm small language or platform features.

References

¹ - https://devblogs.microsoft.com/dotnet/net-core-with-juypter-notebooks-is-here-preview-1/

² - https://hanselman.com/blog/announcing-net-interactive-try-net-includes-net-notebooks-and-more

³ - https://devblogs.microsoft.com/dotnet/dotnet-interactive-notebooks-is-now-polyglot-notebooks/

⁴ - https://techcommunity.microsoft.com/t5/educator-developer-blog/using-visual-studio-notebooks-for-learning-c/ba-p/3580015

⁵ - https://github.com/dotnet/interactive/blob/main/docs/jupyter-in-polyglot-notebooks.md

Tuesday, June 22, 2021

Close all overdue Azure DevOps work items with Python

As software engineers, we need to track our work items even if we are working as freelancers or for an enterprise. Those work items constitute the health of the project also helping the management to understand the high-level view. Every company has its own ALM software to track the work. One of the famous ALM is Azure DevOps (ADO hereafter) from Microsoft.

Problem

In an ideal situation, we should plan our tasks for every day. Good if we can plan in advance and close the work items as soon as it's done. But sometimes we may not be able to make the ADO work items sync with reality. It may be due to long release days. Unexpected support issues, shortage of team members, etc. At the end of the billing cycle finance department will be chasing us to close work items. At that time closing each and every item manually is time-consuming. There are many ways to tackle it such as import to Excel close all and sync. We may use any no-code low-code platforms such as Power Automate to automate the task. Developers who use those platforms normally called 'citizen developers'. I strongly recommend trying any of these methods to automate this type of work. There is no need to code.

The no-code, low-code platforms generally offer building blocks to do simple day-to-day operations then provide extensibility via plug-ins or by invoking web requests / Web APIs. The plug-ins require coding efforts. Invoking web requests needs deep knowledge of Web APIs and how the service is structured.

Potential solution

As developers, we are proud of our programming ability and may not want to become citizen developers. For those, there are SDKs available to automate Azure DevOps work items. Also when the no-code, low-code platform doesn't have required customizations, we have to use the SDKs or make direct Web API calls to Azure Dev Ops.

We can use the Python SDK given by Azure DevOps as one of the mediums to interact with Azure Dev Ops to close all the OverDue work items.

Code is available on GitHub.

How to use is already documented in the readme.md files. Please follow that.

Code walkthrough

The Git Repo has enough comments. I am also planning a YouTube video explaining the same.

Tuesday, December 29, 2015

Published my first Google App Engine Python Application


This would have been a post if everything went easily. But it was not easy. Got one trouble. Ok let me start the story.

Introduction

Google App Engine (here after GAE) was there for long time at least from 2011 its no more preview. Unfortunately I didn't get a chance to play with it. Now since my family went to India during the winter season, I have enough time to play around.

I never thought it would be easy as publishing web site from Visual Studio to Azure in single click. But app engine is simple as one click publish.

First I ensured that it still has free quota. Because being in the Microsoft shop in my day job who embraces Azure a lot, there is no way I will be hosting an application into Google cloud. So its for my personal use and for personal use I never wanted to pay money. Oh except my domain and hosting space.
https://cloud.google.com/appengine/docs/quotas

First Python application targeting Google App Engine

Then I started with the below basics on Python based GAE development and how to publish a simple Python web app into GAE.
https://cloud.google.com/appengine/docs/python/
https://cloud.google.com/appengine/docs/python/tools/devserver
https://cloud.google.com/appengine/docs/python/gettingstartedpython27/introduction

Then setup the environment. I already had Python 2.7. So installed only the GAE SDK.
https://cloud.google.com/appengine/downloads#Google_App_Engine_SDK_for_Python

Its very simple. Once we install the SDK. It will provide us an option to run our web site locally. Once we are satisfied we can push to app engine ie cloud

The helloworld sample in google help is very preliminary. So googled for little higher startup sample and I got the below link.

http://www.labnol.org/internet/host-website-on-google-app-engine/18801/

In the above link I was able to see some more better sample which deal with html files as well. I took that did some modification in html and tried to run from local app engine server. It worked fine.

Deployment

Then I tried to deploy to real GAE by clicking on the Deploy button in the GAE launcher. It opened the browser and I entered my google credentials. But unfortunately it didn't publish to my app engine. The window stayed as is with the below message

If your browser is on a different machine then exit and re-run this
application with the command-line parameter

  --noauth_local_webserver

Then I started googling and found that it happens sometimes and if we use the command based deployment it will work. I tried that and didn't succeed.

Then googled with error and language Python. Then I got another workaround to a known issue.

If the local development server is running we will not be able to deploy to GAE. I just stopped the local server and deployed. It worked.

The public url is as follows
http://joystestproject.appspot.com/