#! /usr/bin/python3
# On 10/4/22 I installed version Python 3.10.7
# Does not work
# Traceback (most recent call last):
# File "/home/andy/Python/png2jpg.py", line 10, in <module>
# from PIL import Image
# ModuleNotFoundError: No module named 'PIL'
import math
import os
import sys
from PIL import Image
if len(sys.argv) > 1:
if os.path.exists(sys.argv[1]):
im = Image.open(sys.argv[1])
target_name = sys.argv[1] + ".jpg"
rgb_im = im.convert('RGB')
rgb_im.save(target_name)
print("Saved as " + target_name)
else:
print(sys.argv[1] + " not found")
else:
print("Usage: convert2jpg.py <file>")
ERROR: Could not find a version that satisfies the requirement Pillow (from versions: none)
ERROR: No matching distribution found for Pillow
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=âpypi.orgâ, port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(âCanât connect to HTTPS URL because the SSL module is not available.â)) - skipping
WARNING: There was an error checking the latest version of pip.
Thanks for your help. I installed it, but I get the same error.
I wish I could find someone running Ubuntu Mate 18.04 who is using Python.
This is a nice script I found that lets you paste snippets.
It runs because it uses no modules.
#!/usr/bin/env python3
#
# /home/andy/.config/snippet_paste/ is where text to be inserted reside.
# Use Alt P to activate
import os
import subprocess
home = os.environ["HOME"]
directory = home+"/.config/snippet_paste"
if not os.path.exists(directory):
os.mkdir(directory)
# create file list with snippets
files = [
directory+"/"+item for item in os.listdir(directory) \
if not item.endswith("~") and not item.startswith(".")
]
# create string list
strings = []
for file in files:
with open(file) as src:
strings.append(src.read())
# create list to display in option menu
list_items = ["manage snippets"]+[
(str(i+1)+". "+strings[i].replace("\n", " ").replace\
('"', "'")[:20]+"..") for i in range(len(strings))
]
# define (zenity) option menu
test= 'zenity --list '+'"'+('" "')\
.join(list_items)+'"'\
+' --column="text fragments" --title="Paste snippets"'
# process user input
try:
choice = subprocess.check_output(["/bin/bash", "-c", test]).decode("utf-8")
if "manage snippets" in choice:
subprocess.call(["seamonkey", directory])
else:
i = int(choice[:choice.find(".")])
# copy the content of corresponding snippet
copy = "xclip -in -selection c "+"'"+files[i-1]+"'"
subprocess.call(["/bin/bash", "-c", copy])
# paste into open frontmost file
paste = "xdotool key Control_L+v"
subprocess.Popen(["/bin/bash", "-c", paste])
except Exception:
pass
python3.6 -m pip install --upgrade pip
python3.6 -m pip install --upgrade Pillow
#! /usr/bin/python3.6
# Use python3.6 [name of python script]
# Much help from ironfoot and karel
import os
import sys
from PIL import Image
if len(sys.argv) > 1:
if os.path.exists(sys.argv[1]):
im = Image.open(sys.argv[1])
target_name = sys.argv[1] + ".jpg"
rgb_im = im.convert('RGB')
rgb_im.save(target_name)
print("Saved as " + target_name)
else:
print(sys.argv[1] + " not found")
else:
print("Usage: convert2jpg.py <file>")
Did these succeed? I donât see a transcript eg shell prompt and
resulting output.
Example here:
[~/hg/css-ebooks(hg:ebooks)]fleet2*> /usr/local/bin/python3.8 -m pip install --upgrade Pillow
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Requirement already satisfied: Pillow in
/Users/cameron/Library/Python/3.8/lib/python/site-packages (8.3.1)
Collecting Pillow
Using cached Pillow-9.2.0-cp38-cp38-macosx_10_10_x86_64.whl (3.1 MB)
Installing collected packages: Pillow
Attempting uninstall: Pillow
Found existing installation: Pillow 8.3.1
Uninstalling Pillow-8.3.1:
Successfully uninstalled Pillow-8.3.1
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Successfully installed Pillow-9.2.0
WARNING: You are using pip version 21.2.4; however, version 22.2.2 is available.
You should consider upgrading via the '/usr/local/opt/python@3.8/bin/python3.8 -m pip install --upgrade pip' command.
Ignore the deprecation warnings, theyâre an artifact of the local
environment.
#! /usr/bin/python3.6
This will indeed run the script using /usr/bin/python3.6 if you invoke
the script directly as a command.
But you can run it with any Python interpret to test its behaviour with
that interpreter, eg:
python3.6 png2jpg.py Dust_Collector.png
Saved as Dust_Collector.png.jpg
Eventually I want to fix it so it outputs Dust_Collector.jpg.
if len(sys.argv) > 1:
if os.path.exists(sys.argv[1]):
im = Image.open(sys.argv[1])
# Backspace 4 spaces and add .jpg
target_name = "sys.argv[1] - 4" + ".jpg"
rgb_im = im.convert('RGB')
rgb_im.save(target_name)
print("Saved as " + target_name)
else:
print(sys.argv[1] + " not found")
else:
print("Usage: convert2jpg.py <file>")
This does save it with .jpg but the file name is mangled.