Windows下 如何用PyCharm运行调试 Odoo 8.0
-
作为新手,能够单步执行调试源代码是个很好的学习过程。 花了一天时间,终于成功用PyCharm运行最新的Odoo 8.0 版本。
***** 新手犯了一个低级的错误,发现[b]Odoo在Windows下不能正常运行[/b]。 建议大家不要尝试了。 留这个帖子引以为戒。 **********
原文在 [检测到链接无效,已移除]
Debug Odoo using PyCharm in Windows
08 Sep 2014
This blog describes how to setup PyCharm to run/debug Odoo in Windows environment. I use PyCharm Professional 3.4 in 64-bit Windows 8 to run/debug Odoo 8.0 branch. This blog has three parts. The first part describes how to install required packages. The second part shows how to configure PostgreSQL and Odoo. The third part gives problems and their solutions during my installation process.
I. Install packages and source code
1. Get Odoo source code and change branch to 8.0
git clone https://github.com/odoo/odoo.git br />git checkout 8.0
2. Install Visual Studio if you don't have one.
The free Visual Studio Express is enough to compile and install Python packages in later steps. To avoid "error: Unable to find vcvarsall.bat", I need to set the following environment variable in "cmd" command line:
If you have Visual Studio 2013 installed (Visual Studio Version 12), execute SET VS90COMNTOOLS=%VS120COMNTOOLS%.
For Visual Studio 2012 (Visual Studio Version 11), execute SET VS90COMNTOOLS=%VS110COMNTOOLS%.
For Visual Studio 2010, execute SET VS90COMNTOOLS=%VS100COMNTOOLS%.
3. Install required packages from a binary source
With 64-bit Python 2.7.8 installed, I had some compiling errors in installing some required packages for Odoo. Tired of fixing them, I just installed the following pre-compiled Windows 64-bit binary packages from http://www.lfd.uci.edu/~gohlke/pythonlibs br />
Pillow
lxml
psycopg2
python-ldap
pywin32
There are installable windows files for them. Carefully select each file that matches your 32-bit/64-bit and Python version, download and execute the file to install it.
4. Create a virtual environment
This is optional but it's a good idea to use a virtual environment.
In PyCharm, open the odoo folder to create a new project.
Then in File --> Setting --> Project Setting (top left panel) --> Project Interpreter, click the tool icon on the top right, then select "Create Virtual Environment". In the dialog, give the new environment a name such as "odoo8", remember the location, choose base interpreter, click both check-boxes (Inherit global site-packages, Make available to all projects). Finally click OK to create it.
You should see some packages such as pip, psycopg2, python-ldap, pywin32 and setuptools. It is a good idea to upgrade pip and setuptools.
Select pip, then the up-arrow icon on the right side to upgrade it. Do the same to upgrade setuptools.
5. Copy and edit requirments.txt
Copy requirements.txt from the root of Odoo source repository to the location of your virtual environment. With the above configuration, it isC:\Users\your-username\odoo8". Edit the file to remove the following lines<br /><br />Pillow==2.5.1<br /><br />lxml==3.3.5<br /><br />psycopg2==2.5.3<br /><br />python-ldap==2.4.15<br />6. Batch install packages from requirments.txt<br />In the "cmd" window that has the correct setting of VS90COMNTOOLS, go to the location of your virtual environment. By default, it is
C:\Users\username\odoo8". execute
.\Scripts\activate.bat
pip -r requirements.txt
The above commands activate the virtual environment and install all required packages for Odoo. Please pay attention to the output of any error message. The output is also stored in a pip log file C:\Users\your-username\pip\pip.log. You can ignore warning messages. pip stops when there is an error.
Restart your PyCharm and you should see all packages in the newly created environment. Make this environment the interpreter of your Odoo project. You are able to run openerp-server.py file.
However, you still need to install Postgresql and configure the Odoo to work with it.
II. Install PostgreSQL and configure Odoo
1. Download and install PostgreSQL for Windows.
2. Create a new role with superuser privilege for Odoo application.
In my case, I create a superuser "odoo" and set its password as "odoo".
3. Check PostgreSQL configuration
You do not need to change anything because default configuration works correctly as a local database. However, if there is any errors, you can check the the two configuration files of PostgreSQL . Both can be edited using Tools --> Server Configuration menu in pgAdmin.
In postgresql.conf, make sure that listen_addresses are enabled. It is checked by default.
In pg_hba.conf, enable the "host all all 127.0.0.1/32 md5". It means localhost can be connected with a role name and password. It is checked by default.
4. Config Odoo
In Odoo project root, copy debian/openerp-server.conf to another folder. In my case, it is D:\Dev\odooTest\openerp-server.conf , edit the file to have the following configurations:
[options]
; This is the password that allows database operations:
; admin_passwd = admin
db_host = localhost
db_port = 5432
db_user = odoo
db_password = odoo
addons_path = D:\Dev\PyCharmProjects\odoo\addons
In the addons_path option, set it to the addons directory in your Odoo project root.
Then in PyCharm menu Run --> Edit Configurations, click "+" on the top left to create a new configuration with the following settings:
Name: Odoo8 Single instance checkbox: checked Script: D:\Dev\PyCharmProjects\odoo\openerp-server Script parameters: --config=D:\Dev\odooTest\openerp-server.conf
Congratulations, you should be able to run and debug Odoo !!!
III. Issues and solutions
When install packages from requirements.txt, there is an message "error: Unable to find vcvarsall.bat". Setting VS90COMNTOOLS to correct Visual Studio path fixed it.
Packages such as lxml, psycopg2, python-ldap had many compile errors. The solution is downloading and installing binary packages from [检测到链接无效,已移除] br />
The Pillow package did work correctly because of an error of 'decoder zip not available'. Again, installing binary package fixed it.
You may need to drop the newly created database if something is wrong when you run Odoo to create the initial database. There might be some garbage left in the database and you see an error message like "QWebTemplateNotFound: External ID not found in the system: web.login" -
英文很头疼呀。。。
-
请看另一片文章。。还有带有pdf,如果是绿色版 配置文件 复制到 source目录,并且修改addons的路径接
Pycharm 联合调试OpenERP服务端和客户端
--------------------------------------------------
原创
1.绿色版如果用来开发。不要安装服务,就是不要点击service_install ,否则停止python-oe.exe也会马上自动运行了
2. 把openerp-server.conf 复制到source,并修改 openerp-server.conf中的addons路径
3 python版本的对应
view->tool
在工具栏中找到这个类似扳手加齿轮的图标
如何在pycharm中切换python版本显示工具栏
找到左侧 project interpreter选项
4 修改程序。需要重启odoo..如果进程有多个python-oe.exe 去取消了
--------------------------------------------------
<br / [检测到链接无效,已移除] br />« 于: 十二月 10, 2013, 03:23:21 下午 »
使用Pycharm开发调试OpenERP(服务端Python和客户端Javascript 联合调试)----这里是文字,完整在附件
个人认为Pycharm是最好的Python开发工具,配置简单,操作简便,界面清爽,支持远程调试python,javascript调试,集成JDango等web框架,跨平台。功能非常强大。鉴于社区主要推荐的是Eclipse IDE,Eclipse本身是很好,万金油IDE,通过Pydev插件支持Python也不错,另外也有针对OpenERP的模版发布,利于快速开发模块。但对Python初学者来说配置工作比较多,Python本身要安装各种插件,即使以前用eclipse开发过java的人,同样不利于快速上手,因此,向python、或OpenERP初学者推荐Pycharm。
本文分三个部分:1、安装开发环境:Python,Pycharm,OpenERP的Python依赖包。2、配置Pycharm,调试OpenERP服务端Python代码。3、调试OpenERP客户端Javascript代码。
一、 安装开发环境:
1、 下载安装必须软件:
对Python不熟悉的同学,建议安装Python(x,y),600兆,这个第三方发布的Python包集成了很多Python常用社区模块。OpenERP需要十几个Python社区模块。
下载Pycharm,下载专业版,专业版支持javascript调试,试用期过后,其实还是可以使用的。Pycharm是需要jre支持的,如果没有,则需要安装jre。
下载OpenERP代码,解压到硬盘中,注意路径中不能有中文名文件夹。
下载OpenERP数据库,Postgres。安装时,记下数据库管理员用户名和密码。
2、 配置Pycharm和OpenERP:
打开Pycharm,导入OpenERP工程:
选择下载的OpenERP代码目录:
这就完成了OpenERP工程的导入。
展开工程文件,从doc目录下拷贝 conf文件到根目录下:
点击根目录下的conf文件,进行配置:
注意db_user 和db_password是前面安装postgreSQL时的数据库用户名和密码。配置好后,选择工程根目录下的”opener-server”文件,右键点击,弹开菜单,Run。
此时,运行结果,会报很多错误,关注最下面的错误,这些错误大多是模块未安装的错误,并提示缺少什么模块,OpenERP需要的模块列表在工程下目录openerp.egg-info内的文件requires.txt里,如下图:
Python(x,y)已经有了很多插件,剩下大致有如下几个:
这些是Python插件包在window下使用的安装包,下载地址在:http://www.lfd.uci.edu/~gohlke/pythonlibs 。逐个下载安装。
全部安装完后,如还缺少,根据报错信息,找到确认模块名,打开cmd命令行窗口,运行 “pip install 模块名” 安装,模块名有时候与requires.txt文件里的不完全一致,需要到pip官网查询确认https://pypi.python.org/pypi 。
如还是解决不了,到论坛或群里发帖吧。
二、 调试OpenERP服务端python代码:
调试Python服务端代码,只需要在前面运行那里,选择debug即可,注意不要同时开启run和debug,OpenERP是一份代码允许同时运行多个实例的,因此不会提示是否以运行。如下图,只有一个debug窗口。多个运行就会有多个窗口。
服务端代码调试,打开openerp-server文件,打上断点,即可跟踪OpenERP的启动过程:
服务启动流程大致如下:
模块启动完成后,OpenERP服务会开始监听8069端口的http请求,此时代码运行起始在services目录下,wsgi.py文件内,如下断点。即可跟踪对请求的一系列处理。
请求处理流程大致如下:
代码多跟踪几遍,就能掌握。
三、 调试OpenERP客户端javascript代码:
在Pycharm里选择配置:
在弹出窗口内,点击 + 号,添加Javascript Debug配置:
按如下配置,注意URL中的写法http://127.0.0.1:8069/?debug= 。
Debug参数让OpenERP服务输出的是原始js文件。
保存返回主界面,如果此时OpenERP还没启动服务,则先运行operp-server,随便是run或debug。 然后再选择js debug,点击debug按钮:
此时pycharm 会提示你安装 chrome插件,点击安装。安装完毕后,关掉chrome,再次点击debug运行,此时chrome就会连接上pycharm
注意,此时Pycharm开启了两个调试进程,分别是python和javascript:
可以联调js和python了。
选择js debug下的 Scripts tab栏,点击展开http://127.0.0.1:8069目录,选择需要调试的js文件。
比如选择web/static/src/js 目录下的boot.js文件,这个是OpenERP客户端javascript框架的启动文件,断点打在init方法内:
在chrome内登录后,会跳到这个断点,注意调试堆栈和 变量窗口:
如果此时Python代码的运行也是debug模式的话,那么就能够实现客户端和服务端联合调试了。
希望此文能给OpenERP初学者一些帮助。
* 使用Pycharm开发调试OpenERP.pdf (821.69 kB - 已被下载 1038 次.)