问题
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
回答1:
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.
回答2:
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.
回答3:
Find the location of a module in Terminal:
$ python # open python import pygame # import a module pygame # get the location
Copy-paste the module folder to the 'Spyder.app/Contents/Resources/lib/python2.7'
Relaunch Spyder.app
回答4:
If you are using Spyder in the Anaconda package...
In the IPython Console, use
!conda install packageName
This works locally too.
!conda install /path/to/package.tar
Note: the ! is required when using IPython console from within Spyder.
回答5:
just use '!' before the pip command in spyder terminal and it will be fine
Eg:
!pip install imutils
回答6:
You can add the Standard Installation location to the PYTHONPATH manager. This way you don't need to add a specific path for each module. Only to update module names.
On Unix this location is usually:
/usr/local/lib/pythonX.Y/site-packages
On Windows:
C:\PythonXY\Lib\site-packages
See the modules install Documentation.
回答7:
I faced the same problem when trying to add the seaborn module in Spyder. I installed seaborn into my anaconda directory in ubuntu 14.04. The seaborn module would load if I added the entire anaconda/lib/python2.7/site-packages/ directory which contained the 'seaborn' and seaborn-0.5.1-py2.7.egg-info folders. The problem was this anaconda site-packages folder also contained many other modules which Spyder did not like.
My solution: I created a new directory in my personal Home folder that I named 'spyderlibs' where I placed seaborn and seaborn-0.5.1-py2.7.egg-info folders. Adding my new spyderlib directory in Spyder's PYTHONPATH manager worked!
回答8:
One can also follow the below steps : Spyder -> Tools -> Open Command Prompt -> write the command "pip install html5lib"
来源:https://stackoverflow.com/questions/10729116/adding-a-module-specifically-pymorph-to-spyder-python-ide