Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 未经sudo许可在virtualenv中安装BeautifulSoup_Python_Virtualenv_Pip - Fatal编程技术网

Python 未经sudo许可在virtualenv中安装BeautifulSoup

Python 未经sudo许可在virtualenv中安装BeautifulSoup,python,virtualenv,pip,Python,Virtualenv,Pip,当我试图通过pip和下载的tar.gz balls在virtualenv中安装BeautifulSoup和Yolk时,我遇到了一个问题: (ola)1x-193-157-193-184:beautifulsoup4-4.1.3 ola$ python setup.py install running install running build running build_py running install_lib running install_egg_info removing '/Libr

当我试图通过pip和下载的tar.gz balls在virtualenv中安装BeautifulSoup和Yolk时,我遇到了一个问题:

(ola)1x-193-157-193-184:beautifulsoup4-4.1.3 ola$ python setup.py install
running install
running build
running build_py
running install_lib
running install_egg_info
removing '/Library/Python/2.7/site-packages/beautifulsoup4-4.1.3-py2.7.egg-info' (and everything under it)
error removing /Library/Python/2.7/site-packages/beautifulsoup4-4.1.3-py2.7.egg-info: /Library/Python/2.7/site-packages/beautifulsoup4-4.1.3-py2.7.egg-info/dependency_links.txt: Permission denied
error removing /Library/Python/2.7/site-packages/beautifulsoup4-4.1.3-py2.7.egg-info: /Library/Python/2.7/site-packages/beautifulsoup4-4.1.3-py2.7.egg-info/installed-files.txt: Permission denied
error removing /Library/Python/2.7/site-packages/beautifulsoup4-4.1.3-py2.7.egg-info: /Library/Python/2.7/site-packages/beautifulsoup4-4.1.3-py2.7.egg-info/PKG-INFO: Permission denied
error removing /Library/Python/2.7/site-packages/beautifulsoup4-4.1.3-py2.7.egg-info: /Library/Python/2.7/site-packages/beautifulsoup4-4.1.3-py2.7.egg-info/SOURCES.txt: Permission denied
error removing /Library/Python/2.7/site-packages/beautifulsoup4-4.1.3-py2.7.egg-info: /Library/Python/2.7/site-packages/beautifulsoup4-4.1.3-py2.7.egg-info/top_level.txt: Permission denied
error removing /Library/Python/2.7/site-packages/beautifulsoup4-4.1.3-py2.7.egg-info: /Library/Python/2.7/site-packages/beautifulsoup4-4.1.3-py2.7.egg-info: Permission denied
Writing /Library/Python/2.7/site-packages/beautifulsoup4-4.1.3-py2.7.egg-info
error: /Library/Python/2.7/site-packages/beautifulsoup4-4.1.3-py2.7.egg-info: Is a directory
在我尝试通过pip进行安装时,也会出现相同的问题:

(ola)1x-193-157-193-184:beautifulsoup4-4.1.3 ola$ pip install BeautifulSoup4
Downloading/unpacking BeautifulSoup4
  Downloading beautifulsoup4-4.1.3.tar.gz (131Kb): 131Kb downloaded
  Running setup.py egg_info for package BeautifulSoup4

Installing collected packages: BeautifulSoup4
  Running setup.py install for BeautifulSoup4
    error: could not delete '/Library/Python/2.7/site-packages/bs4/__init__.py': Permission denied
    Complete output from command /Users/ola/.virtualenvs/ola/bin/python -c "import setuptools;__file__='/Users/ola/.virtualenvs/ola/build/BeautifulSoup4/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /var/folders/3z/xsfq9cfx6vb18z0n84xnbdd00000gn/T/pip-JmvSkh-record/install-record.txt --install-headers /Users/ola/.virtualenvs/ola/include/site/python2.7:
    running install

