0

所以,我以为我已经正确安装了setuptools和argparse 1.2.1。无法在Windows上为python 2.5导入argparse 1.2.1

C:\Python25_64bit>python ez_setup.py argparse 
Searching for argparse 
Best match: argparse 1.2.1 
Processing argparse-1.2.1-py2.5.egg 
argparse 1.2.1 is already the active version in easy-install.pth 

Using c:\python25_64bit\lib\site-packages\argparse-1.2.1-py2.5.egg 
Processing dependencies for argparse 
Finished processing dependencies for argparse 

C:\Python25_64bit>python 
Python 2.5.4 (r254:67916, Dec 23 2008, 15:19:34) [MSC v.1400 64 bit (AMD64)] on 
win32 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import argparse 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named argparse 
>>> quit() 

但是,看起来我无法导入它,如上所述。我也试着直接将这个鸡蛋添加到我的Eclipse PyDev项目中,但这也无济于事。正如你所看到的,我的环境中没有设置任何东西。也许,这是问题吗?

C:\Python25_64bit>echo %PYTHONPATH% 
%PYTHONPATH% 

C:\Python25_64bit>echo %PYTHONHOME% 
%PYTHONHOME% 
+0

我总是假设Lib/site-packages是导入搜索路径的一部分。这是不正确的? 'C:\ Python25_64bit \ Lib \ site-packages> dir ... C:\ Python25_64bit \ Lib \ site-packages目录 2012-08-28 05:41 PM

。 2012-08-28 05:41 PM .. 2012-08-27 10:55 AM 21,499 argparse-1.2.1-py2.5.egg' – kevinmm

回答

0

我希望您在安装时注意并注意在哪里安装了​​。 在你的脚本(从命令行或从IDE中运行)包括在顶部:

import sys 
for p in sys.path: 
    print repr(p) 

看到所有的路径蟒蛇正在搜索通过。要么使用argparse添加路径:

sys.path.insert(0, '/your/path/to/argparse') 

或将安装移至路径中的某处。

环境变量可以是空的,也可以编译为sys.path的元素。