Create dev environment and install trytond dependencies

Hello all, I have experimented successfully with Tryton using the Docker install, and now I am trying to create a working dev environment for trytond on a current Linux Mint (Ubuntu-based) laptop by piecing together the various recent install-related forum topic posts and comments[1].

It seems I don’t have trytond dependencies installed correctly because I’m getting “module not found” errors attempting to execute tryton-env/tryton/trytond/bin/trytond.

I tried installing trytond dependencies several ways, using pip install, executing trytond/setup.py, using trytond/requirements.txt, and even continuously executing trytond and manually installing the module reported missing each time, but each method eventually arrived at an uncorrectable error, so I presume I’m missing something.

What am I doing wrong? How should trytond dependencies be installed?

Many thanks,
Dale

[1] References

Create virtual environment for developing

$ mkdir -p ~/Source/tryton-dev
$ cd ~/Source/tryton-dev
$ python3 -m venv .
$ source bin/activate

Clone Tryton project repo

(tryton-dev) ~/Source/tryton-dev$ hg clone https://hg.tryton.org/tryton-env

Update tryton-env/.hg/hgrc

(tryton-dev) ~/Source/tryton-dev$ vi trytond-env/.hg/hgrc

and add:

[hooks]
update.modules = .hooks/link_modules
update.requirements = .hooks/update_requirements

Generate requirements.txt and requirements-dev.txt

(tryton-dev) ~/Source/tryton-dev$ cd tryton-env
(tryton-dev) ~/Source/tryton-dev/tryton-env$ hg update

Install trytond dependencies

  • Option 1 - “pip install” and list all dependencies on pip install command line
  • Option 2 - “pip install -r” [requirements.txt | requirements-dev.txt]
  • Option 3 - “trytond/setup.py [install | develop]”

Run trytond

Run Tryton client and connect to trytond

Download tryton tarball from sources from tryton org website. Run setup.py. Run Tryton client using the bin/tryton script (…/unpacked/tryton-6.08/bin/tryton).

1 Like

If hooks is working, you should have two files requirements.txt and requirements-dev.txt.
In your virtualenv, you have to install dependencies with this command:

pip3 install -r requirements.txt

or

pip3 install -r requirements-dev.txt

Thank you @maxx for your help.

IIUC I should use requirements-dev.txt because my goal is to create a new module. Please advise if this is not correct.

Running install with requirements-dev.txt was unsuccessful due to “Error: pg_config executable not found.”

(tryton-dev) ~/Source/tryton-dev$ cd tryton-env
(tryton-dev) ~/Source/tryton-dev/tryton-env$ pip3 install -r requirements-dev.txt
...
Collecting psycopg2
  Downloading psycopg2-2.9.1.tar.gz (379 kB)
     |████████████████████████████████| 379 kB 7.2 MB/s 
    ERROR: Command errored out with exit status 1:
     command: /home/dale/Source/tryton-dev/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-rxg86nt2/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-rxg86nt2/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-rxg86nt2/psycopg2/pip-egg-info
         cwd: /tmp/pip-install-rxg86nt2/psycopg2/
    Complete output (23 lines):
    running egg_info
    creating /tmp/pip-install-rxg86nt2/psycopg2/pip-egg-info/psycopg2.egg-info
    writing /tmp/pip-install-rxg86nt2/psycopg2/pip-egg-info/psycopg2.egg-info/PKG-INFO
    writing dependency_links to /tmp/pip-install-rxg86nt2/psycopg2/pip-egg-info/psycopg2.egg-info/dependency_links.txt
    writing top-level names to /tmp/pip-install-rxg86nt2/psycopg2/pip-egg-info/psycopg2.egg-info/top_level.txt
    writing manifest file '/tmp/pip-install-rxg86nt2/psycopg2/pip-egg-info/psycopg2.egg-info/SOURCES.txt'
    
    Error: pg_config executable not found.
    
    pg_config is required to build psycopg2 from source.  Please add the directory
    containing pg_config to the $PATH or specify the full executable path with the
    option:
    
        python setup.py build_ext --pg-config /path/to/pg_config build ...
    
    or with the pg_config option in 'setup.cfg'.
    
    If you prefer to avoid building psycopg2 from source, please install the PyPI
    'psycopg2-binary' package instead.
    
    For further information please check the 'doc/src/install.rst' file (also at
    <https://www.psycopg.org/docs/install.html>).
    
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
(tryton-dev) ~/Source/tryton-dev/tryton-env$ 

iiuc this is a well-understood issue because it seems installing psycopg2 is not simple, also iiuc, installing psycopg2-binary will avoid having to learn how to build psycopg2 from source, so I installed psycopg2-binary, and will then try setup again after.

(tryton-dev) ~/Source/tryton-dev/tryton-env$ pip install psycopg2-binary
Collecting psycopg2-binary
  Using cached psycopg2_binary-2.9.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.4 MB)
