Spyder-Python-安装外部软件包 [英] Spyder - python - install external packages

查看:493
本文介绍了Spyder-Python-安装外部软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用python(在Windows中为64位)-我对如何在anaconda/spyder环境中安装外部软件包有一个基本问题.我了解,对于大多数软件包来说,人们可以简单地使用"conda安装小兔子".但是,某些软件包不在anaconda存储库中,并且可能已在外部安装(例如从github安装).对于那些软件包,为了使spyder能够识别此软件包,是否仅需要另外更新Spyder中的PYTHONPATH管理器,以包含下载该软件包的目录(例如c:\ users \ bunnies)?还是应该采取其他步骤/是否有更快的方法?

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?

推荐答案

您有几种选择来使用尚未通过conda install提供的软件包:

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

1.)如果相应的软件包位于 PyPi 上,则可以按照手册.

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

2.)如果无法从头开始构建并且该软件包位于 PyPi 上,则您也可以请尝试通过 pip 安装.并非必须在Anaconda发行版中使用 pip ,而不是您的系统Python之一安装.

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.)如果要包括外部软件包或包含Python脚本的本地文件夹,则可以执行以下操作.

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

3.1.)使用sys模块并将所需的程序包/文件夹附加到路径:

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)或将模块放入站点软件包中,即目录$HOME/path/to/anaconda/lib/pythonX.X/site-packages始终位于sys.path上. (来源)

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)或将.pth文件添加到目录$HOME/path/to/anaconda/lib/pythonX.X/site-packages.可以将其命名为任何名称(仅必须以.pth结尾). .pth文件只是用换行符分隔的目录完整路径名列表,该目录将在Python启动时添加到您的路径中. (来源)

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)

祝你好运!

这篇关于Spyder-Python-安装外部软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