当我的包是 Python 3.6 时,为啥 conda 要将所有内容降级到 Python 2.7?

Posted

技术标签:

【中文标题】当我的包是 Python 3.6 时,为啥 conda 要将所有内容降级到 Python 2.7?【英文标题】:Why does conda want to downgrade everything to Python 2.7 when my package is Python 3.6?当我的包是 Python 3.6 时,为什么 conda 要将所有内容降级到 Python 2.7? 【发布时间】:2019-07-02 15:15:57 【问题描述】:

我正在尝试将我们的应用程序升级到 Python 3,但无法让 conda 接受该包兼容。

该包似乎可以构建,并且似乎是一个 Python 3 包:

 λ conda search jbagdal --info

jbagdal 2.2.0 py36_vc15hca0d6c3_0
---------------------------------
file name   : jbagdal-2.2.0-py36_vc15hca0d6c3_0.tar.bz2
name        : jbagdal
version     : 2.2.0
build       : py36_vc15hca0d6c3_0
build number: 0
size        : 8.7 MB
subdir      : win-64
url         : file://devserver/conda_packages/win-64/jbagdal-2.2.0-py36_vc15hca0d6c3_0.tar.bz2
md5         : 600a8...770e9
timestamp   : 2019-07-02 14:42:03 UTC
dependencies:
  - geos
  - numpy
  - proj4
  - python >=3.6,<3.7.0a0
  - sqlite

但是,当我使用 Python 3.6.8 创建一个全新的 conda 环境并尝试安装该包时,我收到消息,许多依赖项将降级到 Python 2.7。

λ conda install jbagdal

The following packages will be DOWNGRADED:

  certifi                                  2019.6.16-py36_0 --> 2019.6.16-py27_0
  pip                                         19.1.1-py36_0 --> 19.1.1-py27_0
  python                                   3.6.8-h9f7ef89_7 --> 2.7.15-h2880e7c_4
  setuptools                                  41.0.1-py36_0 --> 41.0.1-py27_0
  vc                                        14.1-h0510ff6_4 --> 9-h7299396_1
  wheel                                       0.33.4-py36_0 --> 0.33.4-py27_0
  wincertstore                           0.2-py36h7fe50ca_0 --> 0.2-py27hf04cefb_0

我已经查过了,有些人建议明确指定 Python 版本,但这也不起作用。

 λ conda install jbagdal python==3.6.8
Collecting package metadata: done
Solving environment: failed

UnsatisfiableError: The following specifications were found to be in conflict:
  - jbagdal
  - python==3.6.8
Use "conda search <package> --info" to see the dependencies for each package.

我的包裹有什么问题?为什么 conda 不相信它是 Python 3 包?我需要在配方中进行哪些更改才能将其构建为 Python 3。

meta.yaml

package:
  name: jbagdal
  version: 2.2.0

source:
  git_rev: trunk
  git_url: https://srcserver/GDAL/gdal.git

build:
  features:
    - vc9     [win and py27]
    - vc10    [win and py34]
    - vc14    [win and py35]
    - vc15    [win and py>=36]

requirements:
  build:
    - swig
    - sqlite
    - python
    - numpy
    - setuptools
    -  compiler('c') 
    -  compiler('cxx') 

  run:
    - python
    - sqlite
    - numpy
    - geos
    - proj4

about:
  home: www.gdal.org
  license:
  license_file:

conda 信息的输出

     active environment : deleteme
    active env location : C:\ProgramData\Anaconda2\envs\deleteme
            shell level : 1
       user config file : C:\Users\jontwo\.condarc
 populated config files : C:\Users\jontwo\.condarc
          conda version : 4.6.8
    conda-build version : 3.0.15
         python version : 2.7.15.final.0
       base environment : C:\ProgramData\Anaconda2  (writable)
           channel URLs : file://devserver/conda_packages/win-64
                          file://devserver/conda_packages/noarch
                          https://conda.anaconda.org/scitools/win-64
                          https://conda.anaconda.org/scitools/noarch
                          https://repo.anaconda.com/pkgs/main/win-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/free/win-64
                          https://repo.anaconda.com/pkgs/free/noarch
                          https://repo.anaconda.com/pkgs/r/win-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/msys2/win-64
                          https://repo.anaconda.com/pkgs/msys2/noarch
          package cache : C:\ProgramData\Anaconda2\pkgs
                          C:\Users\jontwo\.conda\pkgs
                          C:\Users\jontwo\AppData\Local\conda\conda\pkgs
       envs directories : C:\ProgramData\Anaconda2\envs
                          C:\Users\jontwo\.conda\envs
                          C:\Users\jontwo\AppData\Local\conda\conda\envs
               platform : win-64
             user-agent : conda/4.6.8 requests/2.21.0 CPython/2.7.15 Windows/10 Windows/10.0.17134
          administrator : False
             netrc file : None
           offline mode : False

Conda 构建命令确实指定了 Python 版本:

conda build . --output-folder v:\conda_packages --python=3.6.8

而目前的conda环境是Python 3.6.8:

 λ python --version
Python 3.6.8 :: Anaconda, Inc.

【问题讨论】:

我认为你需要 --use-local 标志来安装你自己构建的包 在哪个命令上,conda install?它正在拾取本地包,只是不将其识别为 Python 3。 显然,它没有选择正确的包,否则它不会尝试降级。奇怪的是它甚至没有尝试下载适当的包,因此我认为如果你自己在conda install ... python==3.6.8 命令上构建了包,我认为你需要--use-local --use-local 只是给了我这个错误:UnavailableInvalidChannel: The channel is not accessible or is invalid. channel name: C:/ProgramData/Anaconda2/conda-bld 如果我从频道中删除 Python 2.7 包,我现在会收到 PackagesNotFoundError: The following packages are not available from current channels: - jbagdal -&gt; *[track_features=vc15] 【参考方案1】:

而答案是meta.yaml 不正确。

    - vc14    [win and py35]
    - vc15    [win and py>=36]

应该是

    - vc14    [win and py>=35]

[track_features] 错误是因为 conda 在安装之前在本地计算机上寻找 vc15。一旦我将其改回vc14,一切正常。

【讨论】:

以上是关于当我的包是 Python 3.6 时,为啥 conda 要将所有内容降级到 Python 2.7?的主要内容,如果未能解决你的问题,请参考以下文章

为啥 PDI 找不到/运行我的包存储过程?

当print()unicode字符时,python 3.5与3.6的差异?

当我使用 matplotlib.pyplot 时,python 3.6 中没有名为 PyQt4 的模块

Python 3.6 启动错误

无法在 Python 3.6 中运行 dlib 模块

为啥我不能使用这样的环境变量?