Cannot import PIL into Python Shell, but can into Terminal - shell

I have installed Pillow on may Macintosh using sudo pip install Pillow in Terminal. I know it is installed because whenever I run import PIL in the Terminal window after typing python, this is my output:
Terminal output:
Python 3.5.1 |Anaconda 2.4.1 (x86_64)| (default, Dec 7 2015, 11:24:55)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
>>>
However, the weird thing is that in the Python Shell, when i do the same thing, I get this:
Python Shell (IDLE) output:
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> import PIL
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import PIL
ImportError: No module named 'PIL'
Why is it that I can import the Python Imaging Library (PIL) in the Macintosh Terminal, but not in the Python Shell, and how would I fix this issue?

You should never use sudo to install a python module.
When you have multiple versions of python installed, each one has its own name, its own pip, and its own IDLE. The command you issue on the command line determines which python will launch. One of the versions of python that you installed will be linked to the name python while other versions will have a name that includes the version, e.g. python3.5.
To keep straight which version of python you are launching, you can launch python with its version name, python3.5, execute pip with its version name, pip3.5, and start IDLE with its version name, idle3.5.
Here are some commands that will help you figure out where pip install Pillow is installing modules:
~$ which pip
/usr/local/bin/pip
~$ cd /usr/local/bin
/usr/local/bin$ ls -al pip*
lrwxrwxr-x 1 root admin 65 Apr 10 2015 pip ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pip
lrwxrwxr-x 1 root admin 66 Apr 10 2015 pip2 ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pip2
lrwxrwxr-x 1 root admin 68 Apr 10 2015 pip2.7 ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pip2.7
lrwxrwxr-x 1 root admin 66 Apr 7 2015 pip3 ->
../../../Library/Frameworks/Python.framework/Versions/3.4/bin/pip3
lrwxrwxr-x 1 root admin 68 Apr 7 2015 pip3.4 ->
../../../Library/Frameworks/Python.framework/Versions/3.4/bin/pip3.4
The syntax pip -> means that the name pip is linked to the file after the arrow. You can see where those names are pointing and therefore which python that pip is installing modules into.
===
You have Anaconda installed, and Anaconda hijacks the names python and pip for its own use, so you will see something like this:
~$ which python
/Users/7stud/anaconda/bin/python
~$ which pip
/Users/7stud/anaconda/bin/pip
Anaconda does not hijack the name idle, so idle points to another python install:
~$ which idle
/usr/local/bin/idle
~$ cd /usr/local/bin
/usr/local/bin$ ls -al idle*
lrwxr-xr-x 1 root wheel 66 Apr 10 2015 idle ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/idle
lrwxr-xr-x 1 root wheel 67 Apr 10 2015 idle2 ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/idle2
lrwxr-xr-x 1 root wheel 69 Apr 10 2015 idle2.7 ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/idle2.7
lrwxr-xr-x 1 root wheel 67 Apr 7 2015 idle3 ->
../../../Library/Frameworks/Python.framework/Versions/3.4/bin/idle3
lrwxr-xr-x 1 root wheel 69 Apr 7 2015 idle3.4 ->
../../../Library/Frameworks/Python.framework/Versions/3.4/bin/idle3.4
Anaconda hijacks the names python and pip by adding the following line to the end of the file ~/.bash_profile:
export PATH="/Users/7stud/anaconda/bin:$PATH"
When you issue a command on the command line, the terminal window searches for that command in the directories specified in your PATH environment variable--in order. Because the Anaconda path is on the front of the PATH variable, the Anaconda directory is searched first for the commands python and pip and idle. The python command is found in that directory:
~$ which python
/Users/7stud/anaconda/bin/python
~$ cd /Users/7stud/anaconda/bin/
~/anaconda/bin$ ls -al python*
lrwxr-xr-x 1 7stud staff 9 Dec 22 05:29 python -> python3.5
-rwxrwxr-x 1 7stud staff 272 Dec 22 05:29 python-argcomplete-check-easy-install-script
-rwxrwxr-x 1 7stud staff 129 Dec 22 05:29 python.app
lrwxr-xr-x 1 7stud staff 9 Dec 22 05:29 python3 -> python3.5
lrwxr-xr-x 1 7stud staff 17 Dec 22 05:29 python3-config -> python3.5m-config
-rwxrwxr-x 1 7stud staff 9096 Dec 7 10:27 python3.5
(In addition to the name python, you can also see the names python3 and python3.5. Because python and python3 both point to python3.5, the commands python, python3, and python3.5 all execute the same python.)
The pip command is also found in the Anaconda directory:
$ which pip
/Users/7stud/anaconda/bin/pip
$ cd /Users/7stud/anaconda/bin
~/anaconda/bin$ ls -al pip*
-rwxrwxr-x 1 7stud staff 125 Dec 22 05:29 pip
There's only one name for pip.
But, the idle command is not found in the Anaconda directory:
~$ which idle
/usr/local/bin/idle
Double checking:
~$ cd ~/anaconda/bin
~/anaconda/bin$ ls -al idle*
lrwxr-xr-x 1 7stud staff 7 Dec 22 05:29 idle3 -> idle3.5
-rwxrwxr-x 1 7stud staff 108 Dec 22 05:29 idle3.5
The name idle is not the same as idle3 or idle3.5, so the search for idle continues on in the other directories in the PATH variable. If you want to launch the Anaconda idle, you can use either the name idle3 or idle3.5.
Because I hate the way Anaconda hijacks all those python names, which prevents me from using those names to run my other python versions, when I'm not using Anaconda I comment out the following line in ~/.bash_profile:
# export PATH="/Users/7stud/anaconda/bin:$PATH"
To get changes you make in ~./bash_profile to take effect, you need to either close the terminal window and launch a new window, or issue the command:
$ source ~/.bash_profile
Another way to keep Anaconda from hijacking all those python names is by doing the following:
~/anaconda/bin$ mv python xpython #change the name to xpython
~/anaconda/bin$ mv python3 xpython3
~/anaconda/bin$ cp python3.5 pyana #copy to a new name
~/anaconda/bin$ mv python3.5 xpython3.5
That preserves all the original names under pseudonyms (in case something goes wrong you can change the x-names back to the originals), and it also creates the name pyana for your Anaconda python. Now the names python, python3, etc. will still point to the same python versions they did before you installed Anaconda:
~/anaconda/bin$ which python
/usr/local/bin/python
~/anaconda/bin$ which python3
/usr/local/bin/python3
~/anaconda/bin$ which pyana
/Users/7stud/anaconda/bin/pyana
~/anaconda/bin$ pyana --version
Python 3.5.1 :: Anaconda 2.4.1 (x86_64)
~/anaconda/bin$ pyana
Python 3.5.1 |Anaconda 2.4.1 (x86_64)| (default, Dec 7 2015, 11:24:55)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Edit: Some time later I found that openssl is found in Anaconda's directory as well, so I've gone back to commenting out the line in .bash_profile when I'm not using Anaconda--Anaconda just hijacks too many names.

