【问题标题】:How can I install argparse in Python 3.1?如何在 Python 3.1 中安装 argparse?
【发布时间】:2011-06-05 19:53:32
【问题描述】:

我正在尝试让 argparse 安装在 Python 3.1 中,但是当我 easy_install 时,我从 setup.py 中得到了 UnicodeDecodeError

(ve31) offline@void (projects) $ easy_install argparse
install_dir /Users/offline/tmp/ve31/lib/python3.1/site-packages/
Searching for argparse
Reading http://pypi.python.org/simple/argparse/
Reading http://code.google.com/p/argparse/
Reading http://argparse.python-hosting.com/
Download error: [Errno 8] nodename nor servname provided, or not known -- Some packages may not be found!
Reading http://argparse.python-hosting.com/
Download error: [Errno 8] nodename nor servname provided, or not known -- Some packages may not be found!
Page at http://pypi.python.org/simple/argparse/ links to .py file(s) without version info; an index scan is required.
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
Reading http://argparse.python-hosting.com/file/trunk/argparse.py?rev=6&format=raw
Download error: [Errno 8] nodename nor servname provided, or not known -- Some packages may not be found!
Reading http://argparse.python-hosting.com/
Download error: [Errno 8] nodename nor servname provided, or not known -- Some packages may not be found!
Reading http://argparse.python-hosting.com/
Download error: [Errno 8] nodename nor servname provided, or not known -- Some packages may not be found!
Reading http://argparse.python-hosting.com/
Download error: [Errno 8] nodename nor servname provided, or not known -- Some packages may not be found!
Reading http://argparse.python-hosting.com/
Download error: [Errno 8] nodename nor servname provided, or not known -- Some packages may not be found!
Reading http://argparse.python-hosting.com/
Download error: [Errno 8] nodename nor servname provided, or not known -- Some packages may not be found!
Reading http://argparse.python-hosting.com/
Download error: [Errno 8] nodename nor servname provided, or not known -- Some packages may not be found!
Reading http://argparse.python-hosting.com/
Download error: [Errno 8] nodename nor servname provided, or not known -- Some packages may not be found!
Best match: argparse 1.1
Downloading http://pypi.python.org/packages/source/a/argparse/argparse-1.1.zip#md5=087399b73047fa5a6482037411ddc968
Processing argparse-1.1.zip
Running argparse-1.1/setup.py -q bdist_egg --dist-dir /var/folders/jj/jjpHKlEGGDCZAkn87y0qBU+++TI/-Tmp-/easy_install-DQ9nUb/argparse-1.1/egg-dist-tmp-zMCdC1
Traceback (most recent call last):
  File "/Users/offline/tmp/ve31/bin/easy_install", line 9, in <module>
    load_entry_point('distribute==0.6.14', 'console_scripts', 'easy_install')()
  File "/Users/offline/tmp/ve31/lib/python3.1/site-packages/distribute-0.6.14-py3.1.egg/setuptools/command/easy_install.py", line 1855, in main
    with_ei_usage(lambda:
  File "/Users/offline/tmp/ve31/lib/python3.1/site-packages/distribute-0.6.14-py3.1.egg/setuptools/command/easy_install.py", line 1836, in with_ei_usage
    return f()
  File "/Users/offline/tmp/ve31/lib/python3.1/site-packages/distribute-0.6.14-py3.1.egg/setuptools/command/easy_install.py", line 1859, in <lambda>
    distclass=DistributionWithoutHelpCommands, **kw
  File "/usr/local/Cellar/python3/3.1.3/lib/python3.1/distutils/core.py", line 149, in setup
    dist.run_commands()
  File "/usr/local/Cellar/python3/3.1.3/lib/python3.1/distutils/dist.py", line 919, in run_commands
    self.run_command(cmd)
  File "/usr/local/Cellar/python3/3.1.3/lib/python3.1/distutils/dist.py", line 938, in run_command
    cmd_obj.run()
  File "/Users/offline/tmp/ve31/lib/python3.1/site-packages/distribute-0.6.14-py3.1.egg/setuptools/command/easy_install.py", line 342, in run
    self.easy_install(spec, not self.no_deps)
  File "/Users/offline/tmp/ve31/lib/python3.1/site-packages/distribute-0.6.14-py3.1.egg/setuptools/command/easy_install.py", line 582, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/Users/offline/tmp/ve31/lib/python3.1/site-packages/distribute-0.6.14-py3.1.egg/setuptools/command/easy_install.py", line 612, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/Users/offline/tmp/ve31/lib/python3.1/site-packages/distribute-0.6.14-py3.1.egg/setuptools/command/easy_install.py", line 802, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/Users/offline/tmp/ve31/lib/python3.1/site-packages/distribute-0.6.14-py3.1.egg/setuptools/command/easy_install.py", line 1079, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/Users/offline/tmp/ve31/lib/python3.1/site-packages/distribute-0.6.14-py3.1.egg/setuptools/command/easy_install.py", line 1068, in run_setup
    run_setup(setup_script, args)
  File "/Users/offline/tmp/ve31/lib/python3.1/site-packages/distribute-0.6.14-py3.1.egg/setuptools/sandbox.py", line 30, in run_setup
    lambda: exec(compile(open(
  File "/Users/offline/tmp/ve31/lib/python3.1/site-packages/distribute-0.6.14-py3.1.egg/setuptools/sandbox.py", line 71, in run
    return func()
  File "/Users/offline/tmp/ve31/lib/python3.1/site-packages/distribute-0.6.14-py3.1.egg/setuptools/sandbox.py", line 31, in <lambda>
    "setup.py"
  File "/Users/offline/tmp/ve31/lib/python3.1/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 39: ordinal not in range(128)

如何将这个非常有用的模块放入我的 Python 3.1 virtualenv 中?

更新

为了完整起见,这里是有问题的运行时:

$ python3.1
Python 3.1.3 (r313:86834, Jan  2 2011, 21:23:36) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin

$ virtualenv5 --version
1.3.4.5

$ uname -a # OSX 10.6.6
Darwin void.local 10.6.0 Darwin Kernel Version 10.6.0: Wed Nov 10 18:13:17 PST 2010; root:xnu-1504.9.26~3/RELEASE_I386 i386

【问题讨论】:

  • Argparse 是 3.2 (docs.python.org/dev/library/argparse.html) 的一部分。您可能需要获取 argparse 的 3.x 兼容版本(或从 3.2 获取)。
  • 您能等到 2011 年 2 月 5 日吗?然后它将成为 Python 3.2(目前处于 Beta 2)中标准库的一部分。
  • 在 Ubuntu 上为我工作。你用什么版本的 virtualenv 来设置它?我在使用 virtualenv3 时遇到了一些麻烦。如果您还没有尝试过名为 virtualenv5 的分支,您可能想尝试一下。
  • 我在 Mac OSX 10.6.6 上使用 virtualenv5。 Python 3.1 版本是 3.1.3,确切地说。我会相应地修改问题。
  • 更好的主意:改用docopt

标签: python easy-install argparse python-3.1


【解决方案1】:

我从 pypi 下载了文件,解压缩并运行 python3 setup.py install。没有错误。在 Ubuntu 10.04 上使用 Python 3.1.2。

$ wget http://argparse.googlecode.com/files/argparse-1.2.1.tar.gz
$ tar -zxvf argparse-1.2.1.tar.gz
$ cd argparse
$ python3 setup.py install

easy_install 也可以,但我有 Distribute 0.6.4。

我怀疑 Distribute 0.6.14 中的一个错误是导致您的问题的原因。提交错误报告。 :)

【讨论】:

  • 我将如何进行测试?当我尝试创建环境时,virtualenv 会自动安装最新的发行版......我将如何强制它使用较旧的发行版?
  • @Chris R:您必须下载旧版本并手动安装。见pypi.python.org/pypi/distribute/0.6.4#source-installation
  • 除上述之外还需要wget http://python-distribute.org/distribute_setup.pypython3 distribute_setup.py 才能成功使用Ubuntu 9.10。
猜你喜欢
  • 1970-01-01
  • 2022-01-06
  • 1970-01-01
  • 2014-06-28
  • 1970-01-01
  • 2017-02-03
  • 1970-01-01
  • 2018-03-26
  • 2011-02-18
相关资源
最近更新 更多