Installing collected packages: psycopg2-binary
Successfully installed psycopg2-binary-2.9.1
(tryton-dev) ~/Source/tryton-dev/tryton-env$ ls

However, running pip install -r requirements-dev.txt a 2nd time is again not successful, and again related to psycopg2 (below).

Am I installing psycopg2 incorrectly? Are my assumptions wrong?

Thanks,
Dale

(tryton-dev) ~/Source/tryton-dev/tryton-env$ pip install -r requirements-dev.txt
Collecting GooCalendar
  Using cached GooCalendar-0.7.2-py3-none-any.whl (22 kB)
Collecting bcrypt
  Using cached bcrypt-3.2.0-cp36-abi3-manylinux2010_x86_64.whl (63 kB)
Collecting forex-python
  Using cached forex_python-1.6-py3-none-any.whl (8.1 kB)
Collecting gevent
  Using cached gevent-21.8.0-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (6.5 MB)
Collecting html2text
  Using cached html2text-2020.1.16-py3-none-any.whl (32 kB)
Collecting passlib[argon2]
  Using cached passlib-1.7.4-py2.py3-none-any.whl (525 kB)
Collecting phonenumbers
  Using cached phonenumbers-8.12.35-py2.py3-none-any.whl (2.6 MB)
Collecting pillow
  Using cached Pillow-8.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB)