running build
running build_py
creating build
creating build/lib
creating build/lib/bs4
copying bs4/__init__.py -> build/lib/bs4
copying bs4/dammit.py -> build/lib/bs4
copying bs4/element.py -> build/lib/bs4
copying bs4/testing.py -> build/lib/bs4
creating build/lib/bs4/builder
copying bs4/builder/__init__.py -> build/lib/bs4/builder
copying bs4/builder/_html5lib.py -> build/lib/bs4/builder
copying bs4/builder/_htmlparser.py -> build/lib/bs4/builder
copying bs4/builder/_lxml.py -> build/lib/bs4/builder
creating build/lib/bs4/tests
copying bs4/tests/__init__.py -> build/lib/bs4/tests
copying bs4/tests/test_builder_registry.py -> build/lib/bs4/tests
copying bs4/tests/test_docs.py -> build/lib/bs4/tests
copying bs4/tests/test_html5lib.py -> build/lib/bs4/tests
copying bs4/tests/test_htmlparser.py -> build/lib/bs4/tests
copying bs4/tests/test_lxml.py -> build/lib/bs4/tests
copying bs4/tests/test_soup.py -> build/lib/bs4/tests
copying bs4/tests/test_tree.py -> build/lib/bs4/tests
running install_lib
copying build/lib/bs4/__init__.py -> /Library/Python/2.7/site-packages/bs4
error: could not delete '/Library/Python/2.7/site-packages/bs4/__init__.py': Permission denied
----------------------------------------
Command /Users/ola/.virtualenvs/ola/bin/python -c "import setuptools;__file__='/Users/ola/.virtualenvs/ola/build/BeautifulSoup4/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /var/folders/3z/xsfq9cfx6vb18z0n84xnbdd00000gn/T/pip-JmvSkh-record/install-record.txt --install-headers /Users/ola/.virtualenvs/ola/include/site/python2.7 failed with error code 1 in /Users/ola/.virtualenvs/ola/build/BeautifulSoup4
Storing complete log in /Users/ola/.pip/pip.log
我的virtualenv安装有什么问题吗?virtualenv的优点之一不是所有文件(Python和库)都是分开包含的吗

---更新--

我试图制作一个新的virtualenv,但得到的只是一条错误消息:

Olas-MacBook-Pro:~ ola$ mkvirtualenv olaenv
New python executable in olaenv/bin/python
Installing setuptools.............................
  Complete output from command /Users/ola/.virtualenvs/olaenv/bin/python -c "#!python
\"\"\"Bootstra...sys.argv[1:])






" /Users/ola/.venvburr...ols-0.6c11-py2.7.egg:
  error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

    [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-88488.write-test'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /Library/Python/2.7/site-packages/

Perhaps your account does not have write access to this directory?  If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account.  If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.

For information on other options, you may wish to consult the
documentation at:

  http://packages.python.org/distribute/easy_install.html

Please make the appropriate changes for your system and try again.

----------------------------------------
...Installing setuptools...done.
Traceback (most recent call last):
  File "/Users/ola/.venvburrito/bin/virtualenv", line 9, in <module>
    load_entry_point('virtualenv==1.7.2', 'console_scripts', 'virtualenv')()
  File "/Users/ola/.venvburrito/lib/python/virtualenv-1.7.2-py2.7.egg/virtualenv.py", line 942, in main
    never_download=options.never_download)
  File "/Users/ola/.venvburrito/lib/python/virtualenv-1.7.2-py2.7.egg/virtualenv.py", line 1052, in create_environment
    search_dirs=search_dirs, never_download=never_download)
  File "/Users/ola/.venvburrito/lib/python/virtualenv-1.7.2-py2.7.egg/virtualenv.py", line 598, in install_setuptools
    search_dirs=search_dirs, never_download=never_download)
  File "/Users/ola/.venvburrito/lib/python/virtualenv-1.7.2-py2.7.egg/virtualenv.py", line 570, in _install_req
    cwd=cwd)
  File "/Users/ola/.venvburrito/lib/python/virtualenv-1.7.2-py2.7.egg/virtualenv.py", line 1020, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /Users/ola/.virtualenvs/olaenv/bin/python -c "#!python
\"\"\"Bootstra...sys.argv[1:])






