簡體   English   中英

Python3無法訪問python2模塊(ubuntu)

[英]Python3 has no acces to python2 modules (ubuntu)

我是編程和Ubuntu的新手。 昨天我終於設法創建了一個雙啟動系統,所以現在我正在運行Ubuntu 12.04 LTS。 對於學校項目,我需要使用名為SPARQLWrapper( https://pypi.python.org/pypi/SPARQLWrapper )的模塊在Python3中工作。

在我剛剛安裝的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的setuptools。

以下是安裝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()
~$ 

每個Python安裝都有自己的模塊目錄。 此外,Python 3不向后兼容,通常不會運行Python 2代碼。 您需要找到所需模塊的Python 3版本並為Python 3安裝它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM