Spyder - python - 安装外部包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33539214/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 13:31:50  来源:igfitidea点击:

Spyder - python - install external packages

pythonpackagesanacondaspyder

提问by user1885116

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?

我刚刚开始使用 python(在 Windows 中,64 位) - 我有一个关于如何在 anaconda / spyder 环境中安装外部包的基本问题。我知道对于大多数软件包,可以简单地使用“conda install bunnies”。但是,某些软件包不在 anaconda 存储库中,并且可能已从外部安装(例如从 github)。对于那些包,为了让 spyder 能够识别这个包——是否只需要更新 Spyder 中的 PYTHONPATH 管理器以包含下载这个包的目录(例如 c:\users\bunnies)?或者应该采取额外的步骤/是否有更快的方法?

回答by Cord Kaldemeyer

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

您有几个选项可以通过以下方式使用(尚未)可用的软件包conda install

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

1.) 如果相应的包在PyPi 上,您可以按照手册中的说明构建它。

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

2.) 如果从头开始构建不起作用并且包在PyPi 上,您也可以尝试通过pip进行安装。并不是说您必须在 Anaconda 发行版中使用pip而不是您的系统 Python 安装之一。

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

3.) 如果要包含包含 Python 脚本的外部包或本地文件夹,您可以执行以下操作。

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

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

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-packageswhich is always on sys.path. (Source)

3.2) 或者把模块放到site-packages中,即$HOME/path/to/anaconda/lib/pythonX.X/site-packages一直在的目录下sys.path。(来源

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

3.3) 或者.pth在目录中添加一个文件$HOME/path/to/anaconda/lib/pythonX.X/site-packages。这可以命名为任何名称(它必须以 结尾.pth)。一个.pth文件只是一个换行分隔的目录将被添加到在Python启动您的路径的完整路径名的列表。(来源

Good luck!

祝你好运!