Anaconda Python Conda pipbuild 失败,WindowsError 找不到文件

3 投票
2 回答
2759 浏览
提问于 2025-04-18 10:34

我最近换到了Anaconda的Python版本,正在努力熟悉它。我想安装这个和yaml相关的包,但是因为没有现成的conda配方,我尝试了以下命令:

conda pipbuild layered-yaml-attrdict-config

结果输出了以下内容(我把系统路径中不相关的部分去掉了):

C:\Anaconda>conda install layered-yaml-attrdict-config
Fetching package metadata: ..
Error: No packages found matching: layered-yaml-attrdict-config

C:\Anaconda>conda pipbuild layered-yaml-attrdict-config
Fetching package metadata: ..
Creating standard recipe for layered-yaml-attrdict-config-14.06.7
Using url https://pypi.python.org/packages/source/l/layered-yaml-attrdict-config
/layered-yaml-attrdict-config-14.06.7.tar.gz (6147) for layered-yaml-attrdict-co
nfig.
Downloading layered-yaml-attrdict-config (use --no-download to skip this step)
Unpacking layered-yaml-attrdict-config...
done
working in c:\users\bnables\appdata\local\temp\1\tmp07kkdbconda_skeleton_layered
-yaml-attrdict-config
Fetching package metadata: ...
Solving package specifications: .
The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    python-2.7.7               |                2        17.1 MB

The following packages will be linked:

    package                    |            build
    ---------------------------|-----------------
    python-2.7.7               |                2   hard-link
    pyyaml-3.11                |           py27_0   hard-link
    setuptools-3.6             |           py27_0   hard-link

Fetching packages ...
python-2.7.7-2 100% |###############################| Time: 0:00:08   2.00 MB/s
Extracting packages ...
[      COMPLETE      ] |#################################################| 100%
Linking packages ...
[      COMPLETE      ] |#################################################| 100%
Applying patch: u'c:\\users\\bnables\\appdata\\local\\temp\\1\\tmp07kkdbconda_sk
eleton_layered-yaml-attrdict-config\\pypi-distutils.patch'
Error:
    Did not find 'patch' in: C:\Anaconda\envs\_build\Scripts;C:\Anaconda\Scripts
;C:\Anaconda;C:\Anaconda\Scripts

    You can install 'patch' using apt-get, yum (Linux), Xcode (MacOSX),
    or conda, cygwin (Windows),


conda create -n _pipbuild_ --yes python pip
Fetching package metadata: ..
Solving package specifications: .
Package plan for installation in environment C:\Anaconda\envs\_pipbuild_:

The following packages will be linked:

    package                    |            build
    ---------------------------|-----------------
    pip-1.5.6                  |           py27_0   hard-link
    python-2.7.7               |                2   hard-link
    setuptools-3.6             |           py27_0   hard-link

WARNING: the process C:\Anaconda\python.exe C:\Anaconda\Scripts\conda-script.py
pipbuild layered-yaml-attrdict-config (7712) is running
WARNING: the process C:\Anaconda\Scripts\conda-pipbuild.exe layered-yaml-attrdic
t-config (4596) is running
WARNING: the process C:\Anaconda\python.exe C:\Anaconda\Scripts\conda-pipbuild-s
cript.py layered-yaml-attrdict-config (7208) is running
WARNING: Continuing installation while the above processes are running is
not recommended.  Please, close all Anaconda programs before installing or
updating things with conda.

Extracting packages ...
[      COMPLETE      ] |#################################################| 100%
Linking packages ...
[      COMPLETE      ] |#################################################| 100%
#
# To activate this environment, use:
# > activate _pipbuild_
#
C:\Anaconda\envs\_pipbuild_/bin/pip install layered-yaml-attrdict-config==14.06.
7
Traceback (most recent call last):
  File "C:\Anaconda\Scripts\conda-pipbuild-script.py", line 4, in <module>
    sys.exit(main())
  File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 76, in
 main
    args.func(args, p)
  File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 347, i
n execute
    build_package(package, version)
  File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 300, i
n build_package
    directory, dependencies = make_recipe(package, version)
  File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 244, i
n make_recipe
    depends = get_all_dependencies(package, version)
  File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 214, i
n get_all_dependencies
    ret = subprocess.Popen(cmd2.split()).wait()
  File "C:\Anaconda\lib\subprocess.py", line 710, in __init__
    errread, errwrite)
  File "C:\Anaconda\lib\subprocess.py", line 958, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

C:\Anaconda>

我不太明白发生了什么,因为我不知道它在找哪个文件,而且我对conda配方还不太了解,只知道它们应该很厉害,不会出现这种错误。

我希望通过conda来安装,这样所有的东西都可以由conda来管理,而不是有些东西由pip来管理。

深入查看main_pipbuild.py的源代码,似乎它在尝试运行C:\Anaconda\envs\_pipbuild_\bin\pip install package==version(当然是用合适的包和版本)。当我查看我的C:\Anaconda\envs_pipbuild_时,发现没有bin文件夹,所以我猜测pip没有正确安装到pipbuild环境中。之前关于没有“patch”的警告可能也是个问题……

在用conda install patch安装了patch之后,我又试了一次,结果如下:

