中英对照,卓忆整理简单翻译及验证:在Macos安装Odoo及配置odoo开发环境

中英对照,卓忆整理简单翻译及验证:在Macos安装Odoo及配置odoo开发环境

测试环境:MacOS10.11

原文地址:

http://bloopark.de/blog/the-bloopark-times-1/post/setup-odoo-development-on-os-x-with-pycharm-109

Odoo官方安装文档参考:https://www.odoo.com/documentation/9.0/setup/install.html#source-install

10.0的 https://www.odoo.com/documentation/10.0/setup/install.html#source-install

Do you want to start with developing on your Mac or you already used tools like vagrant or docker and this is too slow for you? I show you how to run odoo locally without using virtualisation and how you configure PyCharm to be able to start the integrated debugger.

In this blogpost we use the Python and PostgreSQL packages from Homebrew. We create a virtual environment for Python and install the necessary packages with pip. At the end we configure PyCharm to use the created virtual environment.

As I told you we use Homebrew. It is titled as “The missing package manager for OS X”. With Homebrew we can install packages in the console as we can in the most Linux distributions. To install you have to run this command in your console (Terminal) and follow the instructions (without #):

这个教程让我们不用通过虚拟机来配置Odoo的开发环境,

在这里我们使用Homebrew中的Python和PostgreSQL,

我们为Python创建一个虚拟环境并通过pip安装需要的安装包。

最后我们会配置PyCharm。

一:安装Homebrew

通过Homebrew我们可以像在linux中那样在终端中安装 安装包。

在MacOS的终端(Terminal)中键入以下命令(注意不包含#)

1
 # ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

After this we can install Python. If you already did this with a downloaded installer you can skip installing Python with Homebrew but I cannot guarantee for that. If you have problems then uninstall Python and try the package from Homebrew. To install run and follow the instructions:

二:安装Python

通过以上命令我们可以安装Python。如果您已经通过下载安装了Python您可以跳过在Homebrew中安装Python,不过我不能保证这是可行的。(我在第一次测试时,没卸载系统自带的python,能用,就是pycharm中在 Project Interpreter,路径和教程中不一样)

如果您遇到问题,您可以卸载Python(macos 11中python应该是无法卸载的)然后试着在 Homebrew中安装它。  (brew update如果更新失败,参考:https://www.logcg.com/archives/1617.html)

1
 # brew update # brew install python

Now we have installed Python. Next we need the PostgreSQL server. Here we can also use Homebrew:

三:然后我们在Homebrew中安装PostgreSQL:

1
 # brew install postgresql

To start the PostgreSQL right now and automatically at system startup we run:

想让PostgreSQL在系统启动时自动启动我们运行:

1
 

To have launchd start postgresql now and restart at login:

# brew services start postgresql

Or, if you don't want/need a background service you can just run:

#  pg_ctl -D /usr/local/var/postgres start

Before we install the Python modules we need to install some dependencies for the Pillow module:

四:安装Pillow所需的依赖

在我们安装Python模块前我们需要为Pillow模块安装一些依赖:

1
brew install freetype jpeg libpng libtiff webp xz

Next we can decide how to install the Python dependencies for odoo. One way is to install these globally. If you developing on other Python applications you sometimes need the same Python packages but in different versions. Or you want to let the system clear and remove these easy when you do not need them anymore. To get these advantages we can create a virtual environment for Python. This virtual environment copies Python and some other files (like pip) to a specified directory (e.g. in your home path) and provides a script which rewrites the path to use the Python from this directory.

To install the Python dependencies we use pip which is package manager for Python (like Homebrew but for Python modules) and is already installed with Python. For creating the virtual environment we have to install virtualenv. Homebrew does not contain virtualenv so we install it with pip (globally):

五:安装virtualenv (这个是可选 安装,不装也能启动)

虚拟环境是独立的Python 工作空间。对开发者而言非常有用,可以在不同的 虚拟环境中使用

不用版本的 Python 库。

您可以使用 virtualent path/to/newenv 命令 按需创建 多个 环境 。

这会创建 newenv 目录 到指定的 路径,包含 bin/ 和 lib/python2.7/ 这些子目录

我们使用pip这个Python包管理器来安装Odoo所需的Python依赖,

pip会随着之前的Python一同被安装。

为了创建虚拟环境,我们需要安装virtualenv。Homebrew 不包含virtualenv,

所以我们通过pip来安装它:

1
 #sudo pip install virtualenv

Now we can create the virtual environment. We use for this the directory odoo-env in our home directory:

现在我们可以创建一个虚拟环境了,这里我们使用odoo-env这个目录

1
2
3
4
 # virtualenv ~/odoo-env

这会在 当前 目录 创建 odoo-env 目录,这个目录内 包含了<span style="font-weight: 400;">bin/ 和 lib/python2.7/ 这些子目录</span>
通过上面的命令所有需要的文件被复制到这个目录中。

With this command all necessary files were copied to this directory. Next we enter the created virtual environment:

1
2
3
 # . ~/odoo-env/bin/activate

上面这条命令在10.11中 会报错。 使用
1
 source ~/odoo-env/bin/activate

Okay, all looking the same as before? :) We can look if we are in this virtual environment:

我们 可以 看看 ,是否 我们 在 虚拟环境中:

 # which python

/Users/youruser/odoo-env/bin/python

As you can see the Python binary from this directory is used. If you want to leave this environment you can type deactivate or close the terminal. Be aware that if you open a new tab or reopen the terminal you are not in the environment. Here you have to run the activate script as before.

如果您想离开这个环境,您可以输入 deactivate 或者 关闭终端。要知道如果您打开一个新的 标签 或者 重新 打开终端,您 并 不在 这个环境中。您需要 像之前 那样 运行 激活的脚本。

Now we can start installing all dependencies for odoo. Download odoo if you did not have (e.g. clone the git repository) . In the newer odoo versions there is a requirements.txt file which contains all dependencies. To install these you have to change to the odoo directory (with cd) and run (you have to be in your virtual environment):

六:下载Odoo并安装Odoo所需的依赖

接下来下载Odoo(比如通过 git clone),

1
git clone https://github.com/odoo/odoo.git -b 10.0 --depth=1

在苹果下用git clone有时会遇到文件过大缓存不足的问题。

我是用scp直接到自己服务器拉了个下来,

然后进入Odoo目录安装Odoo所需的Python依赖:

# sudo easy_install pip

 # pip install -r requirements.txt 

This takes some time. If you get these as last lines you can be happy:

天朝目前访问国外网络的关系,这步也比较耗时,有时放很久也没动静。

 Successfully installed [...] Cleaning up...

Odoo9开始,还需要安装nodejs:

1
# brew install node

on OS X, install nodejs via your preferred package manager (homebrewmacports) then install less and less-plugin-clean-css:

  • 然后安装 less和  less-plugin-clean-css
    1
    
    $ sudo npm install -g less less-plugin-clean-css

You have installed all dependencies. Now you can start odoo if you want:

七:运行Odoo

通过python ./odoo.py 运行odoo看到下面的窗口,

1
2
# python ./odoo.py
注意: 10.0取消了odoo.py  用 python odoo-bin 启动

2014-12-16 09:52:28,172 2974 INFO ? openerp: OpenERP version 8.0

2014-12-16 09:52:28,172 2974 INFO ? openerp: addons paths: ['/Users/youruser/Library/Application Support/Odoo/addons/8.0', u'/Users/youruser/odoo/openerp-v8/openerp/addons', u'/Users/youruser/odoo/openerp-v8/addons']

2014-12-16 09:52:28,172 2974 INFO ? openerp: database hostname: localhost

2014-12-16 09:52:28,172 2974 INFO ? openerp: database port: 5432

2014-12-16 09:52:28,172 2974 INFO ? openerp: database user: youruser

2014-12-16 09:52:28,328 2974 INFO ? openerp.service.server: HTTP service (werkzeug) running on 0.0.0.0:8069 2014-12-16 09:53:32,095 2974 INFO ? openerp.addons.bus.bus: Bus.loop listen imbus on db postgres …

Then you can open your browser and open http://localhost:8069.

Here you can create a new database with or without demo data and playing/developing with odoo. If you done you can stop with CTRL+C in your console.

您就可以在chrome,firefox或者safari浏览器访问 http://localhost:8069.打开odoo了,

您可以在终端中用Ctrl+C来终止这个Odoo (好像用 Ctrl + Z 更好)。

第二部分配置Pycharm开发环境(仅供参考)

CONFIGURING PYCHARM

For Python developing I am using the Python IDE PyCharm from JetBrains. You can download the community version which should be sufficient for our needs. After installing and starting open the odoo directory as project.

访问PyCharm下载PYCHARM 社区版

As first we have to set the Python interpreter for our project. In the menu open PyCharm and then Preferences. Left in the sidebar open your project and select Project Interpreter. Next to the drop down field click on the gear and select Add Local. In the dialog search the folder odoo-env in your home directory which we created before. In the subdirectory bin select the python2.7 binary and click Choose (or use double click).

首先我们为我们的项目设置Python解释器。

运行PyCharm打开您的项目

在Preferences中 选择 您的项目然后选择 Project Interpreter,

接下来 选择 Python的环境

If you have more than one odoo projects you can select the added virtualenv in the drop down field. You can close this dialog with OK. Now we have set the interpreter. PyCharm will browse the virtual environment and looking for the Python modules in the background. With this you have no errors in the Python files about missing Python modules.

如果您有多个Odoo项目,您可以增加 virtualenv 。现在我们设置了编译。

PyCharm会在后台浏览虚拟环境及寻找Python模块。

To run or debug odoo from PyCharm we create a new run configuration (for each project). In the menu select Run and then Edit Configurations. Click on the +-Icon and select Python. This adds a new entry. Name your configuration as you like and select Single instance only. Running more than one times is not possible because only one application can use the same port at the same time. In Script use the ...-Button and look for your project directory. Here select the odoo.py. In Python interpreter you have to select the interpreter from the virtual environment we created before. The other fields are untouched. You can change these if you want.

If you have more than one project you have to add a new configuration for each. After creating all configuration you can click OK.

我们为每个新项目创建一个新的配置文件。

在菜单中选择Run 然后 选择 Edit Configurations编辑配置 文件。

点击 +—图标并选择 Python。

如果我们有多个项目,我们必须为每个项目创建配置文件。

现在我们就可以 通过 右上角绿色的 play按钮来运行odoo了。

也可以用边上的 debugger按钮。

在这之前确保我们 终端 没有运行其他 odoo。

Now we can run odoo with the green play button in the top right (select the right configuration for your project). You can also run the debugger with the second button. Please be aware that you have to stop the running odoo from your console (with CTRL+C) if you did not stopped yet.

This is all. Now you can develop with odoo in PyCharm without any virtualisation or something else. If you have any questions please use the comment section below.

支付宝扫一扫赞助

微信钱包扫描赞助