cookiecutter command not found after installing with pip

此生再无相见时 提交于 2020-12-08 06:34:56

问题


I want to use cookiecutter to start a django project but for some reason cookiecutter cannot be found.

What I did was:

pip install cookiecutter

After that:

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

Then I get the error message:

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

However when I install cookiecutter with apt and run cookiecutter https://github.com/pydanny/cookiecutter-django I get an error.

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 }}

I understand this has to do with the version of cookiecutter which has to be >=1.4
The pip package is version 1.4, but that won't run.

What am I missing here?

I am using virtualbox so therefore this is not inside a virtualenv.


回答1:


I'm sorry but it appears you're mixing things up.

  1. Because sudo apt-get install cookiecutter installs something called cookiecutter doesn't mean it is the same cookiecutter from pip. In fact, they have nothing in common. One is a cookie cutter for python, and the other is for django.
  2. This is the cookiecutter on launchpad, the one you installed with apt-get: https://launchpad.net/ubuntu/+source/cookiecutter
  3. And this is what you're looking for: https://pypi.python.org/pypi/cookiecutter-django

So back to your question:

If you wish to save yourself some headache, even if you're working within a Virtualbox, there's nothing wrong setting up a VirtualEnv to handle the encapsulation of your projects.

I just, from the understanding of your question, replicated, and got everything working in seconds.

  • mkvirtualenv myProject (assuming you have virtualenv and virtualenvwrapper installed, added to ~/.bashrc and bash restarted, either restarting terminal gui, or souce ~/.bashrc
  • workon myProject
  • Then within the (myProject) $~ prompt, proceed with your installations, namely:
  • sudo apt install python-pip
  • pip install cookiecutter
  • Then proceed as normal, cookiecutter https://github.com/pydanny/cookiecutter-django.git

Unless you plan to spin up Ubuntu virtualbox instances for each Django project you wish to start, I will recommend you use virtualenv to keep things clean.




回答2:


You can also run that with

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


来源:https://stackoverflow.com/questions/38172539/cookiecutter-command-not-found-after-installing-with-pip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!