Monday, June 10, 2024

What is a scratch file in PyCharm?

 As the name implies it is a scratch file and not attached to any project. It is extremely useful to run some temporary stuff before you plan on using in a project. It is saved to a separate location and indexed. The code on the scratch can be run and debugged. What is more it is color coded.

How do you work with a scratch file?

It is very easy as shown in the PyCharm IDE. From the main menu you can access this dropdown when you click File.


When you choose New Scratch File or use the shortcut Ctrl+Alt+Shift+Insert the next dropdown is displayed. 

There are lots of programs you can run as shown. These are all functional and bring in great value to the IDE.

Herein, for demo I shall create a python file and test run it. When I choose a Python code, it creates a file scratch.py and saves it to the Scratches directory. I write this simple code in the scratch.py file,

print("Scratchy") as shown.


Now you can run this file and the interpreter picks it up. After highlighting the scratch.py file in the Scratches folder, with a right click you display this dropdown.


In the drop-down, you click Run 'Scratch'. The code gets run and you see the result of running the code.
You can rerun the code using the control shown with the horizontal arrow insert. There is a main run control in the main menu and it will not run the code in Scratch folder.


You can rename the file. You need to choose the file and right click. From the drop-down click Refactor and rename the file.

In addition to fully functional files show above, you can also use the Scratch Buffers. These can not be run as they are just text files. You need to create a scratch buffer to store these(also indexed and rotated). It is an excellent feature to keep codes, code scratches, and anything else you want to come back to.

How to create a Scratch buffer file?

Ctrl+Shift+A brings up a window. In the window start type in "New Scratch.." and you get some choices. Choose New Scratch Buffer and a buffer1.txt is created wherein you can keep your notes. These files are also stored in the Scratches node.












Saturday, June 8, 2024

How do you install Python Image Library for PyCharm?

 PIL, or Python Image Library provides support for working with images in Python (Interpreter). PIL provides a fairly fast and powerful way to process images.

You may also come across Pillow. Pillow (a fork of PIL) is same as PIL, and it was created since PIL was not supported since 2009.You use Pillow wherever you need PIL. Pillow is supported by active developers.

Importantly Pillow provides,

File format support.

Image processing capabilities.

In an earlier post we have seen many of the desirable features of PyCharm. Other libraries for processing images in Python are OpenCV and matplotlib.

PIL Installation:

Using PIP, PIL can be installed. Installing Pillow (or PIL) is easy and with a simple command,

pip install Pillow

However, you may have to use it with caution.

PIL,  or Pillow with PyCharm:

If you have PyCharm installed, it is fairly easy to install PIL. The highligted in blue is the node for Phyton Packages.


You find Pillow at the end of the listt of packages available in this node.


If you click Install (blue lin) it opens a drop-down list as shown.


From PIL 1.0 to 10.3.0 versions can be installed. What is the best version then? It would be the latest since Pillow is maintained with all bug fixes. If you need to work with older projects you may need to dig a little deeper as there may be compatibility issues with Python versions.

Herein the latest version will be used and if some problems arise other versions may be considered.

Clicking on 10.3.0 installs this version of Pillow. Easy, isn't it?


How do you check if Pillow is installed?

Just try to run the following code from the Python Console shown in blue, 

from PIl import Image

You should see the success of your code.

Visit again for more PyCharm and PIL.

Friday, May 31, 2024

Do AI chat bots learn from user interaction?

 This is an important question going forward with AI. If they do then information from one questions to the next and the answers get somehow sent to AI's source. If not, there is nothing going from your device to the source. I do AI chats both on my Android Samsung phone as well as from my Surface Pro laptop. The META AI is on my on my phone.

CoPilot

CoPilot does not remember stuff from one conversation to next. It does not LEARN from user interaction.


META AI

Look here, what I hear from META AI on my WhatsApp account:

Do you learn from user interaction in any way?

Yes, I learn from user interaction in several ways:

1. *Improving responses*: Through user feedback, I can refine my understanding of what constitutes a helpful and accurate response.
2. *Adapting to language*: User interactions help me learn to recognize and generate language patterns, idioms, and colloquialisms.
3. *Expanding knowledge*: Users may ask questions or provide information on topics I'm not familiar with, which helps me expand my knowledge base.
4. *Tuning accuracy*: User corrections and clarifications enable me to fine-tune my understanding and accuracy on specific topics.
5. *Understanding context*: User interactions help me better understand the context and nuances of language, allowing me to provide more relevant and empathetic responses.

Your interactions with me today are contributing to my ongoing learning and improvement!

The Q&A are indeed saved on the server.


GEMINI

Here is what I hear from Gemini:

Do you profit from user interaction in some way by saving the Q &A?

