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

早过忘川 提交于 2019-12-13 03:59:01

问题


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.


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/57983778/looking-for-a-cross-platform-linux-macos-windows-tool-for-managing-python-en

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!