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

Sunday, September 29, 2024

If your python environment does not have pip installed. What then?

Over a period of time, there was some computer problem which needed complete recovery. Before this event, I had installed PyCharm and had everything working without problem and I had even installed PIL library from within PyCharm. However, after the recovery, I lost some of the files.

Besides, PIL I wanted to install other libraries to work with images. When I tried to open an existing project in PyCharm, I encountered errors.

All Python packages were absent and the program was asking me for a Python interpreter.

What happened to my python?

Before proceeding to other image related libraries, I had to fix this problem.

If your Python environment does not have pip installed you need to install pip first. There are two ways to install pip supported by the pip's maintainers:

ensurepip       -------->run py -3 -m ensurepip

or run get-pip.py------->run get-pip.py using python interpreter

Because of the recovery created problem, I did not have python interpreter according to PyCharm (as shown in the first image above).

I need to install python even before I can install pip.

I tried to find python.dll which I could not as I had lost it during recovery.

Finally, I found it in the Windows.old folder [C:\Windows.old07042024\Users\hoden\AppData\Local ]

I copied the python.exe from the windows.old folder to Windows/system32.

 I tried to run from the command-line with administrative privileges:

-------

C:\Users\hoden\OneDrive\Desktop\PyCharm\PIL>python get-pip.py

Could not find platform independent libraries <prefix>

Collecting pip

  Downloading pip-24.2-py3-none-any.whl.metadata (3.6 kB)

Downloading pip-24.2-py3-none-any.whl (1.8 MB)

   ---------------------------------------- 1.8/1.8 MB 33.0 MB/s eta 0:00:00

Installing collected packages: pip

  WARNING: The scripts pip.exe, pip3.12.exe and pip3.exe are installed in 'C:\Users\hoden\OneDrive\Desktop\PyCharm\PIL\Scripts' which is not on PATH.

  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

Successfully installed pip-24.2

-----------

I ran into another problem because of the 'Onedrive'. Permit me to call it 'oneDrive" interference.

Finally, I copied the python folder into Windows\System32 of local computer and restarted the computer(laptop). The problem was resolved as seen in PyCharm.

Finally, both the Python Console and the Python packages are all back in PyCharm.

More here:




 

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.