如何在 Ubuntu 10.10 上安装 Python 2.7 模块?
在 Ubuntu 10.10 上,我无法将 lxml 安装到 python 2.7。这是我采取的步骤。
sudo su -
apt-get install python2.7
apt-get install python-lxml
请注意,在运行 python-lxml 包的安装时,出现以下内容:
INFO: using unknown version '/usr/bin/python2.7' (debian_defaults not up-to-date?)"
在 python2.6(Ubuntu 标配版本)中导入模块有效。但是在python2.7下导入模块则不行。那么如何将 Python 模块安装到非默认 Python 安装中呢?
On Ubuntu 10.10, I am unable to install lxml to python 2.7. Here are the steps I take.
sudo su -
apt-get install python2.7
apt-get install python-lxml
Note when running the install for python-lxml package, the following appeared:
INFO: using unknown version '/usr/bin/python2.7' (debian_defaults not up-to-date?)"
Importing the module in python2.6 (the version that comes standard with Ubuntu) works. However, importing the module under python2.7 does not. So how does one install Python modules to a non-default Python installation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试安装
libxml2、libxml2-dev、libxslt、libxslt-dev、python-dev
。这些是头文件。然后尝试再次安装lxml
。Try to install
libxml2, libxml2-dev, libxslt, libxslt-dev, python-dev
. These are header files. Then try to installlxml
again.在 Ubuntu 10.10 上,从存储库安装的 python 软件包安装到 /usr/lib/python2.6/dist-packages,因此一种选择是将此路径添加到 $PYTHONPATH 环境变量中,以便 python2.7 将查找 python2.6库的目录。
我在 Ubuntu 10.10 上所做的是将其添加
到我的 .bashrc 文件和 .gnomerc 文件中。这会为从 shell 或 gnome 桌面启动的 python 实例设置 $PYTHONPATH。然后,您应该能够导入从 python2.7 中的 Ubuntu 存储库安装的 python 库。
.bashrc 和 .gnomerc 都位于您的主目录中;如果 .gnomerc 尚不存在,您可能需要创建它。还有一个警告:我的 .gnomerc 中有一个语法错误,导致 gnome 桌面无法加载,而且我无法登录。我必须使用恢复控制台来修复此语法错误,然后我才能再次登录。
这对我来说似乎有点老套,所以我有兴趣听到更好的解决方案。
On Ubuntu 10.10 the python packages installed from the repositories get installed to /usr/lib/python2.6/dist-packages so one option is to add this path to your $PYTHONPATH environmental variable so python2.7 will look to the python2.6 directory for the libs.
What I've done on Ubuntu 10.10 is add
to my .bashrc file, and also to my .gnomerc file. This sets the $PYTHONPATH for python instances started from the shell or from the gnome desktop. You should then be able to import the python libs which you have installed from the Ubuntu repositories in python2.7.
.bashrc and .gnomerc are both located in your home directory; you might have to create .gnomerc if it doesn't already exist. And one caution: I had a syntax error in my .gnomerc which stopped the gnome desktop from loading, and I couldn't log in. I had to use a recovery console to fix this syntax error and then I could log in again.
This seems a little hackish to me, so I'm interested in hearing better solutions.
另一种解决方案可能是使用以下代码:
[Source]
这将导入 lxml(如果可用),或者否则是原始的 ElementTree。
我在 Google App Engine 上的应用程序中使用此代码(使用 Python 2.7):在服务器上它将使用 lxml,在我的计算机上它将使用 ElementTree。
Another solution might be to use the following code:
[Source]
This will import lxml if it is available, or the original ElementTree otherwise.
I use this code for my application on Google App Engine (using Python 2.7): on the server it will use lxml, on my machine it will use ElementTree.
我有一个最简单的技巧,只需打开突触包管理器,在搜索框中输入“python-lxml”,它就会向您显示所有依赖项和可用的包,选择您想要安装的包并点击“应用”。
I have one easiest trick Just open synaptic package manager type "python-lxml" in search box it will show you all the dependencies and available packages select packages which you want to install and hit apply.