How to install Python libraries under specific environments

前端 未结 3 704
野性不改
野性不改 2021-02-06 18:00

I have two Anaconda installations on my computer. The first one is based on Python 2.7 and the other is based on Python 3.4. The default Python version is the 3.4 though. What i

相关标签:
3条回答
  • 2021-02-06 18:36

    Virtualenv seems like the obvious answer here, but I do want to suggest an alternative that we've been using to great effect lately: Fig - this is particularly effective since we use Docker in production as well, but I imagine that using Fig as a replacement for virtualenv would be quite effective regardless of your production environment.

    0 讨论(0)
  • 2021-02-06 18:40

    You don't need multiple anaconda distributions for different python versions. I would suggest keeping only one.

    conda basically lets you create environments for your different needs.

    conda create -n myenv python=3.3 creates a new environment named myenv, which works with a python3.3 interpreter.

    source activate myenv switches to the newly created environment. This basically sets the PATH such that pip, conda, python and other binaries point to the correct environment and interpreter.

    conda install pip is the first thing you may want to do. Afterwards you can use pip and conda to install the packages you need.

    After activating your environment pip install <mypackage> will point to the right version of pip so no need to worry too much.

    You may want to create environments for different python versions or different sets of packages. Of course you can easily switch between those environments using source activate <environment name>.

    For more examples and details you may want to have a look at the docs.

    0 讨论(0)
  • 2021-02-06 18:41

    Using virtualenv is your best option as @Dettorer has mentioned.

    I found this method of installing and using virtualenv the most useful. Check it out:

    Proper way to install virtualenv

    0 讨论(0)
提交回复
热议问题