Related

Mac os permissions prevent me to delete files

I installed easy_install on mac wityh the following command:
curl https://bootstrap.pypa.io/ez_setup.py -o - | sudo python
After that I tried to install pip but couldn't.
After checking here is what I have in /usr/bin
$ ls -l easy*
-rwxr-xr-x 2 root wheel 925 7 Jan 2016 easy_install
-rwxr-xr-x 1 root wheel 454 7 Jan 2016 easy_install-2.6
-rwxr-xr-x 1 root wheel 461 7 Jan 2016 easy_install-2.7
Probably it does not work because I have 2 versions installed now. I am in the list of sudoers but even with sudo I cannot delete these files:
sudo rm -f easy_install-2.6
Password:
rm: easy_install-2.6: Operation not permitted
When I log in to this macbook there is my username and also Administrator which I do not have access to now.
Is there a way to be able to delete these files without having to wait until the person that has the password for Administrator comes back from vacation?
Here is my macbook info
System Version: OS X 10.11.6 (15G31)
Kernel Version: Darwin 15.6.0
Boot Volume: Macintosh HD
Thanks

gcc with MacPorts (select not changing the right link)

I followed the instructions for installing GCC 4.7 with MacPorts.
http://www.ficksworkshop.com/blog/14-coding/65-installing-gcc-on-mac
Everything seems to work, but 'select set' is not updating the right (AFAIK) link.
$ gcc -version
i686-apple-darwin11-llvm-gcc-4.2: no input files
$ which gcc
/usr/bin/gcc
$ ls -l /usr/bin/gcc
lrwxr-xr-x 1 root wheel 12 Jul 14 2013 /usr/bin/gcc -> llvm-gcc-4.2
According to the guide, Macports installs to /opt/local/bin. Select is changing that link accordingly:
$ ls -l /opt/local/bin/gcc
lrwxr-xr-x 1 root admin 25 Sep 28 12:20 /opt/local/bin/gcc -> /opt/local/bin/gcc-mp-4.7
But make is calling /usr/bin/gcc.
Can I manually change the symbolic link or is there a more elegant solution?
You need to put /opt/local/bin earlier in your PATH than /usr/bin. As I recall, the installer package for MacPorts modifies your ~/.profile or ~/.bash_profile to do this for you. However, that will only affect shells which are started after installing MacPorts.
So, the first thing to try is to simply open a new shell and see if things are working as you expect there.

