0

So I did some research and learn that you use the sys module to set the path for 2.5:

import sys
sys.path.append('usr/local/lib/python2.5/site-packages/')

And that would set the path for 2.5 permanently, but if i do the samething for 2.6 or 3.0, it will not work the next time I open the interpreter.

I thought this path was suppose to be set by default. it's not so i'm trying to set it.

help please
thanks

5
Contributors
11
Replies
13
Views
8 Years
Discussion Span
Last Post by vegaseat
Featured Replies
  • It's quicker to get the path to site-packages right from the command line: [code]python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" [/code] Read More

0

You can get the path to the site-packages directory like this

>>> import os
>>> os.path.join(os.path.split(os.__file__)[0], "site-packages")
'/usr/lib64/python2.6/site-packages'

With python 3:

>>> import os                                                   
>>> os.path.join(os.path.split(os.__file__)[0], "site-packages")
'/usr/local/lib/python3.1/site-packages'

(on the same machine).

However, you shouldn't normally need to put the site-packages in sys.path yourself. I'd like to see the value of your sys.path just after you start python.

0

You can get the path to the site-packages directory like this

>>> import os
>>> os.path.join(os.path.split(os.__file__)[0], "site-packages")
'/usr/lib64/python2.6/site-packages'

With python 3:

>>> import os                                                   
>>> os.path.join(os.path.split(os.__file__)[0], "site-packages")
'/usr/local/lib/python3.1/site-packages'

(on the same machine).

However, you shouldn't normally need to put the site-packages in sys.path yourself. I'd like to see the value of your sys.path just after you start python.

Doesn't even work temporarily.

"No module name file.py" after i did what you wrote and attempted to image a module

0

What I wrote doesn't do anything, it only computes the path to site-packages.
What you should do is paste your sys.path here (before you do anything with it).

0

What you should do is paste your sys.path here (before you do anything with it).

What do you mean by that? where is here?

0

What Gribouillis means is run this code and post the output here on DaniWeb ...

# show the system path for Python ( PYTHONPATH )

import sys
print( sys.path )

You need to run this with the version of Python you are interested in.

Also you cannot permanently set PYTHONPATH as it includes information about the current file you are working with.

Edited by vegaseat: this

0

I thought this path was suppose to be set by default. it's not so i'm trying to set it.

You can modify it on startup by adding PYTHONPATH to your ~/.bash.rc file, or create one if you don't have it.
export PYTHONPATH=$PYTHONPATH:/path/to/add:/second/path

0

>>> import sys
>>> sys.path

This is what i got. no site-pakcages though

0

I suggest that you write a module

# mystartup.py
import os, sys
site_packages = os.path.join(os.path.split(os.__file__)[0], "site-packages")
sys.path.append(site_packages)

and put this module somewhere on your python path. Then when you write a python program, you simply put

# at the top of your main program
import mystartup

This should work even if you have different versions of python.

Edited by Gribouillis: n/a

1

It's quicker to get the path to site-packages right from the command line:

python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

Edited by prouty: needed [code]

0
from distutils.sysconfig import get_python_lib

Yes, I knew there was a function like this, but I couldn't remember where it was. Thanks.

0

That means that the startup code from Gribouillis could also be written this way ...

# mystartup.py
import sys
from distutils.sysconfig import get_python_lib
sys.path.append(get_python_lib())

Well, both ways ought to work equally well. :)

The advantage with the code from Gribouillis is that is somewhat self-documenting.

Edited by vegaseat: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.