Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

How to get a Python shell with the Odoo environment?

Subscribe

Get notified when there's activity on this post

This question has been flagged
pythonclishell
9 Replies
69912 Views
Avatar
Kasper Souren

How to get a Python shell with the Odoo environment?

Ideally IPython.

I don't have a clear idea what I want to achieve but over the years I've come to love the possibility of Python (and JavaScript, as opposed to PHP) to just be in a shell with all the relevant code and figure out things. Much better way to learn and code than reading a book or even API documentation.

I started playing around a bit.

    $ ipython

    import openerp

    openerp.cli.main()

5
Avatar
Discard
Hannes Smit

Kasper, may I ask what you want to achieve? `python openerp-server` should do start the server. Have a look at the help for flags / configurations.

Avatar
Bernardo Kyotoku
Best Answer

In version 10: ./odoo-bin shell -d <database>  --addons-path='your/addons/path'

http://stackoverflow.com/questions/34293139/how-to-run-odoo-orm-methods-in-the-python-console

6
Avatar
Discard
Avatar
Muhammad Awais
Best Answer

 You can also use...           

  • $ python3 odoo-bin shell -d db_name

1
Avatar
Discard
Avatar
Marvin Taboada
Best Answer

Hello Kasper,

It seems you're using a source distribution where all addons have been moved out of the "openerp.addons" Python package to the root directory of the distribution (current layout in GitHub, branch 7.0), hence it cannot load some required modules. Specifying "--addons-path/addons_path" is required in order to fix this.

You can fake command line arguments in the Python interactive interpreter in the following way:

>>> import sys
>>> import openerp
>>>
>>> sys.argv = ['', '--addons-path=/opt/openerp/server/addons', '--log-level=debug']
>>>
>>> openerp.cli.main()

Please note that the first argument is an empty string.

Regards.

1
Avatar
Discard
Avatar
john doe
Best Answer

Same situation, shell module is installed. When i type sudo ./odoo.py shell -d v8dev it says:

"ERROR ? openerp.sql_db: Connection to the database failedTraceback (most recent call last): OperationalError: IMPORTANR  "root" role is not exist"

Fix: type just ./odoo.py shell -d v8dev

0
Avatar
Discard
Avatar
Wouter Tebbens
Best Answer

Hey Kasper, have a look at this thread, it's precisely about IDE's that people use for OpenERP v7 / odoo development:

https://www.odoo.com/forum/Help-1/question/Tools--IDE-for-OpenERP7-source-and-report-development-5536

0
Avatar
Discard
Avatar
Manuel A. Márquez
Best Answer

I know it's too late but you can use erppeek. https://erppeek.readthedocs.io/en/latest/

0
Avatar
Discard
Avatar
Jérémy Kersten (jke)
Best Answer

Not compatible with V7, because it's new in saas-6...

But that can help other peoples looking about it...

./odoo.py shell -d saas6

after, all is possible ...

OLD API : 

 >>> blog_post_ids = env.registry['blog.post'].search(env.cr, env.uid, [], context=env.context)
>>> env.registry['blog.post'].browse(env.cr, env.uid, blog_post_ids, context=env.context).mapped('name')

[u'The Future of Emails', u'Integrating your CMS and E-Commerce']


NEW API:

>>> env['blog.post'].search([]).mapped('name')

[u'Integrating your CMS and E-Commerce', u'The Future of Emails']

0
Avatar
Discard
Avatar
Nehemias Herrera
Best Answer

Hi, I am trying to get to the interactive shell with odoo 11 but I am getting the error

odoo@21ad17f724ce:/$ odoo shell -d universidad

2018-01-07 18:53:39,951 134 INFO ? odoo: Odoo version 11.0-20171030

2018-01-07 18:53:39,952 134 INFO ? odoo: Using configuration file at /etc/odoo/odoo.conf

2018-01-07 18:53:39,952 134 INFO ? odoo: addons paths: ['/var/lib/odoo/addons/11.0', '/mnt/extra-addons', '/usr/lib/python3/dist-packages/odoo/addons']

2018-01-07 18:53:39,953 134 INFO ? odoo: database: default@default:default

2018-01-07 18:53:39,963 134 INFO ? odoo.service.server: Initiating shutdown

2018-01-07 18:53:39,963 134 INFO ? odoo.service.server: Hit CTRL-C again or send a second signal to force the shutdown.

2018-01-07 18:53:39,964 134 INFO ? odoo.sql_db: Connection to the database failed

Traceback (most recent call last):

File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 59, in __new__

return cls.registries[db_name]

File "/usr/lib/python3/dist-packages/odoo/tools/func.py", line 68, in wrapper

