gpt4 book ai didi

Python3 无法访问 python2 模块 (ubuntu)

转载 作者:太空狗 更新时间:2023-10-29 22:13:34 25 4
gpt4 key购买 nike

我是编程和 Ubuntu 的新手。昨天我终于成功创建了一个双引导系统,所以现在我运行的是 Ubuntu 12.04 LTS。对于学校项目,我需要在 Python3 中使用名为 SPARQLWrapper ( https://pypi.python.org/pypi/SPARQLWrapper ) 的模块。

在我新安装的 Ubuntu 上,我安装了最新版本的 Python。当我在我的终端中键入“python3”时,python 3.2.3 启动,这很好。我安装了 easy_install (sudo apt-get install python-setuptools),并下载并安装了 SPARQLWrapper egg 文件 (sudo easy_install SPARQLWrapper-1.5.2-py3.2)。

如果我运行 python2 并使用“import 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 相同的模块。我该如何解决?谢谢!

最佳答案

要为 Python3 安装包,您需要 python3 的设置工具。

以下是安装 python3 的 setuptools 和 SPARQLWrapper

的步骤
  1. sudo apt-get install python3-setuptools
  2. sudo easy_install3 pip
  3. pip -V 这应该显示与您的 python3 安装对应的 pip。
  4. sudo pip install 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()
~$

关于Python3 无法访问 python2 模块 (ubuntu),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16709914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com