" /Users/ola/.venvburr...ols-0.6c11-py2.7.egg failed with error code 1
Olas-MacBook-Pro:~ ola$ 
Olas MacBook Pro:~ola$mkvirtualenv olaenv
olaenv/bin/python中的新python可执行文件
安装安装工具。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
从命令/Users/ola/.virtualenvs/olaenv/bin/python-c“#!python”完成输出
\“\”\“Bootstra…sys.argv[1:])
“/Users/ola/.venvburr…ols-0.6c11-py2.7.egg:
错误:无法在安装目录中创建或删除文件
尝试在中添加或删除文件时发生以下错误
安装目录:
[Errno 13]权限被拒绝:“/Library/Python/2.7/site-packages/test-easy-install-88488.write-test”
指定的安装目录(通过--install dir、-prefix或
distutils默认设置)为:
/Library/Python/2.7/site-packages/
可能您的帐户没有对此目录的写入权限?如果
安装目录是系统拥有的目录,您可能需要登录
作为管理员或“root”帐户。如果您没有管理权限
访问此计算机时,您可能希望选择其他安装
目录,最好是PYTHONPATH环境中列出的目录
变量
有关其他选项的信息,请咨询
文件位于:
http://packages.python.org/distribute/easy_install.html
请对您的系统进行适当的更改,然后重试。
----------------------------------------
…安装安装工具…完成。
回溯(最近一次呼叫最后一次):
文件“/Users/ola/.venvburrito/bin/virtualenv”,第9行,在
加载入口点('virtualenv==1.7.2','console\u scripts','virtualenv')()
文件“/Users/ola/.venvburrito/lib/python/virtualenv-1.7.2-py2.7.egg/virtualenv.py”,主文件第942行
从不下载=选项。从不下载)
文件“/Users/ola/.venvburrito/lib/python/virtualenv-1.7.2-py2.7.egg/virtualenv.py”,第1052行,在create_环境中
搜索目录=搜索目录,从不下载=从不下载)
文件“/Users/ola/.venvburrito/lib/python/virtualenv-1.7.2-py2.7.egg/virtualenv.py”,第598行,安装工具
搜索目录=搜索目录,从不下载=从不下载)
文件“/Users/ola/.venvburrito/lib/python/virtualenv-1.7.2-py2.7.egg/virtualenv.py”,第570行,安装要求
cwd=cwd)
call_子流程中的文件“/Users/ola/.venvburrito/lib/python/virtualenv-1.7.2-py2.7.egg/virtualenv.py”,第1020行
%(指令描述,程序返回代码))
OSError:Command/Users/ola/.virtualenvs/olaenv/bin/python-c“#!python
\“\”\“Bootstra…sys.argv[1:])
“/Users/ola/.venvburr…ols-0.6c11-py2.7.egg失败,错误代码为1
Olas MacBook Pro:~ola$

有什么建议吗

如果是旧版本的virtualenv,`--no site packages`直到最近才被默认(2011-11-30的1.7版)。创建virtualenv时,请尝试显式使用该标志

mkvirtualenv olaenv --no-site-packages

简而言之:你必须用sudo安装virtualenv

我就是这样做的:

  • sudo pip卸载virtualenv(以便进行干净的安装)
  • sudopip安装virtualenv
  • 虚拟的
  • 光盘
  • 源箱/激活 此时,您可以检查是否使用了正确的pip或python:

  • 哪条蟒蛇

  • 哪一点
它们应该是虚拟的

此时,您可以通过以下方式安装bs:
-pip install beautifulsoup4

您确定
pip
python
是虚拟环境中的命令吗?查看
哪个pip
哪个python
。您好,谢谢。两者都位于virtualenvs文件夹中:(ola)1x-193-157-193-184:beautifulsoup4-4.1.3 ola$which pip/Users/ola/.virtualenvs/ola/bin/pip(ola)1x-193-157-193-184:beautifulsoup4-4.1.3 ola$which python/Users/ola/.virtualenvs/ola/bin/python(ola)1x-193-157-193-157-193-184:beautifulsoup4-4.1.3 ola$能否尝试使用新的虚拟环境<代码>$mkdir~/tmp;cd~/tmp;虚拟人;源venv/bin/激活;pip install BeautifulSoup4我尝试过,但在尝试创建新的VirtualEnvironment时收到一条错误消息v:/n能否尝试首先以root用户身份全局安装setuptools?感谢您的建议,但问题仍然存在。