C:\Anaconda>conda pipbuild layered-yaml-attrdict-config
Fetching package metadata: ..
Creating standard recipe for layered-yaml-attrdict-config-14.06.7
Using url https://pypi.python.org/packages/source/l/layered-yaml-attrdict-config/layered-yaml-attrdict-config-14.06.7.ta
r.gz (6147) for layered-yaml-attrdict-config.
Downloading layered-yaml-attrdict-config (use --no-download to skip this step)
Unpacking layered-yaml-attrdict-config...
done
working in c:\users\bnables\appdata\local\temp\1\tmp7cuibgconda_skeleton_layered-yaml-attrdict-config
Fetching package metadata: ...
Solving package specifications: .69 unparsed bytes left at the end of stream
file 1/1:        core.py
 hunk no.1 doesn't match source file at line 165
  expected:
  actual  :                 raise SystemExit, "error: " + str(msg)
source file is different - core.py

Applying patch: u'c:\\users\\bnables\\appdata\\local\\temp\\1\\tmp7cuibgconda_skeleton_layered-yaml-attrdict-config\\pyp
i-distutils.patch'
Traceback (most recent call last):
  File "C:\Anaconda\Scripts\conda-skeleton-script.py", line 4, in <module>
    sys.exit(main())
  File "C:\Anaconda\lib\site-packages\conda_build\main_skeleton.py", line 124, in main
    args.func(args, p)
  File "C:\Anaconda\lib\site-packages\conda_build\main_skeleton.py", line 135, in execute
    pypi.main(args, parser)
  File "C:\Anaconda\lib\site-packages\conda_build\pypi.py", line 314, in main
    run_setuppy(src_dir, tempdir, args)
  File "C:\Anaconda\lib\site-packages\conda_build\pypi.py", line 485, in run_setuppy
    apply_patch(join(stdlib_dir, 'distutils'), patch)
  File "C:\Anaconda\lib\site-packages\conda_build\source.py", line 202, in apply_patch
    check_call([patch, '-p0', '-i', path], cwd=src_dir)
  File "C:\Anaconda\lib\subprocess.py", line 540, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '[u'C:\\Anaconda\\Scripts\\patch.bat', u'-p0', u'-i', u'c:\\users\\bnables\\appda
ta\\local\\temp\\1\\tmp7cuibgconda_skeleton_layered-yaml-attrdict-config\\pypi-distutils.patch']' returned non-zero exit
 status -1

conda create -n _pipbuild_ --yes python pip
Error: prefix already exists: C:\Anaconda\envs\_pipbuild_
C:\Anaconda\envs\_pipbuild_/bin/pip install layered-yaml-attrdict-config==14.06.7
Traceback (most recent call last):
  File "C:\Anaconda\Scripts\conda-pipbuild-script.py", line 4, in <module>
    sys.exit(main())
  File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 76, in main
    args.func(args, p)
  File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 347, in execute
    build_package(package, version)
  File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 300, in build_package
    directory, dependencies = make_recipe(package, version)
  File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 244, in make_recipe
    depends = get_all_dependencies(package, version)
  File "C:\Anaconda\lib\site-packages\conda_build\main_pipbuild.py", line 214, in get_all_dependencies
    ret = subprocess.Popen(cmd2.split()).wait()
  File "C:\Anaconda\lib\subprocess.py", line 710, in __init__
    errread, errwrite)
  File "C:\Anaconda\lib\subprocess.py", line 958, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

所以它似乎在包的某个地方发现了问题,可能是在Solving package specifications: .69 unparsed bytes left at the end of stream。然后它进行了一些补丁操作,但显然失败了。接着它又尝试用pip install,结果还是找不到pipbuild环境中的bin/pip目录。

它应该在C:\Anaconda\envs\_pipbuild_\Scripts\pip.exe找pip吗?因为那个确实存在。

如果这是个bug,可以在这里报告:https://github.com/conda/conda-build/issues。我会等反馈再继续操作。

任何帮助都会很棒!

2 个回答

1

我在用“conda pipbuild package-name”来构建PyPI包时遇到过类似的问题,而且在Windows 7(64位)上一直没能成功。这里有一个我找到的有用的解决办法(如果你想在特定的conda环境中用“conda install package-name”来安装这个包),步骤如下:

  • 首先用“pip install package-name”来安装这个PyPI包。
  • 然后用“binstar upload %conda_install_path%/pkgs/package-name-ver-py27.tar.bz2”把这个包上传到你的binstar账户。
  • 最后用“conda install -c https://conda.binstar.org/user-name package-name -p %path-to-conda-env%”把包安装到指定的conda环境中。
0

在Python 3中,有一个解决这个问题的方法,具体可以查看这个链接:https://groups.google.com/a/continuum.io/d/msg/anaconda/6_reeaIjx5c/fhRjbA4AdQkJ。这个方法需要你去修改Python标准库中的distutils\cygwinccompiler.py文件。

我觉得在Python 2中也可以用类似的方法,不过可能需要稍微调整一下,因为Python 2版本的cygwinccompiler使用的是os.popen,而不是subprocess.check_output。你可以在文件中相关的位置直接用subprocess.check_output(['gcc', '-dumpmachine'], shell=True),这样应该就能解决问题了。

撰写回答