Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spyder - python - install external packages

I have just started to use python (within Windows, 64bit) - and I have a basic question on how to install external packages within the anaconda / spyder environment. I understand that for most packages one can simply use “conda install bunnies”. However, certain packages are not in the anaconda repository, and might have be installed externally (e.g. from github). For those packages, in order to have spyder to recognize this package – does one only in addition have to update the PYTHONPATH manager in Spyder to include the directory (e.g. c:\users\bunnies) in which one has downloaded this package? Or should one take additional steps / is there a faster way?

like image 666
user1885116 Avatar asked Nov 05 '15 07:11

user1885116


People also ask

How do I install standalone Spyder packages?

Open the “gear” menu in Spyder's section under Home in Navigator. Go to Install specific version and select the version of Spyder you want to use.

How do I install an external module in Python?

Download and install External Modules in Python External modules in Python can also be downloaded and installed using pip which is a package manager. On the other hand, some modules such as the Math module need no installation. We just need to use the word import followed by the module name.


1 Answers

You have several options to use packages that are not (yet) available via conda install:

1.) If the respective package is on PyPi you can build it as described in the manual.

2.) If building from scratch doesn't work and the package is on PyPi you can also try an installation via pip. Not that you have to use the pip in your Anaconda distribution and not the one of your systems Python installation.

3.) If you want to include external packages or local folders that contain Python-scripts you can do the following.

3.1.) Use the sys module and append the required package/folder to the path:

import sys
sys.path.append(r'/path/to/my/package')

3.2) Or put the modules into into site-packages, i.e. the directory $HOME/path/to/anaconda/lib/pythonX.X/site-packages which is always on sys.path. (Source)

3.3) Or add a .pth file to the directory $HOME/path/to/anaconda/lib/pythonX.X/site-packages. This can be named anything (it just must end with .pth). A .pth file is just a newline-separated listing of the full path-names of directories that will be added to your path on Python startup. (Source)

Good luck!

like image 119
Cord Kaldemeyer Avatar answered Oct 04 '22 12:10

Cord Kaldemeyer