virtualenv在错误的地方寻找easy_install&其他文件

时间:2015-12-23 03:57:51

标签: python python-2.7 pip virtualenv easy-install

不知何故,我把我的python 2.7安装搞砸了,所以我尝试用“brew install python”重新安装。现在,当我尝试创建一个新的virtualenv时,它会抛出一个关于找不到/ bin / easy_install的错误。 easy_install实际上在/ usr / local / bin / easy_install中。如果我将它符号链接到/ bin,virtualenv就会失败/ bin / pip等等 - 它正在寻找的每个文件实际上都在/ usr / local / bin中没有/ bin

我如何永久地将virtualenv放在正确的位置:/ usr / local / bin?

$ virtualenv env
New python executable in /Users/myusername/code/lambda/env/bin/python2.7
Also creating executable in /Users/myusername/code/lambda/env/bin/python
Installing setuptools, pip, wheel...
  Complete output from command /Users/myusername/c...da/env/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel:
  Ignoring indexes: https://pypi.python.org/simple
Collecting setuptools
Collecting pip
Collecting wheel
Installing collected packages: setuptools, pip, wheel
Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/basecommand.py", line 211, in main
    status = self.run(options, args)
  File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/commands/install.py", line 311, in run
    root=options.root_path,
  File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/req/req_set.py", line 646, in install
    **kwargs
  File "/usr/local/lib/python2.7/site-packages/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 "/usr/local/lib/python2.7/site-packages/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 "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/wheel.py", line 465, in move_wheel_files
    generated.extend(maker.make(spec))
  File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/_vendor/distlib/scripts.py", line 353, in make
    self._make_script(entry, filenames, options=options)
  File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/_vendor/distlib/scripts.py", line 257, in _make_script
    self._write_script(scriptnames, shebang, script, filenames, ext)
  File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/_vendor/distlib/scripts.py", line 231, in _write_script
    self._fileop.write_binary_file(outname, script_bytes)
  File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/_vendor/distlib/util.py", line 388, in write_binary_file
    with open(path, 'wb') as f:
IOError: [Errno 13] Permission denied: '/bin/easy_install'
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
  File "/usr/local/bin/virtualenv", line 9, in <module>
    load_entry_point('virtualenv==13.2.0.dev0', 'console_scripts', 'virtualenv')()
  File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 699, in main
    symlink=options.symlink)
  File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 872, in create_environment
    install_wheel(to_install, py_executable, search_dirs)
  File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 837, in install_wheel
    'PIP_USER': '0'
  File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 777, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /Users/myusername/c...da/env/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel failed with error code 2

在输出的大约一半时,您可以看到virtualenv正在寻找/ bin / easy_install

$ ls -al /bin/easy_install
ls: /bin/easy_install: No such file or directory

$ ls -al /usr/local/bin/easy_install
lrwxr-xr-x  1 myusername  admin  40 Dec 22 14:21 /usr/local/bin/easy_install -> ../Cellar/python/2.7.11/bin/easy_install

但它应该在/ usr / local / bin中查找,因为这是我现在唯一的easy_install并且有效:

$ which easy_install
/usr/local/bin/easy_install

$ easy_install
install_dir /usr/local/lib/python2.7/site-packages/
error: No urls, filenames, or requirements specified (see --help)

我已经尝试 pip卸载virtualenv 然后 pip install virtualenv 但这没有用 - 同样的问题。

任何人都知道如何解决这个问题?

谢谢!

====================

编辑:解决了! 尝试使用/usr/local/bin/virtualenv-2.7并按预期工作。我移动/ usr / local / bin / virtualenv然后symlinked /usr/local/bin/virtualenv-2.7回到/ usr / local / bin / virtualenv ---现在看起来世界上都很好。

2 个答案:

答案 0 :(得分:1)

解决!尝试使用/usr/local/bin/virtualenv-2.7并按预期工作。我移动/ usr / local / bin / virtualenv然后symlinked /usr/local/bin/virtualenv-2.7回到/ usr / local / bin / virtualenv ---现在看起来世界上都很好。

答案 1 :(得分:0)

我编译了自己的Python 3,然后安装了virtualenvwrapper。但是在我从编译我自己的Python切换到使用deadsnakes PPA后,我遇到了上述问题中描述的问题。

似乎virtualenv脚本的#!部分正在发生一些事情。

我得到的错误如下:

nb@ubuntu-0xA520322HC30H:~/proj/redis-py$ mkvirtualenv --python='/usr/bin/python3' redispytest
bash: /home/nb/.local/bin/virtualenv: /usr/local/bin/python3.6: bad interpreter: No such file or directory