Collecting psycopg2
  Using cached psycopg2-2.9.1.tar.gz (379 kB)
    ERROR: Command errored out with exit status 1:
     command: /home/dale/Source/tryton-dev/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ghcku81u/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ghcku81u/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-ghcku81u/psycopg2/pip-egg-info
         cwd: /tmp/pip-install-ghcku81u/psycopg2/
    Complete output (23 lines):
    running egg_info
    creating /tmp/pip-install-ghcku81u/psycopg2/pip-egg-info/psycopg2.egg-info
    writing /tmp/pip-install-ghcku81u/psycopg2/pip-egg-info/psycopg2.egg-info/PKG-INFO
    writing dependency_links to /tmp/pip-install-ghcku81u/psycopg2/pip-egg-info/psycopg2.egg-info/dependency_links.txt
    writing top-level names to /tmp/pip-install-ghcku81u/psycopg2/pip-egg-info/psycopg2.egg-info/top_level.txt
    writing manifest file '/tmp/pip-install-ghcku81u/psycopg2/pip-egg-info/psycopg2.egg-info/SOURCES.txt'
    
    Error: pg_config executable not found.
    
    pg_config is required to build psycopg2 from source.  Please add the directory
    containing pg_config to the $PATH or specify the full executable path with the
    option:
    
        python setup.py build_ext --pg-config /path/to/pg_config build ...
    
    or with the pg_config option in 'setup.cfg'.
    
    If you prefer to avoid building psycopg2 from source, please install the PyPI
    'psycopg2-binary' package instead.
    
    For further information please check the 'doc/src/install.rst' file (also at
    <https://www.psycopg.org/docs/install.html>).
    
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
(tryton-dev) ~/Source/tryton-dev/tryton-env$ pip install psycopg2-binary
Requirement already satisfied: psycopg2-binary in /home/dale/Source/tryton-dev/lib/python3.8/site-packages (2.9.1)
(tryton-dev) ~/Source/tryton-dev/tryton-env$

Unfortunately psycopg2 has decided to make two packages for psycopg2 one for the source only and another with pre-compiled libraries. The problem is that with setuptools it does not seem to be possible to define as dependency “one of a list of packages”. So we have to choose one and we choose psycopg2 because it is the recommended for production.
So if you want to be able to just install the dev requirements you will need to fix the building of psycopg2. This seems that you are missing the header of postgresql headers (this probably can be installed by your distribution package manager, you need only the client parts).

Now you must also know that the requirements-dev.txt define only the addition optional dependencies. You do not absolutely need them to run or develop on Tryton (only if you want to be sure to have all the features of all the modules).
Also you can install manually the dependencies that you find to need and for example installing psycopg2-binary will be enough for trytond to use the postgresql backend. This is because at run time there is no differences between the two psycopg2 packages.

If you are on Debian you can

# apt install libpq-dev

which contains the headers and the missing pg_config binary.

See Debian -- Details of package libpq-dev in bullseye

Edit: for Mint: Linux Mint - Community

1 Like

Hi Dale, if your goal is to create a new module, the steps can be different. tryton-env is only necessary if you want to contribute/develop on the Tryton source itself.

To develop a new module, you could for example use the cookie-cutter Tryton module template:

On Linux, you can do it like this:

mkdir my_module
cd my_module
python3 -m venv venv --prompt my_module # this creates a python virtualenv under the directory 'venv'
source venv/bin/activate # activates the virtualenv for the current terminal session
pip install cookiecutter
cookiecutter hg+https://hg.tryton.org/cookiecutter

cookiecutter will ask for details about your module. Name, description, etc. Set the version to 6.0.0 to develop from the latest stable version of Tryton. The command will create another folder, which comes with all the files you need to start creating your module. You can keep the files in that folder, or move everything to the first folder you created mv my_module/* my_module/.* .; rmdir my_module. I did it like this so that you install cookiecutter in the virtualenv.

Then you can install the module in development mode python my_module/setup.py develop. This will install all the tryton dependencies in your virtual env. It also detects other trytond_module that you declared in the tryton.cfg file. If you have your own dependencies, you need to add them to setup.py. For your own dev dependencies, like linting, for example, you can list them on a requirements-dev.txt — which you’ll need to install with pip install -r requirements-dev.txt.

There is also this guide for creating a new module, which is different for developing on tryton. The guide goes beyond creating the dev env and installing dependencies. How to setup environment to create a new module - #11 by mwl

It is probably better now to use pip install --editable my_module (see Python 3.9 breaks module import (#10513) · Issues · Tryton / Tryton · GitLab).

1 Like

Thank you very much for your help @maxx @ced @lars_wuerfel. It’s starting to make more sense now. I seem to have trytond running now from the Method Not Allowed error I’m seeing in Chrome when I access localhost:8000 (which is what I would expect since I expect sao is not running). However, accessing using the Tryton client (from tryton-latest.tar.gz) shows “Incompatible version” in the client. Is this normal because I don’t have a database yet?

@fmorato thank you for referencing the new module setup post. I will post a new topic when I get there. :wink:

It is normal because the latest release is older than the development series.
With the development server, you must use the development client.

Thus, if you’re using tryton-env, you might want to make sure that the codebase is on the version you want to use: hg update 6.0, which is the current latest.

@fmorato thanks for the help. I’m having trouble trying to create a consistent environment starting with cloning the dev repository, so if it’s not needed if I am developing a new module only with no tryton changes, then perhaps installing minimum Tryton modules from PYPI and then adding new module is the way to go. More questions later… :wink: