windows: pip 卸载失败,访问被拒绝

windows: pip uninstallation fails with access denied

我是 Python 的新手,正在尝试使用 Jenkinsfile 自动化 python 构建,为此我正在创建虚拟环境,然后安装 pybuilder。但是 pybuilder 安装因权限问题而失败,

命令:

    virtualenv venv
    source venv/Scripts/activate        
    pip install pybuilder       
    pyb

输出:

+ pip install virtualenv
Collecting virtualenv
  Downloading https://.../repository/pypi-public/packages/b6/30/96a02b2287098b23b875bc8c2f58071c35d2efe84f747b64d523721dc2b5/virtualenv-16.0.0-py2.py3-none-any.whl (1.9MB)
Installing collected packages: virtualenv
Successfully installed virtualenv-16.0.0
You are using pip version 9.0.1, however version 18.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
+ virtualenv --version
16.0.0
+ virtualenv venv
Using base prefix 'f:\app\python'
New python executable in ...\venv\Scripts\python.exe
Installing setuptools, pip, wheel...done.
+ source venv/Scripts/activate
++ deactivate nondestructive
++ unset -f pydoc
++ '[' -z '' ']'
++ '[' -z '' ']'
++ '[' -n /usr/bin/sh ']'
++ hash -r
++ '[' -z '' ']'
++ unset VIRTUAL_ENV
++ '[' '!' nondestructive = nondestructive ']'
+++ '[' msys == cygwin ']'
+++ echo .../py/venv
++ VIRTUAL_ENV=.../venv
++ export VIRTUAL_ENV
++ _OLD_VIRTUAL_PATH='...'
++ PATH='...'
++ export PATH
++ '[' -z '' ']'
++ '[' -z '' ']'
++ _OLD_VIRTUAL_PS1=
++ '[' x '!=' x ']'
+++ basename ...
++ PS1='(venv) '
++ export PS1
++ alias pydoc
++ '[' -n /usr/bin/sh ']'
++ hash -r
+ pip --version
pip 18.1 from ...\venv\lib\site-packages\pip (python 3.5)

+ pip install pybuilder
Looking in indexes: https://.../repository/pypi-public/simple
Collecting pybuilder
  Downloading https://.../repository/pypi-public/packages/c0/23/57ef070a20ca2ff7852371056a57fef2d95d74b1b99e01bb7200dc7e80e5/pybuilder-0.11.17-py3-none-any.whl (114kB)
Collecting pip<11dev,>=7.1 (from pybuilder)
  Downloading https://.../repository/pypi-public/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl (1.3MB)
Requirement already satisfied: tailer in g:\applications\jenkins\slaves\stcjs3\workspace\py\venv\lib\site-packages (from pybuilder) (0.4.1)
Requirement already satisfied: tblib in g:\applications\jenkins\slaves\stcjs3\workspace\py\venv\lib\site-packages (from pybuilder) (1.3.2)
Collecting setuptools~=39.0.0 (from pybuilder)
  Downloading https://.../repository/pypi-public/packages/20/d7/04a0b689d3035143e2ff288f4b9ee4bf6ed80585cc121c90bfd85a1a8c2e/setuptools-39.0.1-py2.py3-none-any.whl (569kB)
Requirement already satisfied: wheel~=0.31 in ...\venv\lib\site-packages (from pybuilder) (0.32.1)
Installing collected packages: pip, setuptools, pybuilder
  Found existing installation: pip 18.1
    Uninstalling pip-18.1:
Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: '...venv\scripts\pip.exe'
Consider using the `--user` option or check the permissions.

这是我看到的 pybuilder 下载它自己的 pip 模块并尝试安装它。由于 pip 已经安装,它正在尝试卸载当前版本并尝试安装下载的版本,但失败了。

它失败了,因为 pybuilder install 本身 运行 pip 命令和 pip 尝试杀死自己。

当我搜索这个时,我知道它在 windows 环境中是不可能的:https://github.com/pypa/pip/issues/3804

Python 版本为 3.5.4.

有人之前遇到过同样的问题吗?

尝试使用 python 可执行文件(运行 这来自管理员命令行)。

python -m pip install pybuilder

有关 的更多信息。