【发布时间】:2026-01-17 02:50:01
【问题描述】:
我的 python 2.7 安装在 /usr/local/lib 中。
如果我输入which python2.7,我可以输入/usr/local/bin/python2.7。
然后我在 ~/.bashrc 中将 PYTHONPATH 设置为
export PYTHONPATH="/usr/local/bin/python2.7:$PYTHONPATH"
我喜欢安装 pip 和虚拟环境。 然后尝试了
sudo apt-get install python-pip python-dev python-virtualenv
在/usr/lib寻找python时发现如下错误:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-dev is already the newest version.
python-pip is already the newest version.
python-virtualenv is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 362 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up python2.7 (2.7.6-8ubuntu0.2) ...
python2.7: can't open file '/usr/lib/python2.7/py_compile.py': [Errno 2] No such file or directory
dpkg: error processing package python2.7 (--configure):
subprocess installed post-installation script returned error exit status 2
Errors were encountered while processing:
python2.7
E: Sub-process /usr/bin/dpkg returned an error code (1)
如何正确设置python路径?
编辑: 我的 echo $PATH 给了
/usr/local/bin:/usr/local/cuda-8.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/bin/python2.7
echo $PYTHONPATH 给了
/home/coie/Softwares/apollocaffe/python:/usr/local/bin/python2.7:
【问题讨论】:
-
只是验证一下,您的意思是
~/.bashrc而不是~/bashrc,对吧? -
对不起~/.bashrc
标签: python-2.7 ubuntu ubuntu-14.04