return func(self, *args, **kwargs)

File "/usr/lib/python3/dist-packages/odoo/tools/lru.py", line 44, in __getitem__

a = self.d[obj].me

KeyError: 'universidad'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/usr/bin/odoo", line 8, in <module>

odoo.cli.main()

File "/usr/lib/python3/dist-packages/odoo/cli/command.py", line 60, in main

o.run(args)

File "/usr/lib/python3/dist-packages/odoo/cli/shell.py", line 124, in run

self.shell(config['db_name'])

File "/usr/lib/python3/dist-packages/odoo/cli/shell.py", line 110, in shell

registry = odoo.registry(dbname)

File "/usr/lib/python3/dist-packages/odoo/__init__.py", line 76, in registry

return modules.registry.Registry(database_name)

File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 61, in __new__

return cls.new(db_name)

File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 73, in new

registry.init(db_name)

File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 141, in init

with closing(self.cursor()) as cr:

File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 472, in cursor

return self._db.cursor()

File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 634, in cursor

return Cursor(self.__pool, self.dbname, self.dsn, serialized=serialized)

File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 178, in __init__

self._cnx = pool.borrow(dsn)

File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 517, in _locked

return fun(self, *args, **kwargs)

File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 585, in borrow

**connection_info)

File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 164, in connect

conn = _connect(dsn, connection_factory=connection_factory, async=async)

psycopg2.OperationalError: could not connect to server: No such file or directory

Is the server running locally and accepting

connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?


I tried from the official odoo docker image and also with bitnami odoo image, same error, I am able to get into it without the -d argument but this way there's no environment, how can I either start the interactive shell properly or how to load the environment if I got into the interactive shell whitout specifying at database.

there's another error

odoo@21ad17f724ce:/$ odoo shell

2018-01-07 18:58:41,137 149 INFO ? odoo: Odoo version 11.0-20171030

2018-01-07 18:58:41,137 149 INFO ? odoo: Using configuration file at /etc/odoo/odoo.conf

2018-01-07 18:58:41,137 149 INFO ? odoo: addons paths: ['/var/lib/odoo/addons/11.0', '/mnt/extra-addons', '/usr/lib/python3/dist-packages/odoo/addons']

2018-01-07 18:58:41,137 149 INFO ? odoo: database: default@default:default

2018-01-07 18:58:41,148 149 INFO ? odoo.service.server: Initiating shutdown

2018-01-07 18:58:41,148 149 INFO ? odoo.service.server: Hit CTRL-C again or send a second signal to force the shutdown.

No environment set, use `/usr/bin/odoo shell -d dbname` to get one.

odoo: <module 'odoo' from '/usr/lib/python3/dist-packages/odoo/__init__.py'>

openerp: <module 'odoo' from '/usr/lib/python3/dist-packages/odoo/__init__.py'>

Python 3.5.3 (default, Jan 19 2017, 14:11:04)

[GCC 6.3.0 20170118] on linux

Type "help", "copyright", "credits" or "license" for more information.

(Console)

>>> dir()

['__builtins__', 'odoo', 'openerp']

>>> from odoo.service import db

>>> db.list_dbs()

2018-01-07 18:59:15,171 149 INFO ? odoo.sql_db: Connection to the database failed

Traceback (most recent call last):

File "<console>", line 1, in <module>

File "/usr/lib/python3/dist-packages/odoo/service/db.py", line 362, in list_dbs

with closing(db.cursor()) as cr:

File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 634, in cursor

return Cursor(self.__pool, self.dbname, self.dsn, serialized=serialized)

File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 178, in __init__

self._cnx = pool.borrow(dsn)

File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 517, in _locked

return fun(self, *args, **kwargs)

File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 585, in borrow

**connection_info)

File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 164, in connect

conn = _connect(dsn, connection_factory=connection_factory, async=async)

psycopg2.OperationalError: could not connect to server: No such file or directory

Is the server running locally and accepting

connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

>>>

Any help will be appreciated :) thanks




-2
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
how to install CLI shell in odoo?
cli shell v8.0
Avatar
Avatar
Avatar
5
Feb 17
11002
new python env
python
Avatar
0
Mar 25
2387
What means "Too many values to unpack" message? Solved
python
Avatar
Avatar
Avatar
Avatar
Avatar
4
Apr 24
175938
have no data in screen. read data in my own module from different model
python
Avatar
0
Dec 23
3000
How to insert value to a one2many field in table with create method? Solved
python
Avatar
Avatar
Avatar
Avatar
Avatar
5
Jul 25
232376
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now