Python - 为python 2.6.6版本安装Argpath的问题

时间:2014-09-22 11:47:09

标签: python python-2.7 pip fedora python-2.6

我已经在我的系统中为python2.6.6安装了argpath包。但是当我尝试运行需要argparser模块的脚本时,仍然会抛出错误" ImportError:没有名为argparse的模块"

我正在使用Fedora 20,所以默认版本是Python 2.7。所以我已经在其他路径中安装了python 2.6(别名python =' /usr/local/bin/python2.6')并且我已经使用pip工具安装了argparser,如下所示,它说"已成功安装"

[root@127 python2.6]# pip install --target=/usr/bin/Python2.6/lib/python2.6/ argparse
Downloading/unpacking argparse
  Downloading argparse-1.2.1.tar.gz (69kB): 69kB downloaded
  Running setup.py egg_info for package argparse

    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '*.pyo' found anywhere in distribution
    warning: no previously-included files matching '*.orig' found anywhere in distribution
    warning: no previously-included files matching '*.rej' found anywhere in distribution
    no previously-included directories found matching 'doc/_build'
    no previously-included directories found matching 'env24'
    no previously-included directories found matching 'env25'
    no previously-included directories found matching 'env26'
    no previously-included directories found matching 'env27'
Installing collected packages: argparse
  Running setup.py install for argparse

    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '*.pyo' found anywhere in distribution
    warning: no previously-included files matching '*.orig' found anywhere in distribution
    warning: no previously-included files matching '*.rej' found anywhere in distribution
    no previously-included directories found matching 'doc/_build'
    no previously-included directories found matching 'env24'
    no previously-included directories found matching 'env25'
    no previously-included directories found matching 'env26'
    no previously-included directories found matching 'env27'
Successfully installed 

argparse
Cleaning up...

但是当我尝试运行我的python脚本时,仍然会说出与下面相同的错误

[root@127 python2.6]# python /home/rajamm/python_scripts/json2csv.py -f /home/rajamm/python_scripts/cvl.json -o /home/rajamm/python_scripts/cvl.csv
Exception in user code:
------------------------------------------------------------
Traceback (most recent call last):
  File "/home/rajamm/python_scripts/json2csv.py", line 6, in <module>
    import fileinput, argparse, json, csv
ImportError: No module named argparse
------------------------------------------------------------
Exiting1.

我已经坚持了2天这个问题。请建议我。

1 个答案:

答案 0 :(得分:0)

我刚刚解决了自己。实际上这是我错误的错误路径,

argparser的安装路径:

[root@127 python2.6]# pwd
/usr/local/lib/python2.6
[root@127 python2.6]# 
[root@127 python2.6]# 

但错误地安装在以下路径中:

[root@127 python2.6]# cd /usr/local/bin/ (Wrong one)
[root@127 bin]# ls -ltr | grep arg
-rwxr-xr-x. 1 root root   87791 Sep 22 17:40 argparse.py
-rwxr-xr-x. 1 root root   61546 Sep 22 17:56 argparse.pyc

其实我是企业用户,我遇到了代理问题。所以我通过使用以下命令解决了代理问题。

pip install -U argparser - 如果您的网络中有代理设置,它将无效。

所以我在下面尝试了代理问题,

export https_proxy=<username>:<password>@<proxy url>:<port no> - 如果您的密码有特殊字符,那么您需要相应地处理它。

所以pip安装程序在默认的Python2.7位置安装了argparser。

然后我修改了如下命令,

pip install --target=/usr/bin/Python2.6/lib/python2.6/ argparse

最后,它将在指定目录中安装argparser包。但在这里我也犯了错误。

对我来说,我已指定/usr/local/lib/python2.6来解决问题。

所以最后的命令是:

1. export https_proxy=<username>:<password>@<proxy url>:<port no>
2. pip install --target=/usr/local/lib/python2.6/ argparse

现在工作正常......感谢上帝。