如何设置python安装路径?

时间:2016-11-08 08:33:14

标签: python-2.7 ubuntu ubuntu-14.04

我的pyhton2.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路径?

编辑: 我的回音$ 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:

3 个答案:

答案 0 :(得分:1)

我使用/usr/local删除了>sudo rm -rf /usr/local/lib/python* or libpython*中安装的所有python。 bin和share文件夹中的那些也被清理。 然后由于所有程序都在/usr内查找python,安装路径设置为sudo ./configure --prefix = /usr

答案 1 :(得分:0)

根据https://askubuntu.com/a/250935/610294

尝试附加到PYTHONPATH而不是完全覆盖它。

阅读:用以下内容替换你添加到bashrc的行:

export PYTHONPATH=$PYTHONPATH:/usr/local/bin/python2.7

答案 2 :(得分:0)

输入setenv PATH" $ PATH:/ usr / local / bin / python"然后按Enter键。 要么  type export ATH =" $ PATH:/ usr / local / bin / python"然后按Enter键。