【问题标题】:Confusing Python install in user local (virtualenv, pip, distribute)令人困惑的 Python 安装在用户本地(virtualenv、pip、distribute)
【发布时间】:2011-07-19 04:18:12
【问题描述】:

我尝试以下面的方式安装 python。但这没有用。 这需要“错误:错误的安装目录或 PYTHONPATH”。

What's the proper way to install pip, virtualenv, and distribute for Python?

制作目录

$ mkdir -p ~/.python

添加.bashrc

#Use local python
export PATH=$HOME/.python/bin:$PATH
export PYTHONPATH=$HOME/.python

创建一个文件 ~/.pydistutils.cfg

[install]
prefix=~/.python

获取安装脚本

$ cd ~/src
$ curl -O http://python-distribute.org/distribute_setup.py

执行和错误

$ python ./distribute_setup.py
Extracting in /tmp/tmpsT2kdA
Now working in /tmp/tmpsT2kdA/distribute-0.6.15
Installing Distribute
Before install bootstrap.
Scanning installed packages
No setuptools distribution foundrunning install
Checking .pth file support in /home/sane/.python/lib/python2.6/site-packages//usr/bin/python -E -c pass
TEST FAILED: /home/sane/.python/lib/python2.6/site-packages/ does NOT support .pth files
error: bad install directory or PYTHONPATH
You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from.  The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/home/sane/.python/lib/python2.6/site-packages/
and your PYTHONPATH environment variable currently contains:
'/home/sane/.python'
Here are some of your options for correcting the problem:
* You can choose a different installation directory, i.e., one that is 
on PYTHONPATH or supports .pth files
* You can add the installation directory to the PYTHONPATH environment 
variable.  (It must then also be on PYTHONPATH whenever you run 
Python and want to use the package(s) you are installing.)
* You can set up the installation directory to support ".pth" files by 
using one of the approaches described here:
http://packages.python.org/distribute/easy_install.html#custom-installation-locations

Please make the appropriate changes for your system and try again.
Something went wrong during the installation.
See the error message above.

我的环境('sane' 是我的 unix 用户名。)

$ python -V
Python 2.6.4
$ which python
/usr/bin/python
$ uname -a
Linux localhost.localdomain 2.6.34.8-68.fc13.x86_64 #1 SMP Thu Feb 17 15:03:58 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

【问题讨论】:

    标签: python installation virtualenv pip distribute


    【解决方案1】:

    我选择 pythonbrew。 我可以通过这个在我的主目录中使用多个 Python。 这是一项很棒的工作。

    utahta/pythonbrew - GitHub https://github.com/utahta/pythonbrew

    【讨论】:

    • "此项目不再处于积极开发中。鼓励您尝试pyenv。" - pythonbrew的自述文件
    【解决方案2】:

    通常我在我的全局 Python 安装中安装了分布式/easy_install 又名 setuptools 以及 virtualenv。从现在开始,我可以使用

    创建专用的虚拟化环境
    virtualenv --no-site-packages name-of-environment
    

    真的不知道为什么要在这里摆弄 PYTHONPATH。

    将 /path/to/name-of-environment/bin 添加到 $PATH 足​​以添加虚拟化 Python 到你的 $PATH。你不需要其他任何东西。

    【讨论】:

      猜你喜欢
      • 2014-01-26
      • 1970-01-01
      • 2012-05-18
      • 2013-05-22
      • 2012-09-22
      • 2020-05-17
      • 2013-08-23
      • 2015-01-05
      • 1970-01-01
      相关资源
      最近更新 更多