mikeckennedy / python-for-entrepreneurs-course-demos

Contains all the "handout" materials for Talk Python's Python for Entrepreneurs course. This includes notes and the final version of the website code.
https://training.talkpython.fm/courses/explore_entrepreneurs/python-for-entrepreneurs-build-and-launch-your-online-business
MIT License
286 stars 141 forks source link

Cache busting: the demo -- can't run index.pt #9

Closed ianmonat closed 7 years ago

ianmonat commented 7 years ago

Hi Michael,

I'm following along in the Cache busting lesson and I'm getting some unexpected behavior from PyCharm when I run index.pt.

In the video, you run index.pt in PyCharm and a link appears in a terminal, and when you click the link, a browser opens, displaying the minimally-styled webpage.

When I try running the file (on Windows with the free version of PyCharm), index.pt pops up as a 'Save As' download in my default browser (Chrome). (see img below)

image

image

I tried opening it after I downloaded it but Windows was confused as to which application to use. I saw your tip in the video to hit Shift + F10, but no action happens when I do that.

Any help is appreciated, thanks!

stevepiercy commented 7 years ago

You don't run templates; you run a Pyramid server which loads the templates through your project. This is summarized in the video: https://training.talkpython.fm/player/course/python-for-entrepreneurs-build-and-launch-your-online-business/lecture/50410

You're running the Community Edition, not Professional (although there is a 3-month free license through the course, look under your account) so there might be some differences between what you see in the video, PyCharm documentation, and my comment below.

First you need to edit your run configuration, and create a new run configuration.

Enter the appropriate values. Here's a screenshot of mine for a later chapter. You'll need to adjust the paths for Config file, Python interpreter, and Working directory.

pycharm001

Then click the run button, and your app should run.

ianmonat commented 7 years ago

Hi Steve,

Thanks for the help, I upgraded PyCharm (thanks for that, i didn't see the 3 mo free previously) and created a new run config, subbing in my own paths in the fields you specified. image

I got a small improvement in that the browser didn't launch the .pt file as a download, but I got a run error instead that I can't quite interpret, see below:

C:\Users\imonat\blueyellowpy\Scripts\python.exe "C:\Program Files (x86)\JetBrains\PyCharm 2016.3.2\helpers\pycharm\pycharm_load_entry_point.py" C:\Users\imonat\Desktop\Python_Scripts\PyForEnt\python-for-entrepreneurs-course-demos\2-web-starter\blue_yellow_app\development.ini Traceback (most recent call last): File "C:\Program Files (x86)\JetBrains\PyCharm 2016.3.2\helpers\pycharm\pycharm_load_entry_point.py", line 12, in sys.exit(f()) File "C:\Users\imonat\blueyellowpy\lib\site-packages\pyramid\scripts\pserve.py", line 40, in main return command.run() File "C:\Users\imonat\blueyellowpy\lib\site-packages\pyramid\scripts\pserve.py", line 222, in run app_spec, name=app_name, relative_to=base, global_conf=vars) File "C:\Users\imonat\blueyellowpy\lib\site-packages\paste\deploy\loadwsgi.py", line 247, in loadapp return loadobj(APP, uri, name=name, **kw) File "C:\Users\imonat\blueyellowpy\lib\site-packages\paste\deploy\loadwsgi.py", line 271, in loadobj global_conf=global_conf) File "C:\Users\imonat\blueyellowpy\lib\site-packages\paste\deploy\loadwsgi.py", line 296, in loadcontext global_conf=global_conf) File "C:\Users\imonat\blueyellowpy\lib\site-packages\paste\deploy\loadwsgi.py", line 320, in _loadconfig return loader.get_context(object_type, name, global_conf) File "C:\Users\imonat\blueyellowpy\lib\site-packages\paste\deploy\loadwsgi.py", line 454, in get_context section) File "C:\Users\imonat\blueyellowpy\lib\site-packages\paste\deploy\loadwsgi.py", line 476, in _context_from_use object_type, name=use, global_conf=global_conf) File "C:\Users\imonat\blueyellowpy\lib\site-packages\paste\deploy\loadwsgi.py", line 406, in get_context global_conf=global_conf) File "C:\Users\imonat\blueyellowpy\lib\site-packages\paste\deploy\loadwsgi.py", line 296, in loadcontext global_conf=global_conf) File "C:\Users\imonat\blueyellowpy\lib\site-packages\paste\deploy\loadwsgi.py", line 328, in _loadegg return loader.get_context(object_type, name, global_conf) File "C:\Users\imonat\blueyellowpy\lib\site-packages\paste\deploy\loadwsgi.py", line 620, in get_context object_type, name=name) File "C:\Users\imonat\blueyellowpy\lib\site-packages\paste\deploy\loadwsgi.py", line 640, in find_egg_entry_point pkg_resources.require(self.spec) File "C:\Users\imonat\blueyellowpy\lib\site-packages\setuptools-18.1-py3.5.egg\pkg_resources__init__.py", line 952, in require File "C:\Users\imonat\blueyellowpy\lib\site-packages\setuptools-18.1-py3.5.egg\pkg_resources__init__.py", line 839, in resolve pkg_resources.DistributionNotFound: The 'blue-yellow-app' distribution was not found and is required by the application

Process finished with exit code 1

stevepiercy commented 7 years ago

This sounds like you did not run the setup.py task to install the app. You can do this by either:

  1. In the project browser, select the parent directory of development.ini, and select Run setup.py task..., and enter develop.
  2. In a terminal session, navigate to the directory in which development.ini is contained, and enter python setup.py develop. In the latest version of PyCharm, the terminal session activates the virtual environment automatically, so it should find your Python. If not, then you can run the same command as /path/to/my/python setup.py develop.
ianmonat commented 7 years ago

Hi Steve, I figured out what I was doing wrong and got the file from the Designable Web lesson (aka the Cache busting lesson) to run as expected. I see what I was doing wrong now, thanks so much for the help.