Python 3 pip 包安装在 Windows 上的 Ubuntu 上,出现 Errno 22 失败

Posted

技术标签:

【中文标题】Python 3 pip 包安装在 Windows 上的 Ubuntu 上,出现 Errno 22 失败【英文标题】:Python 3 pip packages install on Ubuntu on Windows failing with Errno 22 【发布时间】:2016-08-18 23:39:10 【问题描述】:

我知道 Windows 上的 Bash (Ubuntu) 仍处于测试阶段,但我想帮助它在整体上更好,以供我使用,并帮助开发人员缩小issue:

当我在使用 Python 3 的 pip 时尝试安装 Flask 或 Hug 等软件包时,几乎每个软件包都会出错,而 Python 2 的 pip 工作正常。请注意,我对两者都使用 virtualenv。此外,即使它使用缓存的包,当新下载它们时问题仍然存在。 这是 Python 3 的 Jinja2 示例:

(test) adam@WORKSTATION:~$ pip install Jinja2
Collecting Jinja2
  Using cached Jinja2-2.8-py2.py3-none-any.whl
Collecting MarkupSafe (from Jinja2)
  Using cached MarkupSafe-0.23.tar.gz
Building wheels for collected packages: MarkupSafe
  Running setup.py bdist_wheel for MarkupSafe ... error
  Complete output from command /home/adam/test/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-_fpuv22h/MarkupSafe/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmpff6o7wfcpip-wheel- --python-tag cp34:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.4
  creating build/lib.linux-x86_64-3.4/markupsafe
  copying markupsafe/__init__.py -> build/lib.linux-x86_64-3.4/markupsafe
  copying markupsafe/_compat.py -> build/lib.linux-x86_64-3.4/markupsafe
  copying markupsafe/_constants.py -> build/lib.linux-x86_64-3.4/markupsafe
  copying markupsafe/_native.py -> build/lib.linux-x86_64-3.4/markupsafe
  copying markupsafe/tests.py -> build/lib.linux-x86_64-3.4/markupsafe
  running egg_info
  writing MarkupSafe.egg-info/PKG-INFO
  writing dependency_links to MarkupSafe.egg-info/dependency_links.txt
  writing top-level names to MarkupSafe.egg-info/top_level.txt
  warning: manifest_maker: standard file '-c' not found

  reading manifest file 'MarkupSafe.egg-info/SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  writing manifest file 'MarkupSafe.egg-info/SOURCES.txt'
  copying markupsafe/_speedups.c -> build/lib.linux-x86_64-3.4/markupsafe
  running build_ext
  building 'markupsafe._speedups' extension
  creating build/temp.linux-x86_64-3.4
  creating build/temp.linux-x86_64-3.4/markupsafe
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.4m -I/home/adam/test/include/python3.4m -c markupsafe/_speedups.c -o build/temp.linux-x86_64-3.4/markupsafe/_speedups.o
  x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.4/markupsafe/_speedups.o -o build/lib.linux-x86_64-3.4/markupsafe/_speedups.cpython-34m.so
  installing to build/bdist.linux-x86_64/wheel
  running install
  running install_lib
  creating build/bdist.linux-x86_64
  creating build/bdist.linux-x86_64/wheel
  creating build/bdist.linux-x86_64/wheel/markupsafe
  copying build/lib.linux-x86_64-3.4/markupsafe/__init__.py -> build/bdist.linux-x86_64/wheel/markupsafe
  copying build/lib.linux-x86_64-3.4/markupsafe/_compat.py -> build/bdist.linux-x86_64/wheel/markupsafe
  copying build/lib.linux-x86_64-3.4/markupsafe/_constants.py -> build/bdist.linux-x86_64/wheel/markupsafe
  copying build/lib.linux-x86_64-3.4/markupsafe/_native.py -> build/bdist.linux-x86_64/wheel/markupsafe
  copying build/lib.linux-x86_64-3.4/markupsafe/_speedups.c -> build/bdist.linux-x86_64/wheel/markupsafe
  copying build/lib.linux-x86_64-3.4/markupsafe/_speedups.cpython-34m.so -> build/bdist.linux-x86_64/wheel/markupsafe
  copying build/lib.linux-x86_64-3.4/markupsafe/tests.py -> build/bdist.linux-x86_64/wheel/markupsafe
  running install_egg_info
  Copying MarkupSafe.egg-info to build/bdist.linux-x86_64/wheel/MarkupSafe-0.23-py3.4.egg-info
  error: [Errno 22] Invalid argument: 'MarkupSafe.egg-info/PKG-INFO'

  ----------------------------------------
  Failed building wheel for MarkupSafe
  Running setup.py clean for MarkupSafe
