1

I am writing a python script that uses PIL library to resize an image.

Is it possible to see whether the user already has PIL installed on his machine, and if not, install it automatically (ask for admin password if needed)?

Nili
  • 1,963
  • 3
  • 20
  • 39

1 Answers1

1

Install pip by running this setup script, then install Pillow a subset of PIL:

pip install Pillow 
Malik Brahimi
  • 16,341
  • 7
  • 39
  • 70
  • I ran the script and got the following exception: Installing collected packages: pip Exception: Traceback (most recent call last): File "/var/folders/vh/jcvrl0tx07b8klnvrbklmfmw0000gn/T/tmpq7Xmrd/pip.zip/pip/basecommand.py", line 246, in main status = self.run(options, args) File "/var/folders/vh/jcvrl0tx07b8klnvrbklmfmw0000gn/T/tmpq7Xmrd/pip.zip/pip/commands/install.py", line 352, in run root=options.root_path, File "/var/folders/vh/jcvrl0tx07b8klnvrbklmfmw0000gn/T/tmpq7Xmrd/pip.zip/pip/req/req_set.py", line 693, in install **kwargs – Nili Apr 08 '15 at 11:25
  • File "/var/folders/vh/jcvrl0tx07b8klnvrbklmfmw0000gn/T/tmpq7Xmrd/pip.zip/pip/req/req_install.py", line 817, in install self.move_wheel_files(self.source_dir, root=root) File "/var/folders/vh/jcvrl0tx07b8klnvrbklmfmw0000gn/T/tmpq7Xmrd/pip.zip/pip/req/req_install.py", line 1018, in move_wheel_files isolated=self.isolated, File "/var/folders/vh/jcvrl0tx07b8klnvrbklmfmw0000gn/T/tmpq7Xmrd/pip.zip/pip/wheel.py", line 237, in move_wheel_files clobber(source, lib_dir, True) – Nili Apr 08 '15 at 11:27
  • File "/var/folders/vh/jcvrl0tx07b8klnvrbklmfmw0000gn/T/tmpq7Xmrd/pip.zip/pip/wheel.py", line 208, in clobber os.makedirs(destdir) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs mkdir(name, mode) OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip' – Nili Apr 08 '15 at 11:27
  • Im soure you know by now, but just for the record, you need to use sudo: `sudo pip install Pillow`. Also this should be marked as the correct answer since Pillow is a more modern fork of PIL. – Lucas Alonso Jan 28 '16 at 16:34
  • @MalikBrahimi running the script you suggested generated the errors I mentioned, so I can't mark it as an answer. – Nili Jan 31 '16 at 09:52
  • @Nili In the command line, enter `sudo apt-get install python-pip` – Malik Brahimi Jan 31 '16 at 16:43
  • Then you enter `pip install Pillow` once you're done with that. – Malik Brahimi Jan 31 '16 at 16:43