简体   繁体   中英

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). I tried to use Miniconda which is supposed to only install the bare minimum. However, I realised that, by default, Miniconda is not "mini" after all. 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. So, before moving to pyenv (for Linux and MacOS) and pyenv-win (for Windows), I would like to ask:

  • 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?
  • Is there any other tool for managing python environments that supports Linux, MacOS, and Windows?

Thank you.

Only install python and its dependencies by

conda create -n py36 python=3.6

without the anaconda package.

Detailed Explanation

conda create -n py36 python=3.6

  • conda create -n py36 , create an environment, actually an empty folder
  • python=3.6 , installed python 3.6 into this env

conda is a package manager, both python and anaconda are packages could be installed by it.

Unlike package python , anaconda is a meta package , which does not contain actual software and simply depends on other packages to be installed .

Download an anaconda package here and extract content from it. The actual packages to be installed is listed in 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 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'. There will be no additional packages installed save pip and a few other core ones.

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). To leave the environment;

(env) $ deactivate

You can have as many as you need, and define different python versions and requirements. Just remember to activate the environment before installing packages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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