Jump to content

Wikipedia:Reference desk/Archives/Computing/2021 February 13

From Wikipedia, the free encyclopedia
Computing desk
< February 12 << Jan | February | Mar >> February 14 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


February 13

[edit]

Python library lost, or not, in Big Sur

[edit]

I recently updated MacOS to Big Sur. In some of my Python programs that contain the line

import Image

I now get

ImportError: No module named Image

... but at least one program is not affected. The 'surviving' program is ~/bin/dragon, while all those that fail are ~/some_other_directory/*.py; perhaps this is coincidence, perhaps not. (Each begins with #!/usr/local/bin/python.)

Any idea what's going on? —Tamfang (talk) 02:11, 13 February 2021 (UTC)[reply]

Tamfang, what python version is used by your programs, and what python version is invoked by that path? Is there a /usr/local/bin/python3 or anywhere else on the system? Is your python interpreter installed by homebrew or is it a stock system? Elizium23 (talk) 08:35, 13 February 2021 (UTC)[reply]
I believe my python (2.7) is "stock", but the Image library isn't (I do not recall how I installed it). —Tamfang (talk) 16:09, 13 February 2021 (UTC)[reply]
/usr/bin/python3 exists but trying to run it gives xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrunTamfang (talk) 16:09, 13 February 2021 (UTC)[reply]
What do you see when you issue the command ls -l /usr/local/bin/python? Is it a link to another executable?  --Lambiam 11:47, 13 February 2021 (UTC)[reply]
link to /Library/Frameworks/Python.framework/Versions/2.7/bin/pythonTamfang (talk) 16:09, 13 February 2021 (UTC)[reply]
Image isn't a module in PyPi or builtins, so it came from somewhere else. from the naming convention, it's likely a class from a module, so maybe this is from PIL or some library that handles images? In your /~/bin/dragon, make it
print(Image.__file__)
if that fails, use .__dir__ instead. ~/bin might have an Image.py that's being imported instead.
As for your python3 path problem, I'm sure this SE answer can solve it; this has nothing to do with python probably, just your terminal. WhoAteMyButter (📨📝) 07:00, 14 February 2021 (UTC)[reply]
The command you suggest results in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/Image.pyc. (I first ran some old code that had import PIL; when that failed I looked at dragon and copied over import Image.) — I apparently acquired PIL/Image in 2009. Will have a look at its README when time allows. —Tamfang (talk) 01:56, 17 February 2021 (UTC)[reply]