1

I am running a Plone instance using the VM Virtual Box. After starting the instance, when I type the import command in the machine: "from plone import api", I get an error: from can't read /var/mail/plone.

I get the same error even if I type: " #!/usr/bin/env python" before the import command

when I rather type python, and then the command : "from plone import api", I get an error: No module named plone.

what should I do?

  • 2
    Sounds like you never installed the plone package with `pip`. Did you run `pip install plone` from your python environment? – Rashid 'Lee' Ibrahim Aug 16 '21 at 20:14
  • 1
    You cannot expect this to work in a normal python REPL, regardless of whether Plone is installed properly or not. Instead, you need to find the Plone buildout root, and from there look into the bin folder. There you might find a script called `zopepy`, which sets up `sys.path` according to your installation. Or else, run `bin/instance debug` or `bin/client debug`. – fulv Aug 16 '21 at 23:13
  • @Rashid'Lee'Ibrahim I don't remember if I did the pip install plone command, as i was having an installation error and I kept trying until it would install python. – duaa fatima Sep 01 '21 at 19:30
  • @fulv I used the bin/instance debug but it gives me : plone.api.exc.CannotGetPortalError, so I looked at the docs, but it says try: bin/instance -O debug but I can't figure out the portal id, what does the portal id refer to? – duaa fatima Sep 01 '21 at 19:31
  • The "can't read /var/mail/..." problem is unrelated, and a duplicate of https://stackoverflow.com/questions/16069816/getting-python-error-from-cant-read-var-mail-bio – tripleee Jun 13 '22 at 05:02

1 Answers1

0

If you start up the zope site via bin/instance debug it's not clear what plone site should be used, since there can be more than one.

So you first need to define what plone site plone.api should use. This is done by pointing the site manager to your plone site.

./bin/instance debug
Starting debugger (the name "app" is bound to the top-level Zope object)
...
...
>>>
>>> api.portal.get()  # Will not work 
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/path/to/egg/plone.api.egg/plone/api/portal.py", line 82, in get
    'Unable to get the portal object. More info on '
CannotGetPortalError: Unable to get the portal object. More info on http://docs.plone.org/develop/plone.api/docs/api/exceptions.html#plone.api.exc.CannotGetPortalError
>>> plone = app.get('my-plone-site')
>>> plone
<PloneSite at /my-plone-site>
>>> from zope.component.hooks import setSite
>>> setSite(plone)
>>> from plone import api
>>> api.portal.get()
<PloneSite at /my-plone-site>

That's it.

Mathias
  • 6,777
  • 2
  • 20
  • 32