Discussion:
Modify Python Path
Kenneth Gomez
2002-12-07 20:05:04 UTC
Permalink
Hello,

This may seem like a silly question but I have tried the documentation
and the system registry but I cant find where Python stores the search
path.

I am using poor old Win Me.

I have modified the path setting under
HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.2\PythonPath to add in
my path : c:\test

but, Python still cant find the modules that I have saved in the test
directory.

Could you kindly advise me where to make the necessary changes?

Thank you.
Cheers,
Kenneth Gomez.
Erik Max Francis
2002-12-07 20:13:39 UTC
Permalink
Post by Kenneth Gomez
This may seem like a silly question but I have tried the documentation
and the system registry but I cant find where Python stores the search
path.
sys.path. You can also use the PYTHONPATH environment variable, though
since I'm a UNIX guy I don't know exactly how that translates into
Windows (which you're obviously using).
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ My long is strong enough, you know / Strong enough to let you go
\__/ Xscape
Official Omega page / http://www.alcyone.com/max/projects/omega/
The official distribution page for the popular Roguelike, Omega.
Dennis Lee Bieber
2002-12-07 21:46:56 UTC
Permalink
Erik Max Francis fed this fish to the penguins on Saturday 07 December
Post by Erik Max Francis
Post by Kenneth Gomez
This may seem like a silly question but I have tried the
documentation and the system registry but I cant find where Python
stores the search path.
sys.path. You can also use the PYTHONPATH environment variable,
though since I'm a UNIX guy I don't know exactly how that translates
into Windows (which you're obviously using).
On the older Windows versions (9x family), edit c:\autoexec.bat (your
choice: command shell, "start/run: sysedit", "start/run: msconfig"
(W98+)).

The NT family requires setting up via some configuration editor (I
don't think msconfig is used in NT, but it might have that name) under
"environment".
--
Post by Erik Max Francis
============================================================== <
wlfraed at ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wulfraed at dm.net | Bestiaria Support Staff <
============================================================== <
Bestiaria Home Page: http://www.beastie.dm.net/ <
Home Page: http://www.dm.net/~wulfraed/ <
GerritM
2002-12-07 20:34:45 UTC
Permalink
"Kenneth Gomez" <kennethg at pd.jaring.my> schreef in bericht
news:3df252a2.2123848 at news.jaring.my...
<...snip...>
Post by Kenneth Gomez
my path : c:\test
but, Python still cant find the modules that I have saved in the test
directory.
Could you kindly advise me where to make the necessary changes?
Thank you.
Cheers,
Kenneth Gomez.
another simple way to achieve this is by creating a file test.pth in the
main python directory (C:\Python22 on my computer), with a single line of
ASCII text:
c:\test

Python will add the content of the .pth files to the pythonpath when
starting up.

kind regards, Gerrit

--
www.extra.research.philips.com/natlab/sysarch/
Gerhard Häring
2002-12-07 20:13:20 UTC
Permalink
Post by Kenneth Gomez
Hello,
This may seem like a silly question but I have tried the documentation
and the system registry but I cant find where Python stores the search
path.
I am using poor old Win Me.
I have modified the path setting under
HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.2\PythonPath to add in
my path : c:\test
but, Python still cant find the modules that I have saved in the test
directory.
Could you kindly advise me where to make the necessary changes?
*Not* in the registry.

Either set an environment variable called PYTHONPATH that includes your
directories, like:

SET PYTHONPATH=c:\test;c:\mylibs

In your home user version of Windows, you might still have to use the
\AUTOEXEC.BAT file to make this persistent. So option #2 might be a
better one:

Alternatively, create a .pth file in your site-packages directory
(c:\python22\lib\site-packages in the default installation). Call it
whatever you like, for example mypkg.pth. In this file, put *one line*
with the directory you want to have in your Python module search path.
For example:

c:\test

HTH,

-- Gerhard
Kenneth Gomez
2002-12-08 03:31:05 UTC
Permalink
Thank you, thank you, thank you...

I knew there was an easier method than modifying the registry.

Thank you again.
Regards,
Kenneth.

Cheers,
Kenneth Gomez.
Peter Hansen
2002-12-08 16:55:55 UTC
Permalink
Post by Kenneth Gomez
Thank you, thank you, thank you...
I knew there was an easier method than modifying the registry.
The suggestions to use .pth files doesn't mention a couple of details:

1. Under Windows, the file extension must be in *lower case* as the
comparison is case-sensitive.

2. See the python/lib/site.py file for this and other gory details.

-Peter

Colin Brown
2002-12-08 19:49:58 UTC
Permalink
Hi Kenneth

One can also modify the path programmatically:

import sys
sys.path.append(r'c:\mynewpath')
...

Colin Brown
PyNZ
Continue reading on narkive:
Loading...