4

I typed the following into textwrangler:

import numpy as np
import scipy
import matplotlib.pyplot as plt
import sphviewer

when I run it in terminal, this shows up in terminal:

Traceback (most recent call last):
  File "/private/var/folders/rx/sn0wllt54c724747zcn3nbr00000gt/T/Cleanup At Startup/setup-428001816.413.py", line 4, in <module>
    import sphviewer
ImportError: No module named sphviewer

Why wouldn't it import sphviewer? I already typed this in terminal before:

pip install py-sphviewer
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Tze Goh
  • 41
  • 2
  • 1
    do you have more than one python installation? – Padraic Cunningham Jul 25 '14 at 17:54
  • I have anaconda, canopy and text wrangler, but I would only like to use textwrangler. I have python 2.5 and 2.6, but what has this to do with the sphviewer? – Tze Goh Jul 30 '14 at 16:25
  • because different installations can have different paths where the are packages are, therefore you could install for one interpreter and be using another – Padraic Cunningham Jul 30 '14 at 16:26
  • How would I install sphviewer into textwrangler ? The only way that I know how to install in python is to type "pip install py-sphviewer" into terminal. – Tze Goh Jul 30 '14 at 16:31
  • what interpreter is textwrangler using? – Padraic Cunningham Jul 30 '14 at 16:34
  • What do you mean by 'interpreter' ? I open this application called Textwrangler, I write the code in it ( in python language ), I hit this button that says 'Run in Terminal', and I guess the program runs in terminal, and it would then show a plot if I import and use Matplotlib. But somehow, I can't seem to add new modules to it, like sphviewer and others. – Tze Goh Jul 30 '14 at 16:39
  • I have never used it but I know you cannot run python programs without an interpreter. Ok from textwrangler, run `import sys` `print sys.path` – Padraic Cunningham Jul 30 '14 at 16:42
  • I typed in import sys print sys.path into Textwrangler, and this is what it says : – Tze Goh Jul 30 '14 at 16:48
  • ['/private/var/folders/rx/sn0wllt54c724747zcn3nbr00000gt/T/Cleanup At Startup', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyfits-3.1-py2.7-macosx-10.6-x86_64.egg', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyregion-1.1_git-py2.7-macosx-10.6-x86_64.egg', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyparsing-1.5.6-py2.7.egg', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages – Tze Goh Jul 30 '14 at 16:49
  • /setuptools-0.6c11-py2.7.egg', '/usr/local/lib/wxPython-3.0.0.0/lib/python2.7/site-packages', '/usr/local/lib/wxPython-3.0.0.0/lib/python2.7/site-packages/wx-3.0-osx_cocoa', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat- – Tze Goh Jul 30 '14 at 16:49
  • mac/lib-scriptpackages', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib – Tze Goh Jul 30 '14 at 16:49
  • /python2.7/site-packages/PIL', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyObjC', '/Library/Python/2.7/site-packages', '/usr/local/lib/wxPython-3.0.0.0/lib/python2.7'] logout [Process completed] – Tze Goh Jul 30 '14 at 16:50
  • and `which python` ? Also I see python 2.7 not 2.5 or 2.6 – Padraic Cunningham Jul 30 '14 at 16:51
  • what do you mean by 'which python' ? If you mean the version, then it would be python 2.7 .... I made a mistake earlier, it is not 2.5 or 2.6 – Tze Goh Jul 30 '14 at 17:00
  • run these commands in bash `which -a python` and `which python` – Padraic Cunningham Jul 30 '14 at 17:01
  • When I type "//anaconda/bin/python /usr/bin/python – Tze Goh Jul 30 '14 at 17:05
  • When I type in "which -a python" into terminal, this is what is says "//anaconda/bin/python /usr/bin/python" – Tze Goh Jul 30 '14 at 17:05
  • When I type in "which python" into terminal, this is what it says : – Tze Goh Jul 30 '14 at 17:06
  • //anaconda/bin/python – Tze Goh Jul 30 '14 at 17:07
  • start a python shell and try `import sphviewer`, NOT textwrangler – Padraic Cunningham Jul 30 '14 at 17:08
  • I type 'import sphviewer' into Anaconda, and it seems to work. Thanks! But does this mean that I can't ever use TextWrangler to run python if I want to use sphviewer and other new modules ? – Tze Goh Jul 30 '14 at 17:17
  • I imagine textwrangler is using your system python. Anaconda adds a path to bash so that is where your packages are getting installed, you need to set the path to use the Anaconda interpreter somehow in textwrangler – Padraic Cunningham Jul 30 '14 at 17:35

1 Answers1

1

You should start out by verifying that sphviewer is installed on your system (I know it probably is, but it's worth the extra 5 seconds just to be sure).

pip freeze | grep sphviewer

If there's no output, then it's not installed. I noticed you didn't include sudo in your install command. Depending on how your system is configured, you may need that to successfully install the module

sudo pip install py-sphviewer

If you still can't import try entering this:

python -c "import sys; print sys.path"

This will show you where python is looking to find installed packages. The sphviewer files should be in one of the shown directories. If it's not, you'll have to see where pip installed it. In theory you can do

python -c "import pip; print pip.get_installed_distributions"

to see everything (though if you can't import the package, it might not be there either). If it's not there you'll have to find the location using other means. Once you have the containing directory, add it to your path.

Note: if you're using virtual environments, you will probably have to re-install this package in the virtual environment separately.

Community
  • 1
  • 1
Skunkwaffle
  • 596
  • 4
  • 18
  • I checked the ' python -c "import sys; print sys.path" ' , and it says that all of the paths are under ' anaconda '. Would this make any difference, as I am only using Textwrangler ? – Tze Goh Jul 30 '14 at 16:27
  • If you used anaconda, you probably have more than one installation. Assuming you're on a Mac (textwrangler is Mac I believe) the machine probably had python installed already, and then anaconda installed a duplicate version. This may be helpful: http://stackoverflow.com/questions/2812520/pip-dealing-with-multiple-python-versions – Skunkwaffle Jul 30 '14 at 21:21