Yes, Google Assistant can benefit from user interaction by saving Q&A data. This data helps improve its understanding of language and user needs. Here are some ways this can happen:

 * Improved responses: By analyzing past interactions, Google Assistant can learn to identify patterns and improve its ability to respond to future queries in a more informative and helpful way.

 * New feature development: Data on user interactions can inform the development of new features and functionalities for Google Assistant.

 * Personalized experiences: User interaction data can be used to personalize the Assistant's responses to individual users, tailoring results to their preferences and search history.

This interactive learning is very important and I am not sure how and how often the creator of CoPilot updates its KB.


Friday, May 17, 2024

How do you launch Python assuming it is installed?

Python from python.org and many other software programs installs python and they may choose to install in different folders or locations. Finding where it is installed is important. If you need to run python on a command prompt, the python executable should be in the environment's path. You may note that you may have multiple versions of Python installed on your computer for varying requirements. You should know what version is installed and where.

In this post you will get to know ways and means to find the python executable on your computer.

1. This is the easiest. You try to check for Python using your command prompt as shown. If you get the following reply:

This only means the python.exe is not in the path C:\

============================================

C:\>python -c Print 'Hello'

Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

============================================

If you find a python in the directory, it may be a short cut, if a file existed.

If I run without arguments as shown above, I am taken to the Windows Store to download Python 3.12 as shown.


I already have Python 3.12 installed when I installed PyCharm. 

You can check if the executable python is in the environment's path as shown:

========================

C:\Users\hoden>path

PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\hoden\AppData\Local\Programs\Python\Launcher\;C:\Users\hoden\AppData\Local\Microsoft\WindowsApps;;C:\Program Files\JetBrains\PyCharm Community Edition 2023.3.3\bin;

========================

The executable is in the JetBrains directory that was installed for PyCharm as shown.

2. There is another way to find where python is installed.


Run the following command at command prompt:

======================================

C:\>where python

C:\Users\hoden\AppData\Local\Microsoft\WindowsApps\python

C:\Users\hoden\AppData\Local\Microsoft\WindowsApps\python.exe

========================================

In this folder,

C:\Users\hoden\AppData\Local\Microsoft\WindowsApps

You find two other python executables as well, python and python3. These are in the environment's PATH as well.

Here is the properties pages of one of them,


As you can see this is an empty file. There are several reasons why this file exists here. It is more like a placeholder or a shortcut for a non existent file and sometimes open a link in the web browser for a download location (Windows Store) as we saw earlier.

3. This yet another way. Windows Powershell is a powerful program that can also be used.There are two ways of starting Powershell, as a command line program or an interactive way.

You could also use Windows Powershell as shown:

===============================

PS C:\Users\hoden> Get-Command python


CommandType     Name                                               Version    Source                                                             

-----------     ----                                               -------    ------                                                             

Application     python.exe                                         0.0.0.0    C:\Users\hoden\AppData\Local\Microsoft\WindowsApps\python.exe  

===================================================

This is similar what we saw earlier. It showed the same file we saw earlier.

3. The following is not run in PowerShell but on the C:\ prompt.

However, if you have multiple versions of python installed you can try this:

==========================================

C:\Windows\System32>py -0

 -V:3.12 *        Python 3.12 (64-bit)

===========================================

This does not show the path but flags the version. if you want both path and version try this:

================================

C:\Users\hoden>py --list-paths

 -V:3.12 *        C:\Users\hoden\AppData\Local\Programs\Python\Python312\python.exe

================================

You can check this here:

=============

 Directory of C:\Users\hoden\AppData\Local\Programs\Python\Python312


05/05/2024  05:33 PM    <DIR>          .

05/05/2024  05:32 PM    <DIR>          ..

05/05/2024  05:32 PM    <DIR>          DLLs

05/05/2024  05:32 PM    <DIR>          Doc

05/05/2024  05:32 PM    <DIR>          include

05/05/2024  05:32 PM    <DIR>          Lib

05/05/2024  05:32 PM    <DIR>          libs

10/02/2023  01:27 PM            36,874 LICENSE.txt

10/02/2023  01:28 PM         1,664,545 NEWS.txt

10/02/2023  01:27 PM           103,192 python.exe

10/02/2023  01:27 PM            68,376 python3.dll

10/02/2023  01:27 PM         6,972,184 python312.dll

10/02/2023  01:27 PM           101,656 pythonw.exe

05/05/2024  05:33 PM    <DIR>          Scripts

05/05/2024  05:32 PM    <DIR>          tcl

10/02/2023  01:27 PM           109,392 vcruntime140.dll

10/02/2023  01:27 PM            49,520 vcruntime140_1.dll

               8 File(s)      9,105,739 bytes

               9 Dir(s)  102,834,245,632 bytes free

===================================================================

There is also a executable pythonw.exe in the above folder. It will give no response should you click on it. It is supposed to work with a python GUI. If you need to use this you will have to use the other system files in the System.IO.

Finally, when we installed PyCharm from the JetBrains site, we created this directory. We also chose to include this in the PATH as shown.

C:\Program Files\JetBrains\PyCharm Community Edition 2023.3.3\bin;

