tags:

views:

310

answers:

3
+2  Q: 

Python in tcsh

I don't have much experience with tcsh, but I'm interested in learning. I've been having issues getting Python to see PYTHONPATH. I can echo $PYTHONPATH, and it is correct, but when I start up Python, my paths do not show up in sys.path. Any ideas?

EDIT:

[dmcdonal@tg-steele ~]$ echo $PYTHONPATH
/home/ba01/u116/dmcdonal/PyCogent-v1.1

>>> from sys import path
>>> from os import environ
>>> path
['', '/apps/steele/Python-2.5.2/lib/python2.5/site-packages/setuptools-0.6c8-py2.5.egg', '/apps/steele/Python-2.5.2/lib/python2.5/site-packages/FiPy-2.0-py2.5.egg', '/apps/steele/Python-2.5.2', '/apps/steele/Python-2.5.2/lib/python25.zip', '/apps/steele/Python-2.5.2/lib/python2.5', '/apps/steele/Python-2.5.2/lib/python2.5/plat-linux2', '/apps/steele/Python-2.5.2/lib/python2.5/lib-tk', '/apps/steele/Python-2.5.2/lib/python2.5/lib-dynload', '/apps/steele/Python-2.5.2/lib/python2.5/site-packages', '/apps/steele/Python-2.5.2/lib/python2.5/site-packages/Numeric']
>>> environ['PYTHONPATH']
'/apps/steele/Python-2.5.2'
+1  A: 

Make sure that you're not starting python with the -E option (which is: ignore environment variables). If you start python via a shell script or some other app, just double check it doesn't add anything.

Since the list of sys.path is long, it can be hard to miss your paths. PYTHONPATH stuff normally gets added to about the middle of the list, after all the library paths. Any chance your paths are there, just buried in the middle?

Jarret Hardie
definately not in the list and I'm calling the binary directly
daniel
Hmmm... Does it work in any other shell? If you pop into bash, etc, does it work there? What version of Python, btw?
Jarret Hardie
works in bash just fine. v2.5.2
daniel
A: 

Check:

  1. PYTHONPATH is in os.environ,
  2. and set to the correct value of a colon separated list of paths.

If it is, and you can confirm that your paths are not in sys.path, you have found a bug.

If it is not in os.environ, your environment is not passing through to Python (probably another bug).

Of course, show us the actual code/exports, and someone will tell you pretty quickly.

Ali A
+4  A: 

How are you setting PYTHONPATH? You might be confusing tcsh's set vs. setenv. Use "set" to set what tcsh calls shell variables and use "setenv" to set environment variables. So, you need to use setenv in order for Python to see it. For example:

$ set FOO='bar'
$ echo $FOO
bar
$ python -c 'import os; print os.getenv("FOO")'
None

$ setenv BAR 'wiz'
$ echo $BAR
wiz
$ python -c 'import os; print os.getenv("BAR")'
wiz

There is some more information available in the variables section of the tcsh documentation.

Ryan Bright