[英]How do I keep track of pip-installed packages in an Anaconda (Conda) environment?
I've installed and have been using the Anaconda Python distribution, and I have started using the Anaconda (Conda) environment. 我已经安装并一直在使用Anaconda Python发行版,我已经开始使用Anaconda(Conda)环境了。 I can use the standard conda install...
command to put packages from the distribution into my environments, but to use anything outside (ie Flask-WTF, flask-sqlalchemy, and alembic) I need to use pip install
in the active environment. 我可以使用标准的conda install...
命令将包从分发包放到我的环境中,但是要使用外面的任何东西(例如Flask-WTF,flask-sqlalchemy和alembic),我需要在活动环境中使用pip install
。 However, when I look at the contents of the environment, either in the directory, or using conda list
these pip install
ed packages don't show up. 但是,当我查看环境的内容时,无论是在目录中还是使用conda list
这些pip install
ed包都不会显示出来。
Using pip freeze
and pip list
just lists every package I've ever installed. 使用pip freeze
和pip list
只列出我曾经安装的每个包。
Is there a way to keep track of what is in each of my Anaconda env
s (both pip
and conda
installed)? 有没有一种方法来跟踪什么是在我的每一个蟒蛇env
S(均由pip
和conda
安装)?
conda-env now does this automatically (if pip was installed with conda). conda-env现在自动执行此操作(如果pip与conda一起安装)。
You can see how this works by using the export tool used for migrating an environment: 您可以使用用于迁移环境的导出工具来查看其工作原理:
conda env export -n <env-name> > environment.yml
The file will list both conda packages and pip packages: 该文件将列出conda包和pip包:
name: stats
channels:
- javascript
dependencies:
- python=3.4
- bokeh=0.9.2
- numpy=1.9.*
- nodejs=0.10.*
- flask
- pip:
- Flask-Testing
If you're looking to follow through with exporting the environment, move environment.yml
to the new host machine and run: 如果您希望继续导出环境,请将environment.yml
移动到新主机并运行:
conda env create -f path/to/environment.yml
conda
will only keep track of the packages it installed. conda
只会跟踪它安装的软件包。 And pip
will give you the packages that were either installed using the pip
installer itself or they used setuptools
in their setup.py
so conda build generated the egg information. 并且pip
将为您提供使用pip
安装程序本身安装的软件包,或者他们在setup.py
使用setuptools
,因此conda build生成了egg信息。 So you have basically three options. 所以你基本上有三种选择。
You can take the union of the conda list
and pip freeze
and manage packages that were installed using conda
(that show in the conda list
) with the conda
package manager and the ones that are installed with pip
(that show in pip freeze
but not in conda list
) with pip
. 您可以使用conda list
的联合和pip freeze
并管理使用conda
(在conda list
中显示)使用conda
包管理器安装的软件包以及使用pip
安装的软件包(以pip freeze
显示但不在conda list
)与pip
。
Install in your environment only the python
, pip
and distribute
packages and manage everything with pip
. 在您的环境中仅安装python
, pip
和distribute
包并使用pip
管理所有内容。 (This is not that trivial if you're on Windows...) (如果你在Windows上,这不是那么简单......)
Build your own conda
packages, and manage everything with conda
. 构建自己的conda
包,并使用conda
管理所有内容。
I would personally recommend the third option since it's very easy to build conda
packages. 我个人会推荐第三个选项,因为它很容易构建conda
包。 There is a git repository of example recipes on the continuum's github account. 在continuum的github帐户上有一个git的示例配方存储库。 But it usually boils down to: 但它通常归结为:
conda skeleton pypi PACKAGE
conda build PACKAGE
or just: 要不就:
conda pipbuild PACKAGE
Also when you have built them once, you can upload them to https://binstar.org/ and just install from there. 此外,当您构建它们一次时,您可以将它们上传到https://binstar.org/并从那里安装。
Then you'll have everything managed using conda
. 然后你将使用conda
管理所有内容。
There is a branch of conda (new-pypi-install) that adds better integration with pip and PyPI. conda(new-pypi-install)的一个分支增加了与pip和PyPI的更好集成。 In particular conda list will also show pip installed packages and conda install will first try to find a conda package and failing that will use pip to install the package. 特别是conda list也将显示pip安装包,conda install将首先尝试查找conda包,并且失败将使用pip来安装包。
This branch is scheduled to be merged later this week so that version 2.1 of conda will have better pip-integration with conda. 这个分支计划在本周晚些时候合并,因此conda 2.1版将与conda进行更好的pip集成。
I followed @Viktor Kerkez's answer and have had mixed success. 我跟着@Viktor Kerkez的回答并取得了不同程度的成功。 I found that sometimes this recipe of 我发现有时这个配方
conda skeleton pypi PACKAGE conda skeleton pypi PACKAGE
conda build PACKAGE conda build PACKAGE
would look like everything worked but I could not successfully import PACKAGE. 看起来一切正常但我无法成功导入PACKAGE。 Recently I asked about this on the Anaconda user group and heard from @Travis Oliphant himself on the best way to use conda to build and manage packages that do not ship with Anaconda. 最近我在Anaconda用户组上询问了这个问题,并从@Travis Oliphant本人那里了解了使用conda构建和管理Anaconda未附带的软件包的最佳方法。 You can read this thread here , but I'll describe the approach below to hopefully make the answers to the OP's question more complete... 你可以在这里阅读这个主题,但我将描述下面的方法,希望能够更完整地回答OP的问题......
Example: I am going to install the excellent prettyplotlib package on Windows using conda 2.2.5. 示例:我将使用conda 2.2.5在Windows上安装优秀的prettyplotlib软件包 。
1a) conda build --build-recipe prettyplotlib
1a) conda build --build-recipe prettyplotlib
You'll see the build messages all look good until the final TEST section of the build. 在构建的最终TEST部分之前,您将看到构建消息看起来都很好。 I saw this error 我看到了这个错误
File "C:\\Anaconda\\conda-bld\\test-tmp_dir\\run_test.py", line 23 import None SyntaxError: cannot assign to None TESTS FAILED: prettyplotlib-0.1.3-py27_0 文件“C:\\ Anaconda \\ conda-bld \\ test-tmp_dir \\ run_test.py”,第23行import无SyntaxError:无法分配给无TESTS FAILED:prettyplotlib-0.1.3-py27_0
1b) Go into /conda-recipes/prettyplotlib and edit the meta.yaml file. 1b)进入/ conda-recipes / prettyplotlib并编辑meta.yaml文件。 Presently, the packages being set up like in step 1a result in yaml files that have an error in the test
section. 目前,如步骤1a中那样设置的包导致yaml文件在test
部分中有错误。 For example, here is how mine looked for prettyplotlib
例如,这是我如何寻找prettyplotlib
test: # Python imports imports:
-
- prettyplotlib
- prettyplotlib
Edit this section to remove the blank line preceded by the - and also remove the redundant prettyplotlib line. 编辑此部分以删除前面带有的空行 - 并删除冗余的prettyplotlib行。 At the time of this writing I have found that I need to edit most meta.yaml files like this for external packages I am installing with conda, meaning that there is a blank import line causing the error along with a redundant import of the given package. 在撰写本文时,我发现我需要编辑这样的大多数meta.yaml文件,用于我用conda安装的外部包,这意味着有一个空白的导入行导致错误以及给定包的冗余导入。
1c) Rerun the command from 1a, which should complete with out error this time. 1c)从1a重新运行命令,这次应完成输出错误。 At the end of the build you'll be asked if you want to upload the build to binstar . 在构建结束时,系统会询问您是否要将构建上传到binstar 。 I entered No and then saw this message: 我输入了No然后看到了这条消息:
If you want to upload this package to binstar.org later, type: 如果您想稍后将此包上传到binstar.org,请键入:
$ binstar upload C:\\Anaconda\\conda-bld\\win-64\\prettyplotlib-0.1.3-py27_0.tar.bz2 $ binstar上传C:\\ Anaconda \\ conda-bld \\ win-64 \\ prettyplotlib-0.1.3-py27_0.tar.bz2
That tar.bz2 file is the build that you now need to actually install. tar.bz2文件是您现在需要实际安装的版本。
2) conda install C:\\Anaconda\\conda-bld\\win-64\\prettyplotlib-0.1.3-py27_0.tar.bz2
2) conda install C:\\Anaconda\\conda-bld\\win-64\\prettyplotlib-0.1.3-py27_0.tar.bz2
Following these steps I have successfully used conda to install a number of packages that do not come with Anaconda. 按照这些步骤,我已成功使用conda来安装许多Anaconda未附带的软件包。 Previously, I had installed some of these using pip, so I did pip uninstall PACKAGE
prior to installing PACKAGE with conda. 以前,我已经使用pip安装了其中一些,所以我在使用pip uninstall PACKAGE
之前做了pip uninstall PACKAGE
。 Using conda, I can now manage (almost) all of my packages with a single approach rather than having a mix of stuff installed with conda, pip, easy_install, and python setup.py install. 使用conda,我现在可以使用单一方法管理(几乎)所有软件包,而不是使用conda,pip,easy_install和python setup.py install安装的东西。
For context, I think this recent blog post by @Travis Oliphant will be helpful for people like me who do not appreciate everything that goes into robust Python packaging but certainly appreciate when stuff "just works". 对于上下文,我认为@Travis Oliphant 最近的博客文章将对像我这样的人有所帮助,他们不喜欢强大的Python包装中的所有内容,但当“东西正常”时肯定会欣赏。 conda seems like a great way forward... 康达似乎是一个很好的前进方式......
This is why I wrote Picky: http://picky.readthedocs.io/ 这就是我写Picky的原因: http : //picky.readthedocs.io/
It's a python package that tracks packages installed with either pip or conda in either virtualenvs and conda envs. 它是一个python包,用于跟踪virtualenvs和conda envs中使用pip或conda安装的软件包。
I think what's missing here is that when you do: 我认为这里缺少的是你做的时候:
>pip install .
to install a local package with a setup.py, it installs a package that is visible to all the conda envs that use the same version of python. 要使用setup.py安装本地软件包,它会安装一个对所有使用相同版本的python的conda env都可见的软件包。 Note I am using the conda version of pip! 注意我正在使用pda的conda版本!
eg, if I'm using python2.7 it puts the local package here: 例如,如果我使用python2.7,它将本地包放在这里:
/usr/local/anaconda/lib/python2.7/site-packages /usr/local/anaconda/lib/python2.7/site-packages
If I then later create a new conda env with python=2.7 (= the default): 如果我稍后用python = 2.7(=默认值)创建一个新的conda env:
>conda create --name new
>source activate new
And then do: 然后做:
(new)>conda list // empty - conda is not aware of any packages yet
However, if I do: 但是,如果我这样做:
(new)>pip list // the local package installed above is present
So in this case, conda does not know about the pip package, but the package is available to python. 所以在这种情况下,conda不知道pip包,但是包可用于python。
However, If I instead install the local package (again using pip) after I've created (and activated) the new conda env, now conda sees it: 但是,如果我在创建(并激活)新的conda env 之后安装本地软件包(再次使用pip), 现在 conda会看到它:
(new)>conda list // sees that the package is there and was installed by pip
So I think the interaction between conda and pip has some issues - ie, using pip to install a local package from within one conda env makes that package available (but not seen via conda list) to all other conda envs of the same python version. 所以我认为conda和pip之间的交互存在一些问题 - 即,使用pip从一个conda env中安装本地包使得该包可用(但不能通过conda列表看到)到同一个python版本的所有其他conda envs。
conda env export
lists all conda and pip packages in an environment. conda env export
列出环境中的所有conda和pip包。 conda-env
must be installed in the conda root ( conda install -c conda conda-env
). conda-env
必须安装在conda根目录中( conda install -c conda conda-env
)。
To write an environment.yml
file describing the current environment: 编写描述当前环境的environment.yml
文件:
conda env export > environment.yml
References: 参考文献:
I usually prefix the 'bin/pip' folder for the specific environment you want to install the package before the 'pip' command. 在'pip'命令之前,我通常在'bin / pip'文件夹前面添加要安装软件包的特定环境。 For instance, if you would like to install pymc3 in the environment py34, you should use this command: 例如,如果要在环境py34中安装pymc3,则应使用以下命令:
~/anaconda/envs/py34/bin/pip install git+https://github.com/pymc-devs/pymc3
You basically just need to find the right path to your environment 'bin/pip' folder and put it before the install command. 您基本上只需要找到环境'bin / pip'文件夹的正确路径,并将其放在install命令之前。
You can start by installing the below given command in the conda environment: 您可以首先在conda环境中安装以下给定的命令:
conda install pip
Followed by installing all pip packages you need in the environment. 然后在环境中安装所需的所有pip包。
After installing all the conda and pip packages to export the environment use: 安装所有conda和pip包以导出环境后使用:
conda env export -n <env-name> > environment.yml
This will create the required file in the folder 这将在文件夹中创建所需的文件
My which pip
shows the following path: 我的which pip
显示以下路径:
$ which pip
/home/kmario23/anaconda3/bin/pip
So, whatever package I install using pip install <package-name>
will have to be reflected in the list of packages when the list is exported using: 因此,使用pip install <package-name>
任何软件包都必须在使用以下命令导出列表时反映在软件包列表中:
$ conda list --export > conda_list.txt
But, I don't. 但是,我没有。 So, instead I used the following command as suggested by several others: 所以,我使用了以下命令,如其他几个人所建议的那样:
# get environment name by
$ conda-env list
# get list of all installed packages by (conda, pip, etc.,)
$ conda-env export -n <my-environment-name> > all_packages.yml
# if you haven't created any specific env, then just use 'root'
Now, I can see all the packages in my all-packages.yml
file. 现在,我可以在all-packages.yml
文件中看到所有all-packages.yml
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.