Failed to build MarkupSafe
Installing collected packages: MarkupSafe, Jinja2
  Running setup.py install for MarkupSafe ... error
    Complete output from command /home/adam/test/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-_fpuv22h/MarkupSafe/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-or8krd05-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/adam/test/include/site/python3.4/MarkupSafe:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.4
    creating build/lib.linux-x86_64-3.4/markupsafe
    copying markupsafe/__init__.py -> build/lib.linux-x86_64-3.4/markupsafe
    copying markupsafe/_compat.py -> build/lib.linux-x86_64-3.4/markupsafe
    copying markupsafe/_constants.py -> build/lib.linux-x86_64-3.4/markupsafe
    copying markupsafe/_native.py -> build/lib.linux-x86_64-3.4/markupsafe
    copying markupsafe/tests.py -> build/lib.linux-x86_64-3.4/markupsafe
    running egg_info
    writing top-level names to MarkupSafe.egg-info/top_level.txt
    writing MarkupSafe.egg-info/PKG-INFO
    writing dependency_links to MarkupSafe.egg-info/dependency_links.txt
    warning: manifest_maker: standard file '-c' not found

    reading manifest file 'MarkupSafe.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    writing manifest file 'MarkupSafe.egg-info/SOURCES.txt'
    copying markupsafe/_speedups.c -> build/lib.linux-x86_64-3.4/markupsafe
    running build_ext
    building 'markupsafe._speedups' extension
    creating build/temp.linux-x86_64-3.4
    creating build/temp.linux-x86_64-3.4/markupsafe
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.4m -I/home/adam/test/include/python3.4m -c markupsafe/_speedups.c -o build/temp.linux-x86_64-3.4/markupsafe/_speedups.o
    x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.4/markupsafe/_speedups.o -o build/lib.linux-x86_64-3.4/markupsafe/_speedups.cpython-34m.so
    running install_lib
    creating /home/adam/test/lib/python3.4/site-packages/markupsafe
    copying build/lib.linux-x86_64-3.4/markupsafe/__init__.py -> /home/adam/test/lib/python3.4/site-packages/markupsafe
    copying build/lib.linux-x86_64-3.4/markupsafe/_compat.py -> /home/adam/test/lib/python3.4/site-packages/markupsafe
    copying build/lib.linux-x86_64-3.4/markupsafe/_constants.py -> /home/adam/test/lib/python3.4/site-packages/markupsafe
    copying build/lib.linux-x86_64-3.4/markupsafe/_native.py -> /home/adam/test/lib/python3.4/site-packages/markupsafe
    copying build/lib.linux-x86_64-3.4/markupsafe/_speedups.c -> /home/adam/test/lib/python3.4/site-packages/markupsafe
    copying build/lib.linux-x86_64-3.4/markupsafe/_speedups.cpython-34m.so -> /home/adam/test/lib/python3.4/site-packages/markupsafe
    copying build/lib.linux-x86_64-3.4/markupsafe/tests.py -> /home/adam/test/lib/python3.4/site-packages/markupsafe
    byte-compiling /home/adam/test/lib/python3.4/site-packages/markupsafe/__init__.py to __init__.cpython-34.pyc
    byte-compiling /home/adam/test/lib/python3.4/site-packages/markupsafe/_compat.py to _compat.cpython-34.pyc
    byte-compiling /home/adam/test/lib/python3.4/site-packages/markupsafe/_constants.py to _constants.cpython-34.pyc
    byte-compiling /home/adam/test/lib/python3.4/site-packages/markupsafe/_native.py to _native.cpython-34.pyc
    byte-compiling /home/adam/test/lib/python3.4/site-packages/markupsafe/tests.py to tests.cpython-34.pyc
    running install_egg_info
    Copying MarkupSafe.egg-info to /home/adam/test/lib/python3.4/site-packages/MarkupSafe-0.23-py3.4.egg-info
    error: [Errno 22] Invalid argument: 'MarkupSafe.egg-info/PKG-INFO'

    ----------------------------------------
Command "/home/adam/test/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-_fpuv22h/MarkupSafe/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-or8krd05-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/adam/test/include/site/python3.4/MarkupSafe" failed with error code 1 in /tmp/pip-build-_fpuv22h/MarkupSafe/

这是 Python 2 的结果:

(test2) adam@WORKSTATION:~$ pip install Jinja2
Collecting Jinja2
  Using cached Jinja2-2.8-py2.py3-none-any.whl
Collecting MarkupSafe (from Jinja2)
Installing collected packages: MarkupSafe, Jinja2
Successfully installed Jinja2-2.8 MarkupSafe-0.23

我试过了:

sudo apt-get 更新 sudo apt-get 升级 sudo apt-get install python-virtualenv sudo pip install -U virtualenv sudo apt-get install python3-pip How do I use pip 3 with Python 3.4? pip install -U pip sudo apt-get install python3-setuptools sudo apt-get install python3-dev

如果没有解决方案,那是可以理解的,因为 Windows 上的 Ubuntu 仍处于测试阶段,但我想知道问题的根源是什么,以便我可以报告。

【问题讨论】:

我尝试在 Windows 上使用 Build 14332 全新安装 Ubuntu,这一次我得到了一个稍微不同的错误,仅适用于 Python 3:error: [Errno 38] Function not implemented: 'MarkupSafe.egg-info/PKG-INFO',最初编译失败后使用:unable to execute 'x86_64-linux-gnu-gcc': No such file or directory。我会尝试通过提供该工具来安装这些东西。 我安装了python3-dev并修复了unable to execute 'x86_64-linux-gnu-gcc': No such file or directory,但第二个错误仍然弹出 【参考方案1】:

使用 python3-pip 包中的 pip3 我没问题:

$ pip3 install Jinja2
Collecting Jinja2
  Downloading Jinja2-2.8-py2.py3-none-any.whl (263kB)
    100% |████████████████████████████████| 266kB 2.0MB/s
Collecting MarkupSafe (from Jinja2)
  Downloading MarkupSafe-0.23.tar.gz
Building wheels for collected packages: MarkupSafe
  Running setup.py bdist_wheel for MarkupSafe ... done
  Stored in directory: /home/lmazuel/.cache/pip/wheels/a3/fa/dc/0198eed9ad95489b8a4f45d14dd5d2aee3f8984e46862c5748
Successfully built MarkupSafe
Installing collected packages: MarkupSafe, Jinja2
Successfully installed Jinja2-2.8 MarkupSafe-0.23enter code here

使用 Windows 10 Insider Preview 14366

【讨论】:

因此,对于 Python 3,似乎使用 virtualenv 会破坏 pip【参考方案2】:

试试这个命令,也许它对你有用:

<path\to\python3\python.exe> -m pip install <package>

【讨论】:

【参考方案3】:

你好,我也有同样的问题,我尝试了很多不同的命令行,这个对我有用:

试试: conda install py-xgboost

我正在使用 Ubuntu Linux Mint。我明白了:

Collecting package metadata: done
Solving environment: done

