Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a module (Specifically pymorph) to Spyder (Python IDE)

I have managed to get spyder installed and functioning on my mac but I want to add in a few modules that it doesn't include by default (mahotas and pymorph).

I installed both via easy_install in the terminal and both seemed to install without any error messages. Running python from a terminal and using import mahotas and import pymorph works just fine without error messages. However, when I run the same lines from a script within spyder I get the following error:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 493, in runfile  execfile(filename, namespace) File "/Users/Name/Documents/Python/dna.py", line 11, in <module>  import pymorph ImportError: No module named pymorph 

All I'm trying to do right now is run the import lines, that's it. I can't seem to find anything about this. I'm guessing that spyder uses a separate install of python and that installing modules via the terminal installs them only to the system version of python. How do I add them to spyder?

Specs:

Mac OSX 10.7.4

Spyder 2.1.9

like image 854
Daniel Avatar asked May 23 '12 23:05

Daniel


People also ask

Can I do pip install on Spyder?

You can install Spyder with the pip package manager, which comes by default with most Python installations. Before installing Spyder itself by this method, you need to acquire the Python programming language.

How do I install Python modules?

You can install modules or packages with the Python package manager (pip). To install a module system wide, open a terminal and use the pip command. If you type the code below it will install the module. That will install a Python module automatically.


2 Answers

Ok, no one has answered this yet but I managed to figure it out and get it working after also posting on the spyder discussion boards. For any libraries that you want to add that aren't included in the default search path of spyder, you need to go into Tools and add a path to each library via the PYTHONPATH manager. You'll then need to update the module names list from the same menu and restart spyder before the changes take effect.

like image 128
Daniel Avatar answered Sep 21 '22 12:09

Daniel


Using ! on the IPython console within spyder allows you to use pip. So, in the example, you could do:

[1] !pip install pymorph 

Note, this is also available (though perhaps unreliably) on the Python console for Spyder versions before ~2.3.3. Thanks to @CarlosCordoba for this clarification.

like image 34
atomh33ls Avatar answered Sep 20 '22 12:09

atomh33ls