使用pip安装后找不到cookiecutter命令

时间:2016-07-03 17:28:58

标签: python django cookiecutter-django

我想使用cookiecutter来启动django项目,但由于某种原因,无法找到cookiecutter。

我做的是:

pip install cookiecutter

之后:

cookiecutter https://github.com/pydanny/cookiecutter-django

然后我收到错误消息:

    The program 'cookiecutter' is currently not installed. You can install it by typing:
    sudo apt install cookiecutter

但是,当我使用apt安装cookiecutter并运行cookiecutter https://github.com/pydanny/cookiecutter-django时,我收到错误。

Traceback (most recent call last):
  File "/usr/bin/cookiecutter", line 9, in <module>
    load_entry_point('cookiecutter==1.3.0', 'console_scripts', 'cookiecutter')()
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/cookiecutter/cli.py", line 100, in main
    config_file=user_config
  File "/usr/lib/python2.7/dist-packages/cookiecutter/main.py", line 140, in cookiecutter
    output_dir=output_dir
  File "/usr/lib/python2.7/dist-packages/cookiecutter/generate.py", line 327, in generate_files
    generate_file(project_dir, infile, context, env)
  File "/usr/lib/python2.7/dist-packages/cookiecutter/generate.py", line 167, in generate_file
    tmpl = env.get_template(infile_fwd_slashes)
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 812, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 786, in _load_template
    template = self.loader.load(self, name, globals)
  File "/usr/lib/python2.7/dist-packages/jinja2/loaders.py", line 125, in load
    code = environment.compile(source, name, filename)
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 565, in compile
    self.handle_exception(exc_info, source_hint=source_hint)
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "./LICENSE", line 3, in template
jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'now'. Jinja was looking for the following tags: 'elif' or 'else' or 'endif'. The innermost block that needs to be closed is 'if'.
  File "./LICENSE", line 3
    Copyright (c) {% now 'utc', '%Y' %}, {{ cookiecutter.author_name }}

我理解这与cookiecutter的版本有关,必须是&gt; = 1.4 pip包是版本1.4,但不会运行。

我在这里缺少什么?

我正在使用virtualbox,因此这不在virtualenv中。

2 个答案:

答案 0 :(得分:8)

对不起,但看起来你正在混淆。

  1. 因为sudo apt-get install cookiecutter安装了一些东西 叫做cookiecutter并不意味着它是同一个cookiecutter 点子。事实上,他们没有任何共同之处。一个是用于python的cookie切割器,另一个用于django。
  2. 这是一个cookiecutter 在启动板上,你用apt-get安装的那个: https://launchpad.net/ubuntu/+source/cookiecutter
  3. 这是什么 您正在寻找:https://pypi.python.org/pypi/cookiecutter-django
  4. 回到你的问题:

    如果您希望为自己省去一些麻烦,即使您在Virtualbox中工作,设置VirtualEnv来处理项目的封装也没什么不错。

    我只是从对你的问题的理解,复制,并在几秒钟内完成所有工作。

    • mkvirtualenv myProject(假设你安装了virtualenv和virtualenvwrapper,添加到~/.bashrc并重启bash,重新启动终端gui,或souce ~/.bashrc
    • workon myProject
    • 然后在(myProject) $~提示符下,继续安装,即:
    • sudo apt install python-pip
    • pip install cookiecutter
    • 然后照常进行,cookiecutter https://github.com/pydanny/cookiecutter-django.git

    除非您计划为您希望启动的每个Django项目启动Ubuntu虚拟机实例,否则我建议您使用virtualenv来保持干净。

答案 1 :(得分:1)

您也可以使用

python -m cookiecutter https://github.com/pydanny/cookiecutter-django