Windows 不生成 Python 编译文件
我目前正在 Windows 7 环境中开发 Pyramid Web 应用程序。我一直在我的 Mac 上开发这个应用程序,但它最近死了,所以我不得不转移到我的 Windows 机器上。
我已经设置了我需要的一切; Python 2.7、Pyramid、pyramid_beaker、MongoDB、mongoengine 等。
在我编辑模板时它似乎正在工作。但是,当我尝试编辑视图以向应用程序添加新页面时,它似乎无法找到它。我添加了以下路由:
config.add_route('info_about','/info/about')
config.add_route('info_contact','/info/contact')
config.add_route('info_copyright','/info/copyright')
config.add_route('info_privacy','/info/privacy')
config.add_route('info_terms','/info/terms')
...由 view_config 装饰器处理,如下所示:
@view_config(route_name='info_about', renderer="myproject:templates/info/about.mako", permission='all')
def info_about(request):
<code goes here>
这是在视图子文件夹中的 info.py
文件中(其中包含 __init__.py< /代码> 文件)。当我在 Mac 上时,这个方法是有效的,但现在我在 Windows 上尝试过,它似乎不起作用(当尝试访问它时,它会抛出 404 Not Found 页面)。
经过一番调查,我发现 info.py
的 .pyc
版本(编译版本)不存在。 info.py
是新的,已添加到 Windows 计算机上。作为测试,我尝试编辑在 Mac 上创建的文件并重新启动测试服务器。它也没有修改 .pyc
对应部分,因此我假设 Windows 没有生成 .pyc
版本的 python 文件。
这是一个常见问题吗?更重要的是,有解决方案吗? (我必须假设有......)
I'm currently on a Windows 7 environment developing a Pyramid web application. I had been developing this app on my Mac, but that's recently died, so I've had to move to my Windows machine.
I've set up everything I need; Python 2.7, Pyramid, pyramid_beaker, MongoDB, mongoengine, etc.
It seemed to be working while I was editing the templates. However, when I tried editing a view to add a new page to the app, it would not seem to be able to find it. I added the following routes:
config.add_route('info_about','/info/about')
config.add_route('info_contact','/info/contact')
config.add_route('info_copyright','/info/copyright')
config.add_route('info_privacy','/info/privacy')
config.add_route('info_terms','/info/terms')
...which are handled by a view_config decorator like so:
@view_config(route_name='info_about', renderer="myproject:templates/info/about.mako", permission='all')
def info_about(request):
<code goes here>
This is in an info.py
file in the view subfolder (which does contain an __init__.py
file). This method has worked when I was on my Mac, but now that I've tried on Windows, it doesn't seem to work (it throws a 404 Not Found page up when trying to access it).
After a little investigating, I found that the .pyc
version of info.py
(the compiled version) does not exist. info.py
is new and was added on the Windows machine. As a test, I tried editing a file created on the Mac and restarting the test server. It hasn't modified the .pyc
counterpart either, so I'm led to assume that Windows is not producing the .pyc
version of the python files.
Is this a common problem, and more importantly, is there a solution? (I have to assume there is...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,您的问题不够清楚。看来您有某种读/写权限问题,生成 *.pyc 与此无关。
*.pyc 包含 Python 字节码,实际上它只是为了更快地加载原始 *.py 文件。每次 Python 成功读取 *.py 文件并能够写入(!)到同一目录时,它都会创建一个相应的 *.pyc 文件。
有关详细信息,请参阅已编译的 python 文件。
Sorry, your question is not clear enough. It seems you have some kind of read/write permission problems, and generating *.pyc has nothing to do with it.
*.pyc contains Python bytecode, in fact it is there just to load the original *.py files faster. Every time Python successfully reads a *.py file and is able to write(!) into the same directory, it creates a corresponding *.pyc file.
For more information see compiled python files.