Python 尝试设置virtualenv会出现错误';无法导入名称"删除"死亡"weakref';安装梵蒂克时
我正在尝试安装vatic,其中一个要求是从vatic工作区运行“virtualenv.env”。当我运行这个程序时,我发现~/anaconda2/lib/python2.7/weakref.py有一个错误“无法导入名称\u删除\u死亡\u weakref”Python 尝试设置virtualenv会出现错误';无法导入名称"删除"死亡"weakref';安装梵蒂克时,python,python-2.7,virtualenv,Python,Python 2.7,Virtualenv,我正在尝试安装vatic,其中一个要求是从vatic工作区运行“virtualenv.env”。当我运行这个程序时,我发现~/anaconda2/lib/python2.7/weakref.py有一个错误“无法导入名称\u删除\u死亡\u weakref” virtualenv .env New python executable in /home/tyler/vatic_ws/.env/bin/python Installing setuptools, pip, wheel... Co
virtualenv .env
New python executable in /home/tyler/vatic_ws/.env/bin/python
Installing setuptools, pip, wheel...
Complete output from command /home/tyler/vatic_ws/.env/bin/python - setuptools pip wheel:
Traceback (most recent call last):
File "<stdin>", line 7, in <module>
File "/home/tyler/anaconda2/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/__init__.py", line 5, in <module>
File "/home/tyler/anaconda2/lib/python2.7/logging/__init__.py", line 26, in <module>
import sys, os, time, cStringIO, traceback, warnings, weakref, collections
File "/home/tyler/anaconda2/lib/python2.7/weakref.py", line 14, in <module>
from _weakref import (
ImportError: cannot import name _remove_dead_weakref
我没有错。为什么我不能复制错误,如何修复它?说明的相关部分:
# How does the Anaconda Python binary usually wind up linking to their
# own "libpython2.7.so" instead of Ubuntu's? By, it turns out, having a
# relative RPATH - that only works if their Python binary is sitting
# right next to the "lib" directory containing their libpython:
#
# $ readelf -d anaconda/bin/python2.7 | grep RPATH
# 0x0000000f (RPATH) Library rpath: [$ORIGIN/../lib]
#
# This situation obviously does not pertain in a new virtualenv since it
# only copies in a minimal ".../lib/pythonX.Y" directory, not any shared
# libraries into "../lib" itself. Hence the linker falls back to
# discovering and linking to the system "libpythonX.Y.so".
你需要运行他的脚本。我将在这里复制脚本,以防它消失
if ! python -c 'import virtualenv' 2>/dev/null
then
echo 'Error: virtualenv is not available to the current "python" binary'
exit 1
fi
venv=$(python -c 'import virtualenv; print(virtualenv.__file__)')
venv=${venv%c}
if grep -q 'Added by Brandon' $venv
then
echo 'Exiting: virtualenv.py has already been fixed'
exit 0
fi
echo 'Editing virtualenv.py'
sed -i -f - $venv <<'EOF'
/^ stdlib_dirs = /i\
\
# Added by Brandon's ",fix-virtualenv" script to copy the Anaconda\
# libpython libraries into the new environment as well:\
outer_lib_dir = os.path.dirname(lib_dir)\
conda_lib_dir = os.path.dirname(os.path.dirname(os.__file__))\
for fn in os.listdir(conda_lib_dir):\
if fn.startswith('libpython'):\
copyfile(join(conda_lib_dir, fn), join(outer_lib_dir, fn), symlink)\
EOF
if!python-c'import virtualenv'2>/dev/null
然后
echo'错误:virtualenv对当前的“python”二进制文件不可用'
出口1
fi
venv=$(python-c‘导入虚拟现实;打印(虚拟现实文件)’)
venv=${venv%c}
如果grep-q'由Brandon'添加,$venv
然后
echo“退出:virtualenv.py已修复”
出口0
fi
echo“编辑virtualenv.py”
sed-i-f-$venv
if ! python -c 'import virtualenv' 2>/dev/null
then
echo 'Error: virtualenv is not available to the current "python" binary'
exit 1
fi
venv=$(python -c 'import virtualenv; print(virtualenv.__file__)')
venv=${venv%c}
if grep -q 'Added by Brandon' $venv
then
echo 'Exiting: virtualenv.py has already been fixed'
exit 0
fi
echo 'Editing virtualenv.py'
sed -i -f - $venv <<'EOF'
/^ stdlib_dirs = /i\
\
# Added by Brandon's ",fix-virtualenv" script to copy the Anaconda\
# libpython libraries into the new environment as well:\
outer_lib_dir = os.path.dirname(lib_dir)\
conda_lib_dir = os.path.dirname(os.path.dirname(os.__file__))\
for fn in os.listdir(conda_lib_dir):\
if fn.startswith('libpython'):\
copyfile(join(conda_lib_dir, fn), join(outer_lib_dir, fn), symlink)\
EOF