我的系统Python设置包含以下符号链接和Python位置:

nb@ubuntu-0xA520322HC30H:~/proj/redis-py$ ls -la /usr/bin/python3
lrwxrwxrwx 1 root root 9 Feb  8 11:43 /usr/bin/python3 -> python3.5
nb@ubuntu-0xA520322HC30H:~/proj/redis-py$ ls -la /usr/bin/python3.5
-rwxr-xr-x 2 root root 4464400 Nov 28 08:53 /usr/bin/python3.5
nb@ubuntu-0xA520322HC30H:~/proj/redis-py$ which python3.5
/usr/bin/python3.5
nb@ubuntu-0xA520322HC30H:~/proj/redis-py$ ls -la /usr/bin/python3.5
-rwxr-xr-x 2 root root 4464400 Nov 28 08:53 /usr/bin/python3.5
nb@ubuntu-0xA520322HC30H:~/proj/redis-py$ ls -la /usr/bin/python3.6
-rwxr-xr-x 2 root root 4695328 Jan 28 10:49 /usr/bin/python3.6
nb@ubuntu-0xA520322HC30H:~/proj/redis-py$ which virtualenv
/home/nb/.local/bin//virtualenv

并且,在/home/nb/.local/bin/¹:

nb@ubuntu-0xA520322HC30H:~/proj/redis-py$ cd ~/.local/bin
nb@ubuntu-0xA520322HC30H:~/.local/bin$ ls
pbr  pip2    pip3    virtualenv        virtualenvwrapper_lazy.sh
pip  pip2.7  pip3.5  virtualenv-clone  virtualenvwrapper.sh

我想知道这个神秘的,并且完全没有/usr/local/bin/python3.6在代码中。

所以我安装了一个全文搜索工具并在〜/ .local文件夹中查找。

nb@ubuntu-0xA520322HC30H:~$ cd .local
nb@ubuntu-0xA520322HC30H:~/.local$ sudo apt-get install --quiet --quiet silversearcher-ag
nb@ubuntu-0xA520322HC30H:~/.local$ ag '/usr/local/bin/python3.6'
bin/virtualenv-clone
1:#!/usr/local/bin/python3.6

bin/pbr
1:#!/usr/local/bin/python3.6

看起来像是在2个地方对Python的静态引用。

我现在有两个选择:

  1. 我可以在那里编辑/usr/local/bin/python3.6文本来引用/usr/bin/python3.6

  2. 我可以通过/usr/local/bin/python3.6 - &gt; /usr/bin/python3.6

  3. 制作符号链接

    我选择了bin/virtualenv-clone文件的选项1: enter image description here

    但我也做了选项2,以防万一我的系统上存在此问题。

    nb@ubuntu-0xA520322HC30H:~$ sudo ln -s /usr/bin/python3.6 /usr/local/bin/python3.6
    

    嗯,无论如何,这都有效:

    nb@ubuntu-0xA520322HC30H:~/.local$ mkvirtualenv --python='/usr/bin/python3' redispytest
    Running virtualenv with interpreter /usr/bin/python3
    Using base prefix '/usr'
    New python executable in /home/nb/Envs/redispytest/bin/python3
    Also creating executable in /home/nb/Envs/redispytest/bin/python
    Installing setuptools, pip, wheel...done.
    virtualenvwrapper.user_scripts creating /home/nb/Envs/redispytest/bin/predeactivate
    virtualenvwrapper.user_scripts creating /home/nb/Envs/redispytest/bin/postdeactivate
    virtualenvwrapper.user_scripts creating /home/nb/Envs/redispytest/bin/preactivate
    virtualenvwrapper.user_scripts creating /home/nb/Envs/redispytest/bin/postactivate
    virtualenvwrapper.user_scripts creating /home/nb/Envs/redispytest/bin/get_env_details
    (redispytest) nb@ubuntu-0xA520322HC30H:~/.local$
    

    摘要:找出virtualenv尝试使用的解释器位置,并从该位置创建一个符号链接到您的实际Python。

    你需要这样做的原因是至少有几个virtualenv位置会有一个#!行引用一个特定的位置,但是如果你从编译自己的Python开始转换就不会改变使用PPA。

    起初我对此犹豫不决,因为我更喜欢让包管理器处理这类事情,而不是让我的路径太复杂。但似乎没有任何其他方法来解决这个问题。我尝试卸载并重新安装virtualenvvirtualenvwrapper,但无济于事。

    ¹嗯...我的.local / bin中有 pbr 。接下来是什么,我的.local /冰箱?该死的赶时髦的人。