2012-10-03 128 views
0

我試着用簡單的安裝來安裝模塊。它似乎已經安裝,但我無法導入它。import python module

# easy_install uuid 
Searching for uuid 
Reading http://pypi.python.org/simple/uuid/ 
Reading http://zesty.ca/python/ 
Best match: uuid 1.30 
Downloading http://pypi.python.org/packages/source/u/uuid/uuid-1.30.tar.gz#md5=639b310f1fe6800e4bf8aa1dd9333117 
Processing uuid-1.30.tar.gz 
Running uuid-1.30/setup.py -q bdist_egg --dist-dir /tmp/easy_install-mQlxdg/uuid-1.30/egg-dist-tmp-gLpk9N 
zip_safe flag not set; analyzing archive contents... 
Adding uuid 1.30 to easy-install.pth file 

Installed /usr/lib/python2.6/site-packages/uuid-1.30-py2.6.egg 
Processing dependencies for uuid 
Finished processing dependencies for uuid 


# python 
>>> import uuid 
Traceback (most recent call last): 
    File "<stdin>", line 1, in ? 
ImportError: No module named uuid 


# python -V 
Python 2.4.3 

回答

3

easy_install清楚地表明,該模塊被安裝到/usr/lib/python2.6,但你正在運行的Python 2.4。

要麼明確運行Python 2.6(例如python2.6python26),要麼使用python -m easy_install uuid將模塊安裝到默認Python。

+0

[documentation](http://packages.python.org/distribute/easy_install.html#multiple-python-versions)還表示您可以在命令行中指定'easy_install'目標的版本。 (例如'easy_install-2.4') –

+1

是的。但是,偶爾我會遇到安裝了相同版本Python的多個副本的情況(在OS X上,如果您在系統Python中安裝'python.org'Python),就會發生這種情況。在這種情況下,最好使用解釋器調用本身來消除歧義。 – nneonneo

+0

這不太可能有幫助,因爲如果你有兩個'python-2.6's,那麼無論如何,你都會首先得到'PATH'上的那個,就像你運行'easy_install-2.6'一樣。 – Julian

0

你看過你發佈的內容:)?

Installed /usr/lib/python2.6/site-packages/uuid-1.30-py2.6.egg 

# python -V 
Python 2.4.3 

如果你正在使用Python 2.6(你應該,因爲即使現在老了,2.4是古),該uuid模塊應該存在了,所以你不應該需要無論如何安裝。

+0

我覺得你的意思是_你不應該這麼做__ –

+0

不,我的意思是應該,而不是他所擁有的2.4。雖然如果2.7是一個選項,那麼確實也不錯。 – Julian