473,385 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How do I add permanently to Pythons sys.path?

cnb
>>sys.path
['C:\\Python25\\Progs\\NatLangProc', 'C:\\Python25\\Lib\\idlelib', 'C:\
\Windows\\system32\\python25.zip', 'C:\\Python25\\lib\\site-packages\
\orange', 'C:\\Python25\\lib\\site-packages\\orange\\OrangeWidgets',
'C:\\Python25\\lib\\site-packages\\orange\\OrangeCanvas', 'C:\
\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-
packages', 'C:\\Python25\\lib\\site-packages\\Numeric', 'C:\\Python25\
\lib\\site-packages\\PIL']
>>>
Now I have my personal programs in C:/Python25/Progs/

How do I add so that I can just do "import somefile" from anywhere in
that directory in the interpreter and it can load files from other
folders in that directory.
Sep 16 '08 #1
12 4850

On 16 sep 2008, at 17:13, cnb wrote:
>>>sys.path
['C:\\Python25\\Progs\\NatLangProc', 'C:\\Python25\\Lib\\idlelib',
'C:\
\Windows\\system32\\python25.zip', 'C:\\Python25\\lib\\site-packages\
\orange', 'C:\\Python25\\lib\\site-packages\\orange\\OrangeWidgets',
'C:\\Python25\\lib\\site-packages\\orange\\OrangeCanvas', 'C:\
\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-
packages', 'C:\\Python25\\lib\\site-packages\\Numeric', 'C:\\Python25\
\lib\\site-packages\\PIL']
>>>>

Now I have my personal programs in C:/Python25/Progs/

How do I add so that I can just do "import somefile" from anywhere in
that directory in the interpreter and it can load files from other
folders in that directory.
--
http://mail.python.org/mailman/listinfo/python-list

a temp solution is to append it to that list:

sys.path.append('C:/Python25/Progs/')

a permanent solution is to add it to the environment variable
(no idea where to set this in windows)
$PYTHONPATH = "/C:/Python25/Progs/"

gr
Arno
Sep 16 '08 #2
cnb
On Sep 16, 5:25*pm, Python <pyt...@rgbaz.euwrote:
On 16 sep 2008, at 17:13, cnb wrote:
>>sys.path
['C:\\Python25\\Progs\\NatLangProc', 'C:\\Python25\\Lib\\idlelib', *
'C:\
\Windows\\system32\\python25.zip', 'C:\\Python25\\lib\\site-packages\
\orange', 'C:\\Python25\\lib\\site-packages\\orange\\OrangeWidgets',
'C:\\Python25\\lib\\site-packages\\orange\\OrangeCanvas', 'C:\
\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-
packages', 'C:\\Python25\\lib\\site-packages\\Numeric', 'C:\\Python25\
\lib\\site-packages\\PIL']
Now I have my personal programs in C:/Python25/Progs/
How do I add so that I can just do "import somefile" from anywhere in
that directory in the interpreter and it can load files from other
folders in that directory.
--
http://mail.python.org/mailman/listinfo/python-list

a temp solution is to append it to that list:

sys.path.append('C:/Python25/Progs/')

a permanent solution is to add it to the environment variable
(no idea where to set this in windows)
$PYTHONPATH = "/C:/Python25/Progs/"

gr
Arno
but since Python25/ is in my path it only seems to import from that
exact dir, not dirs inside the dir.

so i have to do somerthing like /progs/* ?
and also, temporary adding doesnt seem to work.
Sep 16 '08 #3
Python wrote:
a temp solution is to append it to that list:

sys.path.append('C:/Python25/Progs/')

a permanent solution is to add it to the environment variable
(no idea where to set this in windows)
$PYTHONPATH = "/C:/Python25/Progs/"
Don't append a / or \!Use "C:/Python25/Progs" instead of
"C:/Python25/Progs/". The trailing slash causes trouble on Windows.

The reason for the trouble is design decision from Microsoft. The low
level stat() syscall returns an error for "C:\\Python25\\Progs\\" but it
returns success for "C:\\Python25\\Progs".

Christian

Sep 16 '08 #4
On Sep 16, 10:13*am, cnb <circularf...@yahoo.sewrote:
>sys.path

['C:\\Python25\\Progs\\NatLangProc', 'C:\\Python25\\Lib\\idlelib', 'C:\
\Windows\\system32\\python25.zip', 'C:\\Python25\\lib\\site-packages\
\orange', 'C:\\Python25\\lib\\site-packages\\orange\\OrangeWidgets',
'C:\\Python25\\lib\\site-packages\\orange\\OrangeCanvas', 'C:\
\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-
packages', 'C:\\Python25\\lib\\site-packages\\Numeric', 'C:\\Python25\
\lib\\site-packages\\PIL']

Now I have my personal programs in C:/Python25/Progs/

How do I add so that I can just do "import somefile" from anywhere in
that directory in the interpreter and it can load files from other
folders in that directory.
Add a file: \Lib\site-packages\locals.pth

with contents, path to the directory you want to add (/python25/progs/)
Sep 16 '08 #5
What about on a unix box?

Sincerely,
Michael H.


-----Original Message-----
From: Aaron "Castironpi" Brady [mailto:ca********@gmail.com]
Sent: Tuesday, September 16, 2008 12:49 PM
To: py*********@python.org
Subject: Re: How do I add permanently to Pythons sys.path?

On Sep 16, 10:13*am, cnb <circularf...@yahoo.sewrote:
>sys.path

['C:\\Python25\\Progs\\NatLangProc', 'C:\\Python25\\Lib\\idlelib', 'C:\
\Windows\\system32\\python25.zip', 'C:\\Python25\\lib\\site-packages\
\orange', 'C:\\Python25\\lib\\site-packages\\orange\\OrangeWidgets',
'C:\\Python25\\lib\\site-packages\\orange\\OrangeCanvas', 'C:\
\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-
packages', 'C:\\Python25\\lib\\site-packages\\Numeric', 'C:\\Python25\
\lib\\site-packages\\PIL']

Now I have my personal programs in C:/Python25/Progs/

How do I add so that I can just do "import somefile" from anywhere in
that directory in the interpreter and it can load files from other
folders in that directory.
Add a file: \Lib\site-packages\locals.pth

with contents, path to the directory you want to add (/python25/progs/)
Sep 16 '08 #6
cnb
On Sep 16, 7:49*pm, "Aaron \"Castironpi\" Brady"
<castiro...@gmail.comwrote:
On Sep 16, 10:13*am, cnb <circularf...@yahoo.sewrote:
>>sys.path
['C:\\Python25\\Progs\\NatLangProc', 'C:\\Python25\\Lib\\idlelib', 'C:\
\Windows\\system32\\python25.zip', 'C:\\Python25\\lib\\site-packages\
\orange', 'C:\\Python25\\lib\\site-packages\\orange\\OrangeWidgets',
'C:\\Python25\\lib\\site-packages\\orange\\OrangeCanvas', 'C:\
\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-
packages', 'C:\\Python25\\lib\\site-packages\\Numeric', 'C:\\Python25\
\lib\\site-packages\\PIL']
Now I have my personal programs in C:/Python25/Progs/
How do I add so that I can just do "import somefile" from anywhere in
that directory in the interpreter and it can load files from other
folders in that directory.

Add a file: \Lib\site-packages\locals.pth

with contents, path to the directory you want to add (/python25/progs/)


And we have a winner!
Now it works. Both doing import and loading form fiel with C-c C-l

However jsut including C:/Python/Progs wasn't enough. I had to add the
folder inside that that contains the files i needed.

so how do i add all files within progs? is there something like C:/
python25/progs/* ?
Sep 16 '08 #7
On Sep 16, 2:40*pm, "Support Desk" <m...@ipglobal.netwrote:
What about on a unix box?
Do you have write permissions on, in this case, '/opt/pkgs/python-2.0/
lib/python2.0/site-packages' ? (Or the entry in your sys.path.)
>>import sys
sys.path
['', '/opt/pkgs/python-2.0/lib/python2.0', '/opt/pkgs/python-2.0/lib/
python2.0/plat-sunos5', '/opt/pkgs/python-2.0/lib/python2.0/lib-tk', '/
opt/pkgs/python-2.0/lib/python2.0/lib-dynload', '/opt/pkgs/python-2.0/
lib/python2.0/site-packages']
>
Sincerely,
Michael H.

-----Original Message-----
From: Aaron "Castironpi" Brady [mailto:castiro...@gmail.com]
Sent: Tuesday, September 16, 2008 12:49 PM
To: python-l...@python.org
Subject: Re: How do I add permanently to Pythons sys.path?

On Sep 16, 10:13*am, cnb <circularf...@yahoo.sewrote:
>>sys.path
['C:\\Python25\\Progs\\NatLangProc', 'C:\\Python25\\Lib\\idlelib', 'C:\
\Windows\\system32\\python25.zip', 'C:\\Python25\\lib\\site-packages\
\orange', 'C:\\Python25\\lib\\site-packages\\orange\\OrangeWidgets',
'C:\\Python25\\lib\\site-packages\\orange\\OrangeCanvas', 'C:\
\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-
packages', 'C:\\Python25\\lib\\site-packages\\Numeric', 'C:\\Python25\
\lib\\site-packages\\PIL']
Now I have my personal programs in C:/Python25/Progs/
How do I add so that I can just do "import somefile" from anywhere in
that directory in the interpreter and it can load files from other
folders in that directory.

Add a file: \Lib\site-packages\locals.pth

with contents, path to the directory you want to add (/python25/progs/)

Sep 16 '08 #8
On Sep 16, 3:16*pm, cnb <circularf...@yahoo.sewrote:
On Sep 16, 7:49*pm, "Aaron \"Castironpi\" Brady"
Now I have my personal programs in C:/Python25/Progs/
How do I add so that I can just do "import somefile" from anywhere in
that directory in the interpreter and it can load files from other
folders in that directory.
Add a file: \Lib\site-packages\locals.pth
with contents, path to the directory you want to add (/python25/progs/)

And we have a winner!

Now it works. Both doing import and loading form fiel with C-c C-l

However jsut including C:/Python/Progs wasn't enough. I had to add the
folder inside that that contains the files i needed.

so how do i add all files within progs? is there something like C:/
python25/progs/* ?
You have:

c:/python/progs/abc/filea.py
c:/python/progs/abc/fileb.py
c:/python/progs/def/filed.py
c:/python/progs/def/filee.py

__init__.py in progs (empty...)
__init__.py in abc
__init__.py in def

c:/python/site-packages/lib/locals.py which contains:
c:/python/progs/

You don't need the subdirectories. You can do:

import abc
import abc.filea
from abc import filea

Sep 16 '08 #9
On Sep 16, 2:40*pm, "Support Desk" <m...@ipglobal.netwrote:
What about on a unix box?
I can't help you. I don't have access to '/opt/pkgs/python-2.0/lib/
python2.0/site-packages' (ha ha) on the one I have access to. If you
do, try the same thing.

>
Sincerely,
Michael H.

-----Original Message-----
From: Aaron "Castironpi" Brady [mailto:castiro...@gmail.com]
Sent: Tuesday, September 16, 2008 12:49 PM
To: python-l...@python.org
Subject: Re: How do I add permanently to Pythons sys.path?

On Sep 16, 10:13*am, cnb <circularf...@yahoo.sewrote:
>>sys.path
['C:\\Python25\\Progs\\NatLangProc', 'C:\\Python25\\Lib\\idlelib', 'C:\
\Windows\\system32\\python25.zip', 'C:\\Python25\\lib\\site-packages\
\orange', 'C:\\Python25\\lib\\site-packages\\orange\\OrangeWidgets',
'C:\\Python25\\lib\\site-packages\\orange\\OrangeCanvas', 'C:\
\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-
packages', 'C:\\Python25\\lib\\site-packages\\Numeric', 'C:\\Python25\
\lib\\site-packages\\PIL']
Now I have my personal programs in C:/Python25/Progs/
How do I add so that I can just do "import somefile" from anywhere in
that directory in the interpreter and it can load files from other
folders in that directory.

Add a file: \Lib\site-packages\locals.pth

with contents, path to the directory you want to add (/python25/progs/)


Sep 16 '08 #10
cnb
On Sep 16, 10:53*pm, "Aaron \"Castironpi\" Brady"
<castiro...@gmail.comwrote:
On Sep 16, 3:16*pm, cnb <circularf...@yahoo.sewrote:
On Sep 16, 7:49*pm, "Aaron \"Castironpi\" Brady"
Now I have my personal programs in C:/Python25/Progs/
How do I add so that I can just do "import somefile" from anywhere in
that directory in the interpreter and it can load files from other
folders in that directory.
Add a file: \Lib\site-packages\locals.pth
with contents, path to the directory you want to add (/python25/progs/)
And we have a winner!
Now it works. Both doing import and loading form fiel with C-c C-l
However jsut including C:/Python/Progs wasn't enough. I had to add the
folder inside that that contains the files i needed.
so how do i add all files within progs? is there something like C:/
python25/progs/* ?

You have:

c:/python/progs/abc/filea.py
c:/python/progs/abc/fileb.py
c:/python/progs/def/filed.py
c:/python/progs/def/filee.py

__init__.py in progs * (empty...)
__init__.py in abc
__init__.py in def

c:/python/site-packages/lib/locals.py *which contains:
c:/python/progs/

You don't need the subdirectories. *You can do:

import abc
import abc.filea
from abc import filea

no I can't...
Sep 16 '08 #11
On Sep 16, 4:24*pm, cnb <circularf...@yahoo.sewrote:
On Sep 16, 10:53*pm, "Aaron \"Castironpi\" Brady"

<castiro...@gmail.comwrote:
On Sep 16, 3:16*pm, cnb <circularf...@yahoo.sewrote:
On Sep 16, 7:49*pm, "Aaron \"Castironpi\" Brady"
Now I have my personal programs in C:/Python25/Progs/
How do I add so that I can just do "import somefile" from anywhere in
that directory in the interpreter and it can load files from other
folders in that directory.
Add a file: \Lib\site-packages\locals.pth
with contents, path to the directory you want to add (/python25/progs/)
And we have a winner!
Now it works. Both doing import and loading form fiel with C-c C-l
However jsut including C:/Python/Progs wasn't enough. I had to add the
folder inside that that contains the files i needed.
so how do i add all files within progs? is there something like C:/
python25/progs/* ?
You have:
c:/python/progs/abc/filea.py
c:/python/progs/abc/fileb.py
c:/python/progs/def/filed.py
c:/python/progs/def/filee.py
__init__.py in progs * (empty...)
__init__.py in abc
__init__.py in def
c:/python/site-packages/lib/locals.py *which contains:
c:/python/progs/
You don't need the subdirectories. *You can do:
import abc
import abc.filea
from abc import filea

no I can't...
Ok well here's mine:

I have

/Documents and Settings/usr/Desktop/working/imptest/

in locals.pth. These directories:

Directory of C:\Documents and Settings\usr\Desktop\working\imptest

09/16/2008 04:29 PM <DIR impt

Directory of C:\Documents and Settings\usr\Desktop\working\imptest
\impt

09/16/2008 04:29 PM <DIR abc
09/16/2008 04:29 PM <DIR defg
09/16/2008 03:40 PM 0 __init__.py
1 File(s) 0 bytes

Directory of C:\Documents and Settings\usr\Desktop\working\imptest
\impt\abc

09/16/2008 03:40 PM 13 abcmod.py
09/16/2008 03:40 PM 0 __init__.py

Directory of C:\Documents and Settings\usr\Desktop\working\imptest
\impt\defg

09/16/2008 03:40 PM 13 defmod.py
09/16/2008 03:40 PM 0 __init__.py

and this code:
>>import impt
import impt.abc
import impt.abc.abcmod
import impt.defg
import impt.defg.defmod
I understand the import behavior will change in 3.0.
Sep 16 '08 #12
cnb wrote:
no I can't...
Python has supported packages since version 1.4 or so, so I'm pretty
sure you can.

</F>

Sep 16 '08 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: ForHimself Every Man | last post by:
What's better about Rattlesnakes than Python. I'm sure there's something. What is it? This is not a troll. I'm a snake shooping and I want people's answers. I don't know beans about...
9
by: Amir Dekel | last post by:
Hi everyone, I have two problems: 1. How can I keep my changes in sys.path after closing the interpreter? 2. os.path.expanduser("~") always gives me "C:\\" instead of my homepath. I have...
3
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users...
5
by: Mathias Panzenboeck | last post by:
Hi. I wrote a small hashlib for C. Because I'm new to hashes I looked at pythons implementation and reused *some* of the code... or more the mathematical "hash-function", not really the code. ...
1
by: Frank | last post by:
Hi, I want to create some modules to use them in my programs. Now the problem is, how to add the path to these modules permanently to the python search path. For example: import sys...
0
by: sathyan8294 | last post by:
i am using vb.net 2003.i am doing my project in vb.net windows application. how do i remove selected row permanently from sql database through datagrid in vb.net windows form during runtime. for...
6
by: tedpottel | last post by:
Hi, I'm trying to create my own lib of functions, but it seems like I can only import them if they are in pythons lib folder. Example I have a folder called K:\mypython Now in the...
2
by: tedpottel | last post by:
Hi, Is their a version of pythons IDLE that will run in a dos command line? The reason is that I would like to be able to run python code interactively from my parable by connecting to my desktop...
1
Markus
by: Markus | last post by:
Currently, to automate some laborious tasks, I'm using a batch file that runs some operations. One of those operations is to update the PATH environment variable, which will point to a drive created...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.