## Package Plan ##

  environment location: /home/simplonco/anaconda3

  added / updated specs:
    - py-xgboost


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    _py-xgboost-mutex-2.0      |            cpu_0           9 KB
    ca-certificates-2019.1.23  |                0         126 KB
    certifi-2018.11.29         |           py37_0         146 KB
    conda-4.6.2                |           py37_0         1.7 MB
    libxgboost-0.80            |       he6710b0_0         3.7 MB
    mkl-2019.1                 |              144       204.6 MB
    mkl_fft-1.0.10             |   py37ha843d7b_0         169 KB
    mkl_random-1.0.2           |   py37hd81dba3_0         405 KB
    numpy-1.15.4               |   py37h7e9f1db_0          47 KB
    numpy-base-1.15.4          |   py37hde5b4d6_0         4.2 MB
    py-xgboost-0.80            |   py37he6710b0_0         1.7 MB
    scikit-learn-0.20.2        |   py37hd81dba3_0         5.7 MB
    scipy-1.2.0                |   py37h7c811a0_0        17.7 MB
    ------------------------------------------------------------
                                           Total:       240.0 MB

The following NEW packages will be INSTALLED:

  _py-xgboost-mutex  pkgs/main/linux-64::_py-xgboost-mutex-2.0-cpu_0
  libxgboost         pkgs/main/linux-64::libxgboost-0.80-he6710b0_0
  py-xgboost         pkgs/main/linux-64::py-xgboost-0.80-py37he6710b0_0

The following packages will be UPDATED:

  ca-certificates     anaconda::ca-certificates-2018.12.5-0 --> pkgs/main::ca-certificates-2019.1.23-0
  mkl                                            2019.0-118 --> 2019.1-144
  mkl_fft                              1.0.4-py37h4414c95_1 --> 1.0.10-py37ha843d7b_0
  mkl_random                           1.0.1-py37h4414c95_1 --> 1.0.2-py37hd81dba3_0
  numpy                               1.15.1-py37h1d66e8a_0 --> 1.15.4-py37h7e9f1db_0
  numpy-base                          1.15.1-py37h81de0dd_0 --> 1.15.4-py37hde5b4d6_0
  scikit-learn                        0.19.2-py37h4989274_0 --> 0.20.2-py37hd81dba3_0
  scipy                                1.1.0-py37hfa4b5c9_1 --> 1.2.0-py37h7c811a0_0

The following packages will be SUPERSEDED by a higher-priority channel:

  certifi                                          anaconda --> pkgs/main
  conda                                            anaconda --> pkgs/main
  openssl                anaconda::openssl-1.1.1-h7b6447c_0 --> pkgs/main::openssl-1.1.1a-h7b6447c_0


Proceed ([y]/n)? y


Downloading and Extracting Packages
libxgboost-0.80      | 3.7 MB    | ##################################### | 100% 
mkl_random-1.0.2     | 405 KB    | ##################################### | 100% 
certifi-2018.11.29   | 146 KB    | ##################################### | 100% 
ca-certificates-2019 | 126 KB    | ##################################### | 100% 
conda-4.6.2          | 1.7 MB    | ##################################### | 100% 
mkl-2019.1           | 204.6 MB  | ##################################### | 100% 
mkl_fft-1.0.10       | 169 KB    | ##################################### | 100% 
numpy-1.15.4         | 47 KB     | ##################################### | 100% 
scipy-1.2.0          | 17.7 MB   | ##################################### | 100% 
scikit-learn-0.20.2  | 5.7 MB    | ##################################### | 100% 
py-xgboost-0.80      | 1.7 MB    | ##################################### | 100% 
_py-xgboost-mutex-2. | 9 KB      | ##################################### | 100% 
numpy-base-1.15.4    | 4.2 MB    | ##################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

【讨论】:

以上是关于Python 3 pip 包安装在 Windows 上的 Ubuntu 上,出现 Errno 22 失败的主要内容,如果未能解决你的问题,请参考以下文章

windows下安装python包

如何在 Windows XP 上使用 pip 安装 selenium 包?

在windows下安装python包管理器pip及使用

windows python 2.6.7 安装pip

python及pip安装(windows10+ Python 3.6.5最简单的安装配置方式)

windows下面安装Python和pip终极教程