-1

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.

AstrOne
  • 3,569
  • 7
  • 32
  • 54

2 Answers2

2

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
Simba
  • 23,537
  • 7
  • 64
  • 76
  • Silly me. I thought the last argument was the name of the repository to fetch the package from! :) Thanks Simba! – AstrOne Sep 18 '19 at 05:25
  • @AstrOne In fact, `anaconda` is a meta package but a normal package like `python`. I've updated my answer about this. – Simba Sep 18 '19 at 05:38
1

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.

elembie
  • 600
  • 2
  • 8
  • Thanks for the response my friend! Is `virtualenv` also supposed to install different python versions? Can you show me how to install 3.5, 3.6, and 3.7 using virtualenv? To my understanding, the command you provided assumes that the requested python interpreter must already be installed. Thanks! – AstrOne Sep 18 '19 at 03:53
  • You can download any version of python you need from [the download site](https://www.python.org/downloads/). I **would be careful using the installers** if you already have a python version installed at a user level - it might break things that use it already. Download the zipped versions and then will have to either point to the python path, build from the source or use [pyenv](https://realpython.com/intro-to-pyenv/) to manage them. Can't talk you through step by step here but there's lots of resources out there! – elembie Sep 18 '19 at 04:21
  • Essentially you just need to have the correct python executable (e.g. 3.5/3.7 etc) available on your machine, then point virtualenv towards it. As I mentioned above, pyenv can also help you manage this (although I've not used it myself). – elembie Sep 18 '19 at 04:22
  • I guess this is what I am trying to avoid. That is why I was looking into Miniconda and pyenv. I just want a single tool that can do all this stuff and at the same time support Linux, MacOS, and Windows. I guess the only option is the bloated Miniconda :/ – AstrOne Sep 18 '19 at 04:27
  • And also may want to mention using `virtualenvwrapper` – arntg Feb 05 '22 at 23:36