Can't run `bzr explorer` on Mac OS 10.9.x

Unfortunately, the answer to this question did not answer my problem. :(
I have the following installed:
$ python
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
$ brew install qt
Warning: qt-4.8.6 already installed
$ brew install pyqt
Warning: pyqt-4.11.1 already installed
$ brew install sip
Warning: sip-4.16.3 already installed
Then when I try to run bzr explorer, it returns the following:
$ bzr explorer
bzr: ERROR: No module named PyQt4
You may need to install this Python library separately.
I am running on Mac OS 10.9.x.
My /Users/me/.bazaar/plugins directory have the following:
$ ll
total 0
drwxr-xr-x 25 me staff 850 Oct 9 15:21 explorer
drwxr-xr-x 20 me staff 680 Oct 9 15:22 qbzr
What am I missing?

IPython launching error with Enthought Python Distribution

I have an Academic license with Enthought Python Distribution, and I'm getting a strange error when I try to run ipython. Here is some of the behavior I'm seeing:
$ ipython
Traceback (most recent call last):
File "/Library/Frameworks/EPD64.framework/Versions/Current/bin/ipython", line 8, in <module>
from IPython import start_ipython
ImportError: cannot import name start_ipython
$ python
Enthought Python Distribution -- www.enthought.com
Version: 7.3-2 (64-bit)
Python 2.7.2 |EPD 7.3-2 (64-bit)| (default, Sep 7 2011, 16:31:15)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "credits", "demo" or "enthought" for more information.
>>> import IPython
>>> IPython.start_ipython()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'start_ipython'
>>>
When I run the enpkg enstaller, it updated ipython and it looked like everything worked OK.
$ sudo enpkg ipython
prefix: /Library/Frameworks/EPD64.framework/Versions/7.2
No update necessary, 'ipython' is up-to-date.
ipython-1.1.0-6.egg was installed on: Sun Jan 19 23:57:27 2014
$ which ipython
/Library/Frameworks/EPD64.framework/Versions/Current/bin/ipython
$ which python
/Library/Frameworks/EPD64.framework/Versions/Current/bin/python
Any help or suggestions what I can do to get ipython to work again?
Same issue here on my Academic license with Enthought Python Distribution. I followed the steps outlined in answer and can confirm everything is working properly now. There's no mention of this solution on the Enthought Knowledge Base. Thanks!
One addition to the answer: in order to find the directory you need to remove from your system . . .
$ python
import IPython
print IPython
Ok after looking around, I found a problem where someone said another install of ipython might be causing problems. enpkg is trying to install ipython 1.1.0 but I still had 0.13.1 around. So I removed it via:
$ sudo rm -rf /Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/ipython-0.13.1-py2.7.egg
Then it loaded with errors about kernmagic so:
$ sudo enpkg kernmagic
It somehow re-installed ipython 1.0
$ ipython
Python 2.7.2 |EPD 7.3-2 (64-bit)| (default, Sep 7 2011, 16:31:15)
Type "copyright", "credits" or "license" for more information.
IPython 1.0.0 -- An enhanced Interactive Python.
So simply re-trying the enpkg command installs the latest version.
$ sudo enpkg ipython
prefix: /Library/Frameworks/EPD64.framework/Versions/7.2
ipython-1.0.0-2.egg [removing]
12.84 MB [.................................................................]
Jinja2-2.6-2.egg [removing]
1.58 MB [.................................................................]
tornado-2.2-1.egg [removing]
1.42 MB [.................................................................]
tornado-3.1.1-1.egg [installing]
2.16 MB [.................................................................]
Jinja2-2.7.1-1.egg [installing]
1.62 MB [.................................................................]
ipython-1.1.0-6.egg [installing]
12.92 MB [.................................................................]
$ ipython
Python 2.7.2 |EPD 7.3-2 (64-bit)| (default, Sep 7 2011, 16:31:15)
Type "copyright", "credits" or "license" for more information.
IPython 1.1.0 -- An enhanced Interactive Python.
And now it runs without errors. So, hopefully that helps anyone else coming across these kinds of problems.

Updating Ant on mac

I am running ant 1.8.2 and I want to up date to the latest on my mac. What is the best way to do this? Should I remove then install or can i write over the previous?
I use it in both Eclipse and from the command line. I also have jenkins call ant targets. It's currently set in /usr/local
I found these two links to update Ant on mac:
Seventy6.com
Ninjascript.com
I had Ant 1.8.4 installed on my Mac 10.8.5 and upgraded to:
Apache Ant(TM) version 1.9.4 compiled on April 29 2014
The first website from seventy6 said all of the below, with a few updates from myself.
To see what version you currently have installed run this:
$ ant -version
Apache Ant version 1.7.1 compiled on February 11 2010
I was advised to use the simple OSX package installer homebrew. I’m not going to discuss how to install this, as they have a really simple guide. However, it’s not obvious how to install Apache Ant as it’s not one of the packages they list. So here is the brew to get started:
$brew install https://raw.github.com/adamv/homebrew-alt/master/duplicates/ant.rb
EDIT: You can also just install now with homebrew just by typing the following
$brew install ant
Beware, you might need to install Apple’s XCode, which if you’re still running OS X 10.6 or lower (like me) you can’t install the latest version (4) via the wonderful (?) AppStore. Ha! fun and games! Luckily, I have an Apple Developer account which allows you to download archived releases of Apple’s software. I created this ages ago and assume they’re still free to do… Once installed it puts the package here:
/usr/local/Cellar/ant/1.8.2
I then scratched my head for a while as to how to get OSX to use the newly installed version. It seems the easiest option is to remove the symlink currently set for the system. Run this to see where this is:
$ whereis ant
/usr/bin/ant //returned message
So we need to remove the symlink and set it to our new installed copy. I found this article which got me started. Useful, but not perfect for a homebrew package install. So here is the final commands to change the symlink to the homebrew version:
$ cd /usr/share
$ sudo rm /usr/share/ant
Password:
************
$ ln -s /usr/local/Cellar/ant/1.8.2 ant
You now need to close your current terminal session and open a new one. In theory you should be able to run 'ant -version' to get the latest version…
$ ant -version
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
I’m not sure if it’s best way to do it. But it’s a simple technique which can easily be updated if needed. At least you haven’t removed the base Java install of Ant from your system!
DONE
Also from blog.ninjascript.com, I saw this was interesting to know about:
Now Ant is kind of buried in OS X; the $PATH variable points to a symlink which points to another symlink. To find out where ant really is, just follow the chain:
$ which ant
/usr/bin/ant
$ ls -la /usr/bin/ant
lrwxr-xr-x 1 root wheel 22 Nov 11 18:04 /usr/bin/ant -> /usr/share/ant/bin/ant
$ ls -la /usr/share/ant
lrwxr-xr-x 1 root wheel 14 Nov 11 18:04 /usr/share/ant -> java/ant-1.7.1
$ ls -la /usr/share/java/ant-1.7.1
total 40
drwxr-xr-x 8 root wheel 272 Feb 27 12:32 .
drwxr-xr-x 8 root wheel 272 Nov 11 18:04 ..
-rw-r--r-- 1 root wheel 15289 Feb 10 2010 LICENSE.txt
-rw-r--r-- 1 root wheel 1270 Feb 10 2010 NOTICE.txt
drwxr-xr-x 8 root wheel 272 Feb 10 2010 bin
drwxr-xr-x 3 root wheel 102 Feb 10 2010 docs
drwxr-xr-x 15 root wheel 510 Feb 10 2010 etc
drwxr-xr-x 44 root wheel 1496 Feb 27 12:09 lib

Resources