简体   繁体   English

寻找用于管理Python环境的跨平台(Linux,MacOS,Windows)工具

[英]Looking for a cross-platform (Linux, MacOS, Windows) tool for managing Python environments

I was investigating the use of Anaconda environments for CI/CD (since, to my knowledge, it is the only platform that supports Linux, MacOS, and Windows). 我正在研究将Anaconda环境用于CI / CD(据我所知,这是唯一支持Linux,MacOS和Windows的平台)。 I tried to use Miniconda which is supposed to only install the bare minimum. 我试图使用Miniconda,它应该只安装最低限度的组件。 However, I realised that, by default, Miniconda is not "mini" after all. 但是,我意识到,默认情况下,Miniconda毕竟不是“ mini”。 For example, if I attempt to create a new Python environment ( conda create -n py36 python=3.6 anaconda ), it will install a bunch of not needed stuff like JupyterLab and others. 例如,如果我尝试创建一个新的Python环境( conda create -n py36 python=3.6 anaconda ),它将安装一堆不需要的东西,例如JupyterLab等。 So, before moving to pyenv (for Linux and MacOS) and pyenv-win (for Windows), I would like to ask: 因此,在转向pyenv (对于Linux和MacOS)和pyenv-win (对于Windows)之前,我想问一下:

  • Is there a way to setup different python environments with anaconda/miniconda without having to install a bunch of extra packages every time I create a new environment? 有没有一种方法可以用anaconda / miniconda设置不同的python环境,而不必在每次创建新环境时都安装一堆额外的软件包?
  • Is there any other tool for managing python environments that supports Linux, MacOS, and Windows? 还有其他用于管理支持Linux,MacOS和Windows的python环境的工具吗?

Thank you. 谢谢。

Only install python and its dependencies by 仅通过安装python及其依赖项

conda create -n py36 python=3.6

without the anaconda package. 没有anaconda包。

Detailed Explanation 详细说明

conda create -n py36 python=3.6

  • conda create -n py36 , create an environment, actually an empty folder conda create -n py36 ,创建一个环境,实际上是一个空文件夹
  • python=3.6 , installed python 3.6 into this env python=3.6 ,在此环境中安装了python 3.6

conda is a package manager, both python and anaconda are packages could be installed by it. conda是一个软件包管理器, pythonanaconda都是可以由它安装的软件包。

Unlike package python , anaconda is a meta package , which does not contain actual software and simply depends on other packages to be installed . 与软件包python不同, anaconda是一个meta软件包 ,它不包含实际的软件,仅依赖于要安装的其他软件包

Download an anaconda package here and extract content from it. 在此处下载anaconda软件包并从中提取内容。 The actual packages to be installed is listed in info/recipe/meta.yaml . 实际要安装的软件包在info/recipe/meta.yaml

package:
    name: anaconda
    version: '2019.07'
build:
    ignore_run_exports:
        - '*'
    number: '0'
    pin_depends: strict
    string: py37_0
requirements:
    build:
        - python 3.7.3 h8c8aaf0_1
    is_meta_pkg:
        - true
    run:
        - alabaster 0.7.12 py37_0
        - anaconda-client 1.7.2 py37_0
        - anaconda-project 0.8.3 py_0
        # ...
        # about 260 packages in total

You want virtualenv: https://virtualenv.pypa.io/en/latest/ 您需要virtualenv: https ://virtualenv.pypa.io/en/latest/

$ virtualenv env --python "[path to python version]"

This will create an environment from the python base you chose in the previous command, in a folder called 'env'. 这将根据您在上一个命令中选择的python库的“ env”文件夹中创建一个环境。 There will be no additional packages installed save pip and a few other core ones. 除pip和其他一些核心软件包外,将不会安装其他软件包。

You then need to 'activate' the environment - this changes based on operating system. 然后,您需要“激活”环境-这取决于操作系统。 For windows; 对于窗户;

$ env\\Scripts\\activate

You will then have the command prompt; 然后,您将看到命令提示符;

(env) $

Showing it's activated. 显示它已激活。 You can then use pip install as normal to install whatever requirements you need into that environment (they will live inside the env folder). 然后,您可以照常使用pip install将所需的任何需求安装到该环境中(它们将位于env文件夹中)。 To leave the environment; 离开环境;离开环境

(env) $ deactivate

You can have as many as you need, and define different python versions and requirements. 您可以根据需要设置任意数量,并定义不同的python版本和要求。 Just remember to activate the environment before installing packages. 只要记住在安装软件包之前activate环境即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM