如何使用conda升级到Python 3.6?

问题:如何使用conda升级到Python 3.6?

我是Conda软件包管理的新手,我想获取最新版本的Python以在代码中使用f字符串。目前,我的版本是(python -V):

Python 3.5.2 :: Anaconda 4.2.0 (x86_64)

如何升级到Python 3.6?

I’m new to Conda package management and I want to get the latest version of Python to use f-strings in my code. Currently my version is (python -V):

Python 3.5.2 :: Anaconda 4.2.0 (x86_64)

How would I upgrade to Python 3.6?


回答 0

Anaconda尚未将python内部更新为3.6。

a)方法1

  1. 如果要更新,请输入 conda update python
  2. 更新anaconda类型 conda update anaconda
  3. 如果要在主要的python版本(例如3.5到3.6)之间升级,则必须

    conda install python=$pythonversion$

b)方法2-创建一个新环境(更好的方法)

conda create --name py36 python=3.6

c)要获取绝对最新的python(在撰写本文时为3.6.5)

conda create --name py365 python=3.6.5 --channel conda-forge

您可以从这里看到所有这些

另外,请参阅此以进行强制升级

编辑:Anaconda现在在这里具有Python 3.6版本

Anaconda has not updated python internally to 3.6.

a) Method 1

  1. If you wanted to update you will type conda update python
  2. To update anaconda type conda update anaconda
  3. If you want to upgrade between major python version like 3.5 to 3.6, you’ll have to do

    conda install python=$pythonversion$
    

b) Method 2 – Create a new environment (Better Method)

conda create --name py36 python=3.6

c) To get the absolute latest python(3.6.5 at time of writing)

conda create --name py365 python=3.6.5 --channel conda-forge

You can see all this from here

Also, refer to this for force upgrading

EDIT: Anaconda now has a Python 3.6 version here


回答 1

创建一个新环境将安装python 3.6:

$ conda create --name 3point6 python=3.6
Fetching package metadata .......
Solving package specifications: ..........

Package plan for installation in environment /Users/dstansby/miniconda3/envs/3point6:

The following NEW packages will be INSTALLED:

    openssl:    1.0.2j-0     
    pip:        9.0.1-py36_1 
    python:     3.6.0-0      
    readline:   6.2-2        
    setuptools: 27.2.0-py36_0
    sqlite:     3.13.0-0     
    tk:         8.5.18-0     
    wheel:      0.29.0-py36_0
    xz:         5.2.2-1      
    zlib:       1.2.8-3 

Creating a new environment will install python 3.6:

$ conda create --name 3point6 python=3.6
Fetching package metadata .......
Solving package specifications: ..........

Package plan for installation in environment /Users/dstansby/miniconda3/envs/3point6:

The following NEW packages will be INSTALLED:

    openssl:    1.0.2j-0     
    pip:        9.0.1-py36_1 
    python:     3.6.0-0      
    readline:   6.2-2        
    setuptools: 27.2.0-py36_0
    sqlite:     3.13.0-0     
    tk:         8.5.18-0     
    wheel:      0.29.0-py36_0
    xz:         5.2.2-1      
    zlib:       1.2.8-3 

回答 2

我在此页面上找到了有关将Anaconda升级到Python的主要更新版本(从Anaconda 4.0+)的详细说明。第一,

conda update conda
conda remove argcomplete conda-manager

我还需要conda remove一些不在官方清单中的软件包:

  • backports_abc
  • 美丽的汤
  • 火焰芯

根据系统上安装的软件包,您可能会遇到其他UnsatisfiableError错误-只需将这些软件包添加到删除列表中即可。接下来,安装Python版本,

conda install python==3.6

这需要一段时间,之后显示消息给conda install anaconda-client,所以我做了

conda install anaconda-client

说它已经在那里。最后,按照指示进行

conda update anaconda

我是在Windows 10命令提示符下执行此操作的,但在Mac OS X中应该与此类似。

I found this page with detailed instructions to upgrade Anaconda to a major newer version of Python (from Anaconda 4.0+). First,

conda update conda
conda remove argcomplete conda-manager

I also had to conda remove some packages not on the official list:

  • backports_abc
  • beautiful-soup
  • blaze-core

Depending on packages installed on your system, you may get additional UnsatisfiableError errors – simply add those packages to the remove list. Next, install the version of Python,

conda install python==3.6

which takes a while, after which a message indicated to conda install anaconda-client, so I did

conda install anaconda-client

which said it’s already there. Finally, following the directions,

conda update anaconda

I did this in the Windows 10 command prompt, but things should be similar in Mac OS X.


回答 3

过去,我发现尝试就地升级非常困难。

注意:我对Anaconda的用例是作为一个多合一的Python环境。我不用理会单独的虚拟环境。如果您conda用于创建环境,这可能具有破坏性,因为conda创建的Anaconda/envs目录中包含硬链接的环境。

因此,如果您使用环境,则可能首先要导出环境。激活环境后,请执行以下操作:

conda env export > environment.yml

备份环境后(如有必要),您可以删除旧的Anaconda(卸载Anaconda非常简单):

$ rm -rf ~/anaconda3/

并通过下载新的Anaconda(例如64位Linux)来替换它:

$ cd ~/Downloads
$ wget https://repo.continuum.io/archive/Anaconda3-4.3.0-Linux-x86_64.sh 

有关最新信息请参见此处),

然后执行它:

$ bash Anaconda3-4.3.0-Linux-x86_64.sh 

In the past, I have found it quite difficult to try to upgrade in-place.

Note: my use-case for Anaconda is as an all-in-one Python environment. I don’t bother with separate virtual environments. If you’re using conda to create environments, this may be destructive because conda creates environments with hard-links inside your Anaconda/envs directory.

So if you use environments, you may first want to export your environments. After activating your environment, do something like:

conda env export > environment.yml

After backing up your environments (if necessary), you may remove your old Anaconda (it’s very simple to uninstall Anaconda):

$ rm -rf ~/anaconda3/

and replace it by downloading the new Anaconda, e.g. Linux, 64 bit:

$ cd ~/Downloads
$ wget https://repo.continuum.io/archive/Anaconda3-4.3.0-Linux-x86_64.sh 

(see here for a more recent one),

and then executing it:

$ bash Anaconda3-4.3.0-Linux-x86_64.sh 

回答 4

我正在使用Mac OS Mojave

这四个步骤对我有用。

  1. conda update conda
  2. conda install python=3.6
  3. conda install anaconda-client
  4. conda update anaconda

I’m using a Mac OS Mojave

These 4 steps worked for me.

  1. conda update conda
  2. conda install python=3.6
  3. conda install anaconda-client
  4. conda update anaconda

回答 5

我发现的最佳方法:

source activate old_env
conda env export > old_env.yml

然后使用以下方法进行处理:

with open('old_env.yml', 'r') as fin, open('new_env.yml', 'w') as fout:
    for line in fin:
        if 'py35' in line:  # replace by the version you want to supersede
            line = line[:line.rfind('=')] + '\n'
        fout.write(line)

然后手动编辑第一行(name: ...)和最后一行(prefix: ...)以反映您的新环境名称并运行:

conda env create -f new_env.yml

您可能需要手动删除或更改一些软件包的版本标记,而对于这些软件包,固定的版本old_env与新python版本不兼容或丢失。

我希望有一个内置的,更简单的方法…

Best method I found:

source activate old_env
conda env export > old_env.yml

Then process it with something like this:

with open('old_env.yml', 'r') as fin, open('new_env.yml', 'w') as fout:
    for line in fin:
        if 'py35' in line:  # replace by the version you want to supersede
            line = line[:line.rfind('=')] + '\n'
        fout.write(line)

then edit manually the first (name: ...) and last line (prefix: ...) to reflect your new environment name and run:

conda env create -f new_env.yml

you might need to remove or change manually the version pin of a few packages for which which the pinned version from old_env is found incompatible or missing for the new python version.

I wish there was a built-in, easier way…