What do we have in this directory?
The BIN folder has two Applications pycharm64 and jetbrains_client64. The jetbrains_client64.exe connects you to an external server if there is one installed. It is a thin client.

However, clicking python64.exe in the installation folder opens up the GUI of PyCharm as shown.


We will be using this for exploring the image recognition programs. Also, JetBrains created a shortcut for this executable on the desktop.




Friday, May 10, 2024

How do you create a 'Hello World' program using PyCharm?

 "Hello World" is a popular program sued in the introduction of many software programs made popular by Microsoft. Bern Kernighan of the Bell Laboratories used (1972) it in the documentation of BCPL when the language C was developed. It has been repeated for many languages.

Before we do this in the PyCharm, it is important to look at the PyCharm interface in some detail. The PyCharm IDE interface is just like other interfaces like Visual Studio IDE. That said, here are some major parts of this interface.

When you start the IDE interface, the first screen you encounter is the Welcome Screen shown here. In this screen, you have access to take a quick tour if you desire to do so.



The navigation pane on the left gives you access to the Projects, Customization, Plugins, and learning tools.

If you have already created a project, you could Open it, create a new one, or get one from the version control system as shown in the above image.

Since this the first time using this interface. Click to create a New Project. This is a Python IDE and therefore it uses Pure Python whose version is 3.12. Django is another option we will not be using now.

The default Project Name is python Project. Overwrite this and provide the name Helloworld as shown. Leave the location as is. Do not click to Create Git Repository. Place check park for Create a main.py welcome script as shown. Note that the project will be created in the C:\ drive at the location, C:\Users\hoden\PyCharm Projects\HelloWorld. The IDE also creates a virtual environment at the location shown on this screen. We will visit virtual environments later.

Now, click Create at the bottom. The program starts running and takes a minute or so and you will see the screen shown here displayed. The Helloworld main program is created. main.py is python file created and the main.py script is shown on the right.

The project is ready to run. If you run the code on the right by clicking the green button shown in the above image. You will immediately see the result of running at the bottom as shown below. The program prints the words, "Hi, PyCharm".

What if you want it to print, Hello World".? Go back to the project screen as shown. Now, overwrite PyCharm in the bottom of the main.py's code window shown.

Now, hit the green button again. You will see, "Hi, Hello World" as shown.

==============

C:\Users\hoden\PycharmProjects\Helloworld\.venv\Scripts\python.exe C:\Users\hoden\PycharmProjects\Helloworld\main.py 

Hi, Hello World

Process finished with exit code 0

=====================

Where did the Hi come from?

Think how you can change this.

Sunday, April 28, 2024

How easy is it to work with image recognition using PyCharm Community edition?

 

PyCharm Community edition is a very powerful IDE for developing Python applications. Community editions while free lack all the features of a professional edition. 

PyCharm has many desirable features:

1. Supports image processing libraries such as PIL(Pillow), OpenCV and matplotlib. These libraries can be installed from within PyCharm using pip.

2. You can easily create Python files(.py)

   PIL after installing can be used to work with images(Load, manipulate and save)

   Image manipulation allows loading, resizing, filtering and saving of images

3. It has a Python Console for quickly running and testing experimental codes. Console also supports         displaying images directly in the console.

4. PyCharm allows youto format Python code consistently and has built-in refactoring tools that help in        maintaining code and improving readability.

5. PyCharm's virtual environments can isolate image processing project from other Python projects.

6. For image recognition, you will require other deep learning libraries such as Keras and TensorFLow.

   For image classification you can build and train custom conventional neural networks(CNNs)

   For feature extraction and preprocessing you can use PIL and OpenCV before feeding into neural 

   network

   Extend image recognition to object detection within an image

   You can visualize model performance, loss curves and accuracy metrics using matplotlib

   OpenCV and ImageViewer plugins allow for efficient image manipulation and analysis.

This should take you quite bit into the image processing tasks

How do you install PyCharm Community Edition?

Just follow the link.


Run the executable file preferably as the administrator. The PyCharm will be installed pretty quickly.




Thursday, March 21, 2024

How do I implement or use AI features in Microsoft Excel?

Microsoft Excel belongs to the group of Microsoft 365 programs and you need to have a subscription to use it.

As to using AI features in Microsoft 365 you need to subscribe to CoPilot Pro associated with the Microsoft 365 account. You need to spend like $20 per month to have this capability. This subscription will allow you to:

1. Analyze Data The Copilot can be tasked to provide appropriate help on formulas, predictions and correlations of all sorts.

2. It allows SWOT analysis or matrix, a strategic planning and management technique. It claims to find strengths(S), weaknesses(W), opportunities(O) and threats(T) from competitors. A tool for fact based strategic decision making that may provide new insights and ideas at improving the business. Here is graphic copied from the web (https://templatelab.com/swot-analysis-templates/).

In order to use these features, you need to update your Microsoft 365 license. Click File and at the bottom group click on Update License. You get a verify your subscription. Follow the instructions.