Setting enviroment with VSCODE

Hi, My name is Julio. I’m newie with tryton and a junior developer with python. So I need a little help to setting up my enviroment in vscode to debug.

I was trying create my launch.json file to run a debug mode, but not lucky with that.
My launch.json

      {    
    "version": "0.2.0",
    "configurations": [       
        {
            "name": "Run Server Tryton",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/trytond/bin/trytond",
            //"program": "${file}",
            "console": "integratedTerminal",
            "args": ["--config" ,"/work/tryton-workspace/tryton-env/trytond.conf",
                     "--logconf","/work/tryton-workspace/tryton-env/trytond_log.conf", 
                     "--dev"]
        }
    ]
}

The error was ‘trytond’ is a package and cannot be directly executed.

thanks in advance :upside_down_face:

Hi Julio,

Did you create a virtualenv ? trytond executable should be in the bin folder of your virtualenv path.

Another thing you could do is adding a pythonPath variable in your launch.json

“pythonPath”: “path_to_your_virtualenv/bin/python”

and “program” variable should be just “trytond”

Thanks for answer me.

Yes I have a virtual enviroment but adding that vscode shows me an error

Do you know why it not works for me?

I will answer myself :smiley:,

My var pythonPath was already configurated on my settings.json.

My share my settings.json
{
“python.pythonPath”: “/usr/bin/python3”,
“python.venvPath”: “/work/tryton-server/tryton-env/bin/activate”
}
And my launch.json remains equals, I only deleted python path from there.

Saddly I have this error because I try to execute bin/trytond, with which file I should starts my tryton server?

Blockquote
/usr/bin/python3: No module named trytond.main; ‘trytond’ is a package and cannot be directly executed

Sorry, I really missed this part :zipper_mouth_face:

My new error after changed

Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 221, in _get_main_module_details
    return _get_module_details(main_name)
  File "/usr/lib/python3.8/runpy.py", line 138, in _get_module_details
    raise error("No module named %s" % mod_name)
ImportError: No module named __main__

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/julio/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
    cli.main()
  File "/home/julio/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 430, in main
    run()
  File "/home/julio/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 267, in run_file
    runpy.run_path(options.target, run_name=compat.force_str("__main__"))
  File "/usr/lib/python3.8/runpy.py", line 278, in run_path
    mod_name, mod_spec, code = _get_main_module_details()
  File "/usr/lib/python3.8/runpy.py", line 224, in _get_main_module_details
    raise error("can't find %r module in %r" %
ImportError: can't find '__main__' module in 'trytond'

It looks like this path point to a directory instead of the trytond starting script.

Hi Cédric, Thanks for answer me.

I changed that when noticed that Maxx had said me on her response. My launch looks like this now

    {
            "version": "0.2.0",
            "configurations": [       
                {
                    "name": "Run Server Tryton",
                    "type": "python",
                    "request": "launch",            
                    "program": "trytond",
                    "console": "integratedTerminal",
                    "args": ["--config" ,"trytond.conf",
                             "--logconf","trytond_log.conf", 
                             "--dev"]            
                } 
            ]
        }

But I have the above error still :expressionless:

ImportError: can't find '__main__' module in 'trytond'

try with variable pythonPath : “path_to_your_virtualenv/bin/python”
Did you install trytond in your virtualenv ?

If you did not installed trytond by only cloned the source code, then the trytond/bin/trytond is not in your path. And it looks like the trytond is so Python tries to run it by finding a __main__.py file which does not exist.
So you have to install trytond or have trytond/bin/trytond in your path.

I believe a I did, if trying to install like I know the log show me as installed.

venv) julio@tryton-server:/work/tryton-workspace/tryton-env$ python3 -m pip install pycairo trytond tryton
Requirement already satisfied: pycairo in ./venv/lib/python3.8/site-packages (1.20.0)
Requirement already satisfied: trytond in ./venv/lib/python3.8/site-packages (5.8.0)
Requirement already satisfied: tryton in ./venv/lib/python3.8/site-packages (5.8.0)
Requirement already satisfied: werkzeug in ./venv/lib/python3.8/site-packages (from trytond) (1.0.1)
Requirement already satisfied: python-sql>=0.5 in ./venv/lib/python3.8/site-packages (from trytond) (1.2.1)
Requirement already satisfied: polib in ./venv/lib/python3.8/site-packages (from trytond) (1.1.0)
Requirement already satisfied: passlib>=1.7.0 in ./venv/lib/python3.8/site-packages (from trytond) (1.7.4)
Requirement already satisfied: wrapt in ./venv/lib/python3.8/site-packages (from trytond) (1.12.1)
Requirement already satisfied: python-dateutil in ./venv/lib/python3.8/site-packages (from trytond) (2.8.1)
Requirement already satisfied: lxml>=2.0 in ./venv/lib/python3.8/site-packages (from trytond) (4.6.2)
Requirement already satisfied: relatorio[fodt]>=0.7.0 in ./venv/lib/python3.8/site-packages (from trytond) (0.9.2)
Requirement already satisfied: Genshi in ./venv/lib/python3.8/site-packages (from trytond) (0.7.5)
Requirement already satisfied: PyGObject in ./venv/lib/python3.8/site-packages (from tryton) (3.38.0)
Requirement already satisfied: six>=1.5 in ./venv/lib/python3.8/site-packages (from python-dateutil->trytond) (1.15.0)
Requirement already satisfied: python-magic; extra == "fodt" in ./venv/lib/python3.8/site-packages (from relatorio[fodt]>=0.7.0->trytond) (0.4.18)
(venv) julio@tryton-server:/work/tryton-workspace/tryton-env$ 

Please let me know if my way to install is wrong

I recreate a new virtual enviroment called venv, and I put python on the pythonPath so I removed venvPath, now my setttings

{
    "python.pythonPath": "venv/bin/python"
}

if I run from the internal terminal it works fine, doing this

/> trytond --config trytond.conf --logconf trytond_log.conf

But it fails with my launch.json

Hi,

I was able to run at now, putting “program”: “trytond/bin/trytond” like Cédric said. But now it throw a exception and show me this error

 No module named trytond.__main__; 'trytond' is a package and cannot be directly executed

There are something I missed to install?

[EDITED]
This problem was solved removing --dev modifier from my args. Now all is working perfectly thanks you both.

I don’t remember even for what reason I putetd it, or what it does. :zipper_mouth_face:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.