在用户本地安装令人困惑的 Python(virtualenv、pip、distribute)

发布于 2024-10-24 16:36:49 字数 2478 浏览 7 评论 0原文

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

正确的方法是什么为 Python 安装 pip、virtualenv 和分发?

创建目录

$ 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

I tried to install python below way. But this did not work.
This take "error: bad install directory or PYTHONPATH".

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

Make directory

$ mkdir -p ~/.python

Add .bashrc

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

Create a file ~/.pydistutils.cfg

[install]
prefix=~/.python

Get install script

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

Execute and Error

$ 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.

My environment('sane' is my unix user name.)

$ 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谎言 2024-10-31 16:36:49

通常我在我的全局Python安装中与virtualenv一起安装了distributed/easy_install aka setuptools。从现在起,我可以使用

virtualenv --no-site-packages name-of-environment

“真的不知道为什么要在这里摆弄 PYTHONPATH”来创建专用的虚拟化环境。

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

Usually I installed distributed/easy_install aka setuptools in my global Python installation together with virtualenv. From this point on I can created dedicated virtualalized environments using

virtualenv --no-site-packages name-of-environment

Really no idea why to fiddle around with PYTHONPATH here.

Adding /path/to/name-of-environment/bin to $PATH is good enough for adding the virtualized
Python to your $PATH. You don't need any else.

唱一曲作罢 2024-10-31 16:36:49

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

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

I choice pythonbrew.
I can use multiple Pythons in my home directory by this.
It's a great job.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文