zope and PYTHONPATH
All- I run Plone2 over zope2.7 on a linux box. We have multiple python intances on our linux box. As zope is very picky about the python version, we have a python instance only for a zope. Also, we have our own applications in python (unrelated to zope) which need 3rd party modules. For that we have a different python binary at a different location. From zope's python I want to use the modules we developed and installed on the other python intance. So, I added the /usr/lib/python2.2/site-packages, the python for our local use, to PYTHONPATH by exporting PYTHONPATH from bash_profile. Invoking the script from the command line with zope's python works without an import error. However, zope/Plone combo wont startup with zopectl if I use one of those modules in a basic zope product I am trying to develop. It throws an ImportError. Am I missing something? Isnt it supposed to work that way? I realized maybe I need to make that change to PYTHONPATH in zope's startup script. So, I have changed the "zopectl" used to start zope+plone now, and printed the PYTHONPATH by using "env | grep PYTHONPATH" in the zopectl script. It is being set to what I want. However, the ImportError persists from zope's startup. I am surprised why it works, when I run the script that does the import, from the commandline and why it wont from zope's startup although the same PYTHONPATH is being set. The error being thrown. 2004-09-20T10:03:36 ERROR(200) Zope Could not import Products.plots Traceback (most recent call last): File "/home/accts/zope/Zope-2.7.0/lib/python/OFS/Application.py", line 654, in import_product product=__import__(pname, global_dict, global_dict, silly) File "/home/accts/zope/srcczope/Products/plots/__init__.py", line 1, in ? import plots File "/home/accts/zope/srcczope/Products/plots/plots.py", line 3, in ? from mx import DateTime ImportError: cannot import name DateTime Traceback (most recent call last): File "/home/accts/zope/Zope-2.7.0/lib/python/Zope/Startup/run.py", line 49, in ? run() File "/home/accts/zope/Zope-2.7.0/lib/python/Zope/Startup/run.py", line 19, in run start_zope(opts.configroot) File "/home/accts/zope/Zope-2.7.0/lib/python/Zope/Startup/__init__.py", line 51, in start_zope starter.startZope() File "/home/accts/zope/Zope-2.7.0/lib/python/Zope/Startup/__init__.py", line 230, in startZope Zope.startup() File "/home/accts/zope/Zope-2.7.0/lib/python/Zope/__init__.py", line 46, in startup _startup() File "/home/accts/zope/Zope-2.7.0/lib/python/Zope/App/startup.py", line 45, in startup OFS.Application.import_products() File "/home/accts/zope/Zope-2.7.0/lib/python/OFS/Application.py", line 631, in import_products import_product(product_dir, product_name, raise_exc=debug_mode) File "/home/accts/zope/Zope-2.7.0/lib/python/OFS/Application.py", line 654, in import_product product=__import__(pname, global_dict, global_dict, silly) File "/home/accts/zope/srcczope/Products/plots/__init__.py", line 1, in ? import plots File "/home/accts/zope/srcczope/Products/plots/plots.py", line 3, in ? from mx import DateTime ImportError: cannot import name DateTime
Hi, Am Mo, den 20.09.2004 schrieb Kalyan Jammigumpula um 17:18:
All- I run Plone2 over zope2.7 on a linux box. ^^^^^^^ ....
on the other python intance. So, I added the /usr/lib/python2.2/site-packages, the python for our local use, to ^^^^^
PYTHONPATH by exporting PYTHONPATH from bash_profile. Invoking the script from the command line with zope's python works without an import error. However, zope/Plone combo wont startup with zopectl if I use one of those modules in a basic zope product I am trying to develop. It throws an ImportError. Am I missing something? Isnt it supposed to work that way?
No. You canot share extensions between different python versions. If your extension is python only, you can link/copy only this over into the path for your Zopes python. Zope isnt really picky about python, it only expects the right version, that is, 2.3 for zope2.7. Regards Tino Wildenhain
on the other python intance. So, I added the /usr/lib/python2.2/site-packages, the python for our local use, to We changed the version of our local use python to python2.3. So, now our path is /usr/lib/python2.3/site-packages. Zope's python is installed in /home/accts/zope/bin/python.
No. You canot share extensions between different python versions. If your extension is python only, you can link/copy only this over into the path for your Zopes python. ??? I dont exactly understand what you mean. I sure can import modules installed in /usr/lib/python2.3/site-packages with the python binary I installed for zope from the commandline.
~zope/bin/python Python 2.3.3 (#1, Jun 24 2004, 17:07:19) [GCC 3.2 20020903 (Red Hat Linux 8.0 3.2-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
from mx import DateTime
the above module is not installed with zope's python but still can import it because /usr/lib/python2.3/site-packages is in PYTHONPATH.
Zope isnt really picky about python, it only expects the right version, that is, 2.3 for zope2.7.
What I meant was it is bound to a version. We have some non-zope, non-web related development in python and I thought it is better to have independent versions of python for local use and zope. It makes upgrading either one of them a lot easier. However, we want to use some of the modules we develop with our local use for zope. Any idea how I could do that? -Kalyan
Kalyan Jammigumpula wrote at 2004-9-20 10:18 -0500:
... From zope's python I want to use the modules we developed and installed on the other python intance. So, I added the /usr/lib/python2.2/site-packages, the python for our local use, to PYTHONPATH by exporting PYTHONPATH from bash_profile. Invoking the script from the command line with zope's python works without an import error. However, zope/Plone combo wont startup with zopectl if I use one of those modules in a basic zope product I am trying to develop. It throws an ImportError. Am I missing something? Isnt it supposed to work that way? ... File "/home/accts/zope/srcczope/Products/plots/plots.py", line 3, in ? from mx import DateTime ImportError: cannot import name DateTime
This means, it found an "mx" but it did not contain "DateTime". Check which "mx" was found and why there is no "DateTime" there... -- Dieter
Kalyan Jammigumpula wrote at 2004-9-20 10:18 -0500:
File "/home/accts/zope/srcczope/Products/plots/plots.py", line 3, in ? from mx import DateTime ImportError: cannot import name DateTime
This means, it found an "mx" but it did not contain "DateTime".
Check which "mx" was found and why there is no "DateTime" there...
That was it Dieter. Thank you very much. What was happening was zope's python had mx with Tidy and other modules but no DateTime. Our local instance of python had mx's DateTime module installed. So, it was finding mx from the zope's python but not DateTime. However, the PYTHONPATH problem remains. For the other modules in python's local instance and not present in zope's python unlike mx, I need to set python's sys.path in every python file I need to import them which is annoying. What I do now is I import sys and do sys.path = sys.path + ['PATHNAMES I NEED'] That seems to work fine and I have no ImportErrors. My idea of PYTHONPATH was to basically avoid this and that's what I think PYTHONPATH is there for. From what I read on zope.org mailing list (keywork PYTHONPATH), somebody had said to look at the pathnames in sys.path and compare them. When I print sys.path in zopectl.py, I see all the pathnames I need. However, by the time zope imports my half-baked product, the pathnames I need and I set using PYTHONPATH are not there anymore. That to me was a little odd. I really appreciate your help regarding this. Thank you very much. It has helped me understand ImportErrors a little better. -Kalyan
Kalyan Jammigumpula wrote at 2004-9-20 13:40 -0500:
... From what I read on zope.org mailing list (keywork PYTHONPATH), somebody had said to look at the pathnames in sys.path and compare them. When I print sys.path in zopectl.py, I see all the pathnames I need. However, by the time zope imports my half-baked product, the pathnames I need and I set using PYTHONPATH are not there anymore. That to me was a little odd. I really appreciate your help regarding this. Thank you very much. It has helped me understand ImportErrors a little better.
A misfeature of the startup/configuration setup: Unfortunately, you must modify "PYTHONPATH" both in "zopectl" as well as in "runzope". Depending on how you start Zope (which "action" you use for "zopectl"), the definition in "zopectl" or "runzope" is effective. Maybe, you consider to file a bug report (as affairs could be improved). -- Dieter
You are right, Dieter. Now, my PYTHONPATH setting works. I have filed a bug report as you have said. Thank you, once again. I really appreciate your help. -Kalyan Dieter Maurer wrote:
Kalyan Jammigumpula wrote at 2004-9-20 13:40 -0500:
... From what I read on zope.org mailing list (keywork PYTHONPATH), somebody had said to look at the pathnames in sys.path and compare them. When I print sys.path in zopectl.py, I see all the pathnames I need. However, by the time zope imports my half-baked product, the pathnames I need and I set using PYTHONPATH are not there anymore. That to me was a little odd. I really appreciate your help regarding this. Thank you very much. It has helped me understand ImportErrors a little better.
A misfeature of the startup/configuration setup:
Unfortunately, you must modify "PYTHONPATH" both in "zopectl" as well as in "runzope".
Depending on how you start Zope (which "action" you use for "zopectl"), the definition in "zopectl" or "runzope" is effective.
Maybe, you consider to file a bug report (as affairs could be improved).
participants (3)
-
Dieter Maurer -
Kalyan Jammigumpula -
Tino Wildenhain