python - pip install 不再适用于 virtualenv,不知何故 pip 尝试使用 root 进行安装

标签 python macos pip

------编辑重新开始---------

我遇到了 virtualenv 的问题,但我不确定是如何引起的。我遇到的问题是我无法将任何 Flask 扩展安装到我的 Flask 应用程序的 site-packages 目录中。

我之前有一个 stackoverflow 问题,我之前重写了它,但我相信我找到了根本问题,而且问题出在 virtualenv 本身。这是执行 virtualenv env 时出现的错误:

New python executable in env/bin/python
Please make sure you remove any previous custom paths from your /Users/drubio/.pydistutils.cfg file.
Installing setuptools, pip, wheel...
  Complete output from command /Users/drubio/example/env/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel:
  Ignoring indexes: https://pypi.python.org/simple
The directory '/Users/drubio/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/drubio/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting setuptools
Collecting pip
Collecting wheel
Installing collected packages: setuptools, pip, wheel
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/virtualenv-13.1.2-py2.7.egg/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/basecommand.py", line 211, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/virtualenv-13.1.2-py2.7.egg/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/commands/install.py", line 311, in run
    root=options.root_path,
  File "/Library/Python/2.7/site-packages/virtualenv-13.1.2-py2.7.egg/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/req/req_set.py", line 646, in install
    **kwargs
  File "/Library/Python/2.7/site-packages/virtualenv-13.1.2-py2.7.egg/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/req/req_install.py", line 803, in install
    self.move_wheel_files(self.source_dir, root=root)
  File "/Library/Python/2.7/site-packages/virtualenv-13.1.2-py2.7.egg/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/req/req_install.py", line 998, in move_wheel_files
    isolated=self.isolated,
  File "/Library/Python/2.7/site-packages/virtualenv-13.1.2-py2.7.egg/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/wheel.py", line 339, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/Library/Python/2.7/site-packages/virtualenv-13.1.2-py2.7.egg/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/wheel.py", line 282, in clobber
    ensure_dir(dest)  # common for the 'include' path
  File "/Library/Python/2.7/site-packages/virtualenv-13.1.2-py2.7.egg/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/utils/__init__.py", line 71, in ensure_dir
    os.makedirs(path)
  File "/Users/drubio/example/env/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/Users/drubio/example/env/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/Users/drubio/example/env/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/lib'
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
  File "/usr/local/bin/virtualenv", line 9, in <module>
    load_entry_point('virtualenv==13.1.2', 'console_scripts', 'virtualenv')()
  File "/Library/Python/2.7/site-packages/virtualenv-13.1.2-py2.7.egg/virtualenv.py", line 832, in main
    symlink=options.symlink)
  File "/Library/Python/2.7/site-packages/virtualenv-13.1.2-py2.7.egg/virtualenv.py", line 1004, in create_environment
    install_wheel(to_install, py_executable, search_dirs)
  File "/Library/Python/2.7/site-packages/virtualenv-13.1.2-py2.7.egg/virtualenv.py", line 969, in install_wheel
    'PIP_NO_INDEX': '1'
  File "/Library/Python/2.7/site-packages/virtualenv-13.1.2-py2.7.egg/virtualenv.py", line 910, in call_subprocess
    % (cmd_desc, proc.returncode))

/lib 中存在某种权限被拒绝,我不确定这意味着什么。有没有办法彻底删除virtualenv.新应用程序的 bin 目录不包含激活文件或任何内容。

此外,运行这些命令会产生以下结果:

(sudo) pip uninstall virtualenv
 zsh: /bin/pip: bad interpreter: /usr/local/opt/python/bin/python2.7: no such file or directory
 sudo: unable to execute /bin/pip: No such file or directory

但是,当我执行 which virtualenvwhich pip 时,我显然将它们放在 /usr/local/bin/virtualenv/ 下>/bin/pip.

有什么想法吗?

最佳答案

我发现问题了!问题出在这个文件 /Users/drubio/.pydistutils.cfg

对于我遇到的另一个问题(我不记得了),我需要放置这两行来解决:

[install]
prefix=''

删除这些行就可以了。

关于python - pip install 不再适用于 virtualenv,不知何故 pip 尝试使用 root 进行安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34052214/

相关文章:

python - Virtualenv OSError - setuptools pip wheel 失败,错误代码为 1

python - 如果某个类(按字符串名称)存在,如何检查 python?

cocoa - 在 AppleScript 中调整不可编写脚本的应用程序的窗口大小

python - 如何使用requirements.txt为不同的python 3版本指定不同的包版本

macos - 无法在 OS X 10.10 上为 Qt Creator 设置自定义 $PATH

xcode - 在 Cocoa 中反转触控板/鼠标事件

python - 安装 pydns 时出错

python - 你如何在 Python 中断言某事不正确?

python - 使用 Flask 和 Swagger 公开 API 文档

python - 通过跳过 Python/Pandas 中的某些值来计算数据帧平均值