我是编程和Ubuntu的新手。昨天我终于创建了一个双引导系统,所以现在我运行的是Ubuntu 12.04 LTS。对于一个学校项目,我需要在Python3中使用一个名为SPARQLWrapper (https://pypi.python.org/pypi/SPARQLWrapper)的模块。
在我新安装的Ubuntu上,我已经安装了最新版本的Python。当我在我的终端输入"python3“时,Python3.2.3启动了,所以这很好。我安装了easy_install (sudo apt-get install python-setuptools),并下载并安装了SPARQLWrapper egg文件(sudo easy_install SPARQLWrapper-1.5.2-py3.2)。
如果我运行python2并使用“导入SPARQLWrapper",它就能正常工作。但是如果我在python3中尝试同样的操作,它会给出以下错误:
x@ubuntu:~$ python3
Python 3.2.3 (default, Oct 19 2012, 20:10:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import SPARQLWrapper
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named SPARQLWrapper所以我的问题是python3不能像我的python2一样访问相同的模块。我该如何解决这个问题?谢谢!
发布于 2013-05-23 18:07:32
要安装Python3的软件包,您需要python3的setuptools。
下面是安装python3的setuptools和SPARQLWrapper需要遵循的步骤
sudo apt-get install python3-setuptoolssudo easy_install3 pippip -V此命令应显示与您的python3 installation.sudo pip install SPARQLWrapper对应的pip
完成上面提到的步骤后,我得到以下结果
~$ python3
Python 3.3.1 (default, Apr 17 2013, 22:30:32)
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import SPARQLWrapper
>>> exit()
~$ 发布于 2013-05-23 17:15:52
每个Python安装都有自己的模块目录。此外,Python3不向后兼容,通常不会运行Python2代码。您需要找到所需模块的Python3版本,并为Python3安装它。
https://stackoverflow.com/questions/16709914
复制相似问题