Python3无法访问python2模块(ubuntu)
我对编程和Ubuntu相当陌生。昨天我终于创建了一个双启动系统,所以现在我运行的是Ubuntu12.04LTS。 对于一个学校项目,我需要在Python3中使用一个名为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并使用“importsparqlwrapper”,它就会正常工作。但如果我在python3中尝试相同的方法,则会出现以下错误:Python3无法访问python2模块(ubuntu),python,ubuntu,python-3.x,installation,python-2.x,Python,Ubuntu,Python 3.x,Installation,Python 2.x,我对编程和Ubuntu相当陌生。昨天我终于创建了一个双启动系统,所以现在我运行的是Ubuntu12.04LTS。 对于一个学校项目,我需要在Python3中使用一个名为SPARQLWrapper()的模块 在我新安装的Ubuntu上,我安装了最新版本的Python。当我在终端中键入“python3”时,python3.2.3将启动,这很好。 我安装了easy_install(sudo-apt-get-install-python-setuptools),下载并安装了SPARQLWrapper-e
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
x@ubuntu:~$python3
Python 3.2.3(默认值,2012年10月19日,20:10:41)
[GCC 4.6.3]关于linux2
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>导入SPARQLWrapper
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ImportError:没有名为SPARQLWrapper的模块
所以我的问题是python3无法访问与python2相同的模块。我该如何解决这个问题?
谢谢 每个Python安装都有自己的模块目录。此外,Python3不向后兼容,通常不会运行Python2代码。您需要找到所需模块的Python3版本,并为Python3安装它。要为Python3安装软件包,您需要Python3的setuptools 以下是安装python3的setuptools和
SPARQLWrapper
sudo apt get install python3 setuptools
sudo easy\u install3 pip
pip-V
这应该显示与python3安装相对应的pipsudo pip安装SPARQLWrapper
~$ 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()
~$
在我的系统(Ubuntu16.04)上,python3的pip是用“pip3”调用的