Re: [Tutor] PYTHONPATH (Mac OS X)

2012-01-13 Thread David Rock
* Stayvoid stayv...@gmail.com [2011-12-30 16:11]:
 You don't have any option.
 You either type in the full path or you get the user to tell you
 in some way - either with a prompt or via an input argument.
 
 OK, now I get it.
 
 How can I tell this to the end-user?
 Should I write a README file or what?
 
 I've tried to run lengthcounter_lutz from the file's folder and this worked 
 out.
 cd /Users/Username/Python_modules/
 python /Users/Username/Python_modules/lengthcounter_lutz.py
 ('Lines:', 12, 'Chars:', 285)
 
 
 But I can't understand what's wrong with the second one:
 def countLines(name):
 file = open(name.__file__)
 return len(file.readlines())
 
 def countChars(name):
 return len(open(name.__file__).read())
 
 def test(name):
 return Lines:, countLines(name), Chars:, countChars(name)
 
 if __name__ == '__main__':
 import lengthcounter
 print test(lengthcounter)
 
  import lengthcounter
  lengthcounter.test(lengthcounter)
 ('Lines:', 5, 'Chars:', 885)
 

Looking at page 1119 in the learning Python book, I might venture a
guess as to where the difference lies.  You are calling test as:
test(lengthcounter), but that is not the name of a file (the name of a
file should be in quotes). lengthcounter in this case is a variable, 
not a filename.  The behavior in this case is probably undetermined.

I suggest doing a manual check on the file named lengthcounter.pyc, and
I'll bet you will find something closer to 5 lines and 885 characters.
pyc files are the bytecode version of your file that gets generated
automatically and is the code that is actually executed.

Somehow, calling the method test inside the interpreter is different
from running it on the commandline and you are picking up the pyc file.  
In either case, this format is iffy at best:

if __name__ == '__main__':
import lengthcounter
print test(lengthcounter)

should really be:

if __name__ == '__main__':
import lengthcounter
print lengthcounter.test(lengthcounter)

to avoid ambiguous behavior.

-- 
David Rock
da...@graniteweb.com


pgpc2h7KXfB8z.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PYTHONPATH (Mac OS X)

2011-12-30 Thread Stayvoid
You don't have any option.
You either type in the full path or you get the user to tell you
in some way - either with a prompt or via an input argument.

OK, now I get it.

How can I tell this to the end-user?
Should I write a README file or what?

I've tried to run lengthcounter_lutz from the file's folder and this worked out.
cd /Users/Username/Python_modules/
python /Users/Username/Python_modules/lengthcounter_lutz.py
('Lines:', 12, 'Chars:', 285)


But I can't understand what's wrong with the second one:
def countLines(name):
file = open(name.__file__)
return len(file.readlines())

def countChars(name):
return len(open(name.__file__).read())

def test(name):
return Lines:, countLines(name), Chars:, countChars(name)

if __name__ == '__main__':
import lengthcounter
print test(lengthcounter)

 import lengthcounter
 lengthcounter.test(lengthcounter)
('Lines:', 5, 'Chars:', 885)


That PYTHONPATH variable has no connection with the mess above. When
should I use it?


Thanks for your help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PYTHONPATH (Mac OS X)

2011-12-30 Thread Alan Gauld

On 30/12/11 13:11, Stayvoid wrote:


I've tried to run lengthcounter_lutz from the file's folder and this worked out.
cd /Users/Username/Python_modules/
python /Users/Username/Python_modules/lengthcounter_lutz.py



You should only have needed:

 python ./lengthcounter_lutz.py

the ./ tells Linux to use the current folder as startuing point.


('Lines:', 12, 'Chars:', 285)


But I can't understand what's wrong with the second one:
def countLines(name):
 file = open(name.__file__)
 return len(file.readlines())

def countChars(name):
 return len(open(name.__file__).read())

def test(name):
 return Lines:, countLines(name), Chars:, countChars(name)

if __name__ == '__main__':
 import lengthcounter
 print test(lengthcounter)


import lengthcounter
lengthcounter.test(lengthcounter)

('Lines:', 5, 'Chars:', 885)


Neither do I but you can debug it easily from the  prompt by calling 
the individual lines/functions. Try:


 import lengthcounter as lc
 print lc.__file__   # to check it's using the expected file
 # assuming it is...
 print (open(lc.__name__),read())   # check the contents is what we 
expect

 print ( len(open(lc.__name__),read()) )   # check the length result
 print ( len(open(lc.__name__),readlines()) )   # check the lines


That PYTHONPATH variable has no connection with the mess above. When
should I use it?


Python uses PYTHONPATH to find modules when you import them.

So when we do import lengthcounter above we dont need to be in the same 
folder as lengthcounter.py to be able to import it.


HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PYTHONPATH (Mac OS X)

2011-12-26 Thread Stayvoid
Simply that python is saying it cannot find the file.
So it is probably in a different folder to the one in which the program is 
running. You need to provide a valid path to the file,

Those files are in the same folder:
/Users/Username/Python_modules/

I don't want to write a full path here:
if __name__ == '__main__':
   print test('lengthcounter_lutz.py')

How to add this directory to the search path?

So what is it doing exactly that seems wrong?
What input? What output? What did you expect?

I have a slightly different copy of this file:

def countLines(name):
file = open(name.__file__)
return len(file.readlines())

def countChars(name):
return len(open(name.__file__).read())

def test(name):
return Lines:, countLines(name), Chars:, countChars(name)

if __name__ == '__main__':
import lengthcounter
print test(lengthcounter)

I've tried to run it in the interactive shell:

import lengthcounter as lc
lc.test(lengthcounter)

And here is the output:

('Lines:', 5, 'Chars:', 885)

But that code has 13 lines and 317 characters according to the Emacs' counter.
Where is an error?

Cheers.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PYTHONPATH (Mac OS X)

2011-12-26 Thread Dave Angel

On 12/26/2011 07:23 AM, Stayvoid wrote:

Simply that python is saying it cannot find the file.
So it is probably in a different folder to the one in which the program is 
running. You need to provide a valid path to the file,

Those files are in the same folder:
/Users/Username/Python_modules/

I don't want to write a full path here:
if __name__ == '__main__':
print test('lengthcounter_lutz.py')

How to add this directory to the search path?
Once again, there is no search path for the open() function.  You can 
either supply an absolute name (eg. starting with leading slash), or you 
can supply a path relative to the current directory.  If you're not sure 
what the current directory is, you can fetch it with something like:


import os

print os.path.abspath(os.curdir)

But if you're running the script from the terminal window, it should 
simply be the current directory for that window.  If you're running it 
from some other shell, you'd have to consult that shell's docs.





--

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PYTHONPATH (Mac OS X)

2011-12-26 Thread Alan Gauld

On 26/12/11 12:23, Stayvoid wrote:

Simply that python is saying it cannot find the file.
So it is probably in a different folder ...

Those files are in the same folder:
/Users/Username/Python_modules/


And is that where you are running the code from? That is the critical 
factor.


By just providing the filename Python assumes its in the same folder 
that you ran the program from. If you run it from somewhere else you 
*must* provide the full (or relative() path to the file. There is no 
option for Python to search for it.



I don't want to write a full path here:
if __name__ == '__main__':
print test('lengthcounter_lutz.py')


You don't have any option.
You either type in the full path or you get the user to tell you
in some way - either with a prompt or via an input argument.



I have a slightly different copy of this file:

def countLines(name):
 file = open(name.__file__)
 return len(file.readlines())

def countChars(name):
 return len(open(name.__file__).read())

def test(name):
 return Lines:, countLines(name), Chars:, countChars(name)

if __name__ == '__main__':
 import lengthcounter
 print test(lengthcounter)

I've tried to run it in the interactive shell:

import lengthcounter as lc
lc.test(lengthcounter)


Are you sure it is your version that's being picked up?
Try renaming it to something guaranteed to be unique. See if the results 
are the same.


Also I would expect the prompt to complain because you are passing 
lengthcounter as a name to the test function, but you imported 
lengthcounter as lc, so python should not know about lengthcounter 
unless you had already imported it (or another file?)

eg.

 import random as r
 random.__file__
Traceback (most recent call last):
  File stdin, line 1, in module
NameError: name 'random' is not defined


Try starting a fresh interpreter session and repeating the test.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PYTHONPATH (Mac OS X)

2011-12-25 Thread Stayvoid
Hey there!

I'm reading Lutz's Learning Python.

Here is some code from the book.

There is a module called lcclient_lutz.py:

from lengthcounter_lutz import countLines, countChars
print countLines('lengthcounter_lutz.py'), countChars('lengthcounter_lutz.py')

And there is another one called lengthcounter_lutz.py:

def countLines(name):
file = open(name)
return len(file.readlines())

def countChars(name):
return len(open(name).read())

def test(name):
return Lines:, countLines(name), Chars:, countChars(name)

if __name__ == '__main__':
print test('lengthcounter_lutz.py')

I've got an error while trying to load lcclient_lutz module:
python /Users/Username/Python_modules/lcclient_lutz.py
Traceback (most recent call last):
  File /Users/Username/Python_modules/lcclient_lutz.py, line 2, in module
print countLines('lengthcounter_lutz.py'),
countChars('lengthcounter_lutz.py')
  File /Users/Username/Python_modules/lengthcounter_lutz.py, line 2,
in countLines
file = open(name)
IOError: [Errno 2] No such file or directory: 'lengthcounter_lutz.py'

How to fix it? Is it connected with the PYTHONPATH variable?

P.S. There might be an error in the lengthcounter_lutz module, because
it makes mistakes while counting.


Kind regards.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PYTHONPATH (Mac OS X)

2011-12-25 Thread Alan Gauld

On 25/12/11 22:55, Stayvoid wrote:


There is a module called lcclient_lutz.py:

from lengthcounter_lutz import countLines, countChars
print countLines('lengthcounter_lutz.py'), countChars('lengthcounter_lutz.py')

countChars('lengthcounter_lutz.py')
   File /Users/Username/Python_modules/lengthcounter_lutz.py, line 2,
in countLines
 file = open(name)
IOError: [Errno 2] No such file or directory: 'lengthcounter_lutz.py'



How to fix it? Is it connected with the PYTHONPATH variable?


PYTHONPATH only helps Python find the files to import.
Since the error message is pointing at code insiude the imported 
functions then clearly PYTHONPATH is working just fine.



So what is the error?
Simply that python is saying it cannot find the file.
So it is probably in a different folder to the one in which the program 
is running. You need to provide a valid path to the file,



P.S. There might be an error in the lengthcounter_lutz module, because
it makes mistakes while counting.


Thats possible. Or it may e worlking to a different definition of 
success to the one you expect! Counting words and letters is quite a 
subjective past-time.


So what is it doing exactly that seems wrong?
What input? What output? What did you expect?


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PYTHONPATH (Mac OS X)

2011-12-20 Thread Alan Gauld

On 20/12/11 01:33, Stayvoid wrote:


I want to have a possibility to import modules from the folder, which
is not included in the load path.


The code and error below has nothing to do with importing modules or the 
PYTHONPATH value.



module.py
-
def testfunc(name):
   file = open(name)
   return len(file.readlines())

if __name__ == __main__:
   print testfunc(module.py)


This is simply opening the file module.py as any other file.
It does not invoke Pythons import mechanism.


Code listing (shell):
python /Users/Username/pythonmodules/module.py

NameError: name 'module.py' is not defined



Please post the full error text not a summary.
But in this case it isc complaining about the favct that you have not 
put quotes around the filename so it thinks module.py is a variable, but 
when it looks for it, it is not defined.


BTW To set PYTHONPATH in a MacOSX environment you have to edit your 
.profile or .bash_profile (I can never remember which!) and add a line like


export PYTHONPATH=/path/to/your/modules:/another/module/path/here

HTH,

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PYTHONPATH (Mac OS X)

2011-12-19 Thread Stayvoid
 Please clarify, or expand, or tell us what problem you are having or
 trying to solve.

Hi!

I want to have a possibility to import modules from the folder, which
is not included in the load path.

Example:

module.py
-
def testfunc(name):
  file = open(name)
  return len(file.readlines())

if __name__ == __main__:
  print testfunc(module.py)

Code listing (shell):
python /Users/Username/pythonmodules/module.py

NameError: name 'module.py' is not defined

Kind regards.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PYTHONPATH (Mac OS X)

2011-12-19 Thread Dave Angel

On 12/19/2011 08:33 PM, Stayvoid wrote:

Please clarify, or expand, or tell us what problem you are having or
trying to solve.

Hi!

I want to have a possibility to import modules from the folder, which
is not included in the load path.

Example:

module.py
-
def testfunc(name):
   file = open(name)
   return len(file.readlines())

if __name__ == __main__:
   print testfunc(module.py)

Code listing (shell):
python /Users/Username/pythonmodules/module.py

NameError: name 'module.py' is not defined

Kind regards.


First rule:  include the complete error message, including the traceback.

Also, make sure you copy/paste the message, not paraphrase or retype it.

Anyway, chances are the error occurs because you didn't have any quotes 
around the filename.  Python is forced to look up the name module in 
the global dictionary, and it can't find it.  Of course, the error 
message wouldn't be exactly that.



--

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] PYTHONPATH (Mac OS X)

2011-12-18 Thread Stayvoid
Hey there!

How to set it right?


Cheers!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



Re: [Tutor] PYTHONPATH (Mac OS X)

2011-12-18 Thread bob gailer

On 12/18/2011 5:45 PM, Stayvoid wrote:

Hey there!

How to set it right?

You may not get an answer as your question is pretty vague.

Please clarify, or expand, or tell us what problem you are having or 
trying to solve.


--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] pythonpath

2010-11-01 Thread Chris King

 Dear Tutors,
When I try to import a module, how can I make it look in certain 
directories for them easily.

Sincerely,
Chris
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pythonpath

2010-11-01 Thread Vince Spicer
On Mon, Nov 1, 2010 at 3:41 PM, Chris King g.nius...@gmail.com wrote:

  Dear Tutors,
When I try to import a module, how can I make it look in certain
 directories for them easily.
 Sincerely,
Chris
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor


Hello Chris

You can manage you path from within your script,

import sys
sys.path.append(/home/user/lib)

Or in bash you can edit your  $PYTHONPATH env variable
echo $PYTHONPATH


-- 
Vince Spicer


-- 
Sent from Ubuntu
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pythonpath

2010-11-01 Thread Karim

On 11/01/2010 10:41 PM, Chris King wrote:

 Dear Tutors,
When I try to import a module, how can I make it look in certain 
directories for them easily.

Sincerely,
Chris
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Hello,

PYTHONPATH environment variable set to /path/to/you/libs.

Regards
Karim
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pythonpath

2010-11-01 Thread Chris King

 On 11/1/2010 5:47 PM, Vince Spicer wrote:



On Mon, Nov 1, 2010 at 3:41 PM, Chris King g.nius.ck 
http://g.nius.ck@gmail.com http://gmail.com wrote:


 Dear Tutors,
   When I try to import a module, how can I make it look in
certain directories for them easily.
Sincerely,
   Chris
___
Tutor maillist  - Tutor@python.org mailto:Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Hello Chris

You can manage you path from within your script,

import sys
sys.path.append(/home/user/lib)

Or in bash you can edit your $PYTHONPATH env variable
echo $PYTHONPATH


--
Vince Spicer


--
Sent from Ubuntu


it didn't work
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pythonpath

2010-11-01 Thread Chris King

 On 11/1/2010 5:57 PM, Vince Spicer wrote:



On Mon, Nov 1, 2010 at 3:54 PM, Chris King g.nius.ck 
http://g.nius.ck@gmail.com http://gmail.com wrote:


On 11/1/2010 5:47 PM, Vince Spicer wrote:



On Mon, Nov 1, 2010 at 3:41 PM, Chris King g.nius.ck
http://g.nius.ck@gmail.com http://gmail.com wrote:

 Dear Tutors,
   When I try to import a module, how can I make it look in
certain directories for them easily.
Sincerely,
   Chris
___
Tutor maillist  - Tutor@python.org mailto:Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Hello Chris

You can manage you path from within your script,

import sys
sys.path.append(/home/user/lib)

Or in bash you can edit your $PYTHONPATH env variable
echo $PYTHONPATH


-- 
Vince Spicer



-- 
Sent from Ubuntu



So doing it in cmd windows will permanently change it?



the first way with work for Window,  the second is for Linux or posix 
systems


Sorry I can't help with PYTHONPATH on windows.

--
Vince Spicer


--
Sent from Ubuntu


I want a permanent change.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pythonpath

2010-11-01 Thread Vince Spicer
On Mon, Nov 1, 2010 at 3:58 PM, Chris King g.nius...@gmail.com wrote:

  On 11/1/2010 5:57 PM, Vince Spicer wrote:



 On Mon, Nov 1, 2010 at 3:54 PM, Chris King g.nius...@gmail.com wrote:

   On 11/1/2010 5:47 PM, Vince Spicer wrote:



 On Mon, Nov 1, 2010 at 3:41 PM, Chris King g.nius...@gmail.com wrote:

  Dear Tutors,
When I try to import a module, how can I make it look in certain
 directories for them easily.
 Sincerely,
Chris
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor


  Hello Chris

 You can manage you path from within your script,

  import sys
 sys.path.append(/home/user/lib)

  Or in bash you can edit your  $PYTHONPATH env variable
  echo $PYTHONPATH


 --
 Vince Spicer


  --
 Sent from Ubuntu

So doing it in cmd windows will permanently change it?



 the first way with work for Window,  the second is for Linux or posix
 systems

  Sorry I can't help with PYTHONPATH on windows.

 --
 Vince Spicer


  --
 Sent from Ubuntu

  I want a permanent change.


There is probably a Windows alternative to env variables and PYTHONPATH,
Google may help.


-- 
Vince Spicer

-- 
Sent from Ubuntu
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pythonpath

2010-11-01 Thread John
Chris,

I haven't worked on windows in ages, but I think you can set a
PYTHONPATH variable if you right click on My Computer and maybe the
advanced tab, there is a place to set ENVIRONMENT VARIABLES. Create a
new one called PYTHONPATH pointing to your directory.

-john

On Mon, Nov 1, 2010 at 10:58 PM, Chris King g.nius...@gmail.com wrote:
 On 11/1/2010 5:57 PM, Vince Spicer wrote:

 On Mon, Nov 1, 2010 at 3:54 PM, Chris King g.nius...@gmail.com wrote:

 On 11/1/2010 5:47 PM, Vince Spicer wrote:

 On Mon, Nov 1, 2010 at 3:41 PM, Chris King g.nius...@gmail.com wrote:

  Dear Tutors,
    When I try to import a module, how can I make it look in certain
 directories for them easily.
 Sincerely,
    Chris
 ___
 Tutor maillist  -  tu...@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor

 Hello Chris
 You can manage you path from within your script,
 import sys
 sys.path.append(/home/user/lib)

 Or in bash you can edit your  $PYTHONPATH env variable
 echo $PYTHONPATH

 --
 Vince Spicer

 --
 Sent from Ubuntu

 So doing it in cmd windows will permanently change it?


 the first way with work for Window,  the second is for Linux or posix
 systems
 Sorry I can't help with PYTHONPATH on windows.

 --
 Vince Spicer

 --
 Sent from Ubuntu

 I want a permanent change.

 ___
 Tutor maillist  -  tu...@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor





-- 
Configuration
``
Plone 2.5.3-final,
CMF-1.6.4,
Zope (Zope 2.9.7-final, python 2.4.4, linux2),
Python 2.6
PIL 1.1.6
Mailman 2.1.9
Postfix 2.4.5
Procmail v3.22 2001/09/10
Basemap: 1.0
Matplotlib: 1.0.0
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pythonpath

2010-11-01 Thread Vince Spicer
On Mon, Nov 1, 2010 at 4:00 PM, Vince Spicer vi...@vinces.ca wrote:



 On Mon, Nov 1, 2010 at 3:58 PM, Chris King g.nius...@gmail.com wrote:

  On 11/1/2010 5:57 PM, Vince Spicer wrote:



 On Mon, Nov 1, 2010 at 3:54 PM, Chris King g.nius...@gmail.com wrote:

   On 11/1/2010 5:47 PM, Vince Spicer wrote:



 On Mon, Nov 1, 2010 at 3:41 PM, Chris King g.nius...@gmail.com wrote:

  Dear Tutors,
When I try to import a module, how can I make it look in certain
 directories for them easily.
 Sincerely,
Chris
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor


  Hello Chris

 You can manage you path from within your script,

  import sys
 sys.path.append(/home/user/lib)

  Or in bash you can edit your  $PYTHONPATH env variable
  echo $PYTHONPATH


 --
 Vince Spicer


  --
 Sent from Ubuntu

So doing it in cmd windows will permanently change it?



 the first way with work for Window,  the second is for Linux or posix
 systems

  Sorry I can't help with PYTHONPATH on windows.

 --
 Vince Spicer


  --
 Sent from Ubuntu

  I want a permanent change.


 There is probably a Windows alternative to env variables and PYTHONPATH,
 Google may help.


 --
 Vince Spicer

 --
 Sent from Ubuntu



Sorry I don't know any developers that run Windows anymore, if you find the
solution please post it back here.

Thanks.


-- 
Vince Spicer


-- 
Sent from Ubuntu
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pythonpath

2010-11-01 Thread Walter Prins
On 1 November 2010 21:57, Chris King g.nius...@gmail.com wrote:

  On 11/1/2010 5:47 PM, Vince Spicer wrote:
 it didn't work


Then you've done something wrong.  Post the code, and/or the error message,
if any.

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pythonpath

2010-11-01 Thread Walter Prins
On 1 November 2010 21:58, Chris King g.nius...@gmail.com wrote:

  the first way with work for Window,  the second is for Linux or posix
 systems

  Sorry I can't help with PYTHONPATH on windows.


To set a PYTHONPATH in Windows, click Start, right click My computer,
click Properties, click Advanced tab/section, click Environment
variables button.  See if you can find an entry in either the User
variables or the System variables sections named PYTHONPATH.  If not, add
a new entry to User variables by clicking New, and entering the name
PYTHONPATH and whatever you want for the path.  Click OK, OK, OK and
you should be back to the desktop.  Open the Python shell, and enter:

 import sys
 print sys.path
['C:\\Python26\\Lib\\idlelib',
'C:\\Python26\\lib\\site-packages\\pip-0.8.1-py2.6.egg', 'C:\\Test',
'C:\\Python26\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib',
'C:\\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26',
'C:\\Python26\\lib\\site-packages']

As you can see have an entry C:\\Test due to the fact that I created that
as the contents of my PYTHONPATH variable.

HTH,

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pythonpath

2010-11-01 Thread Chris King

 On 11/1/2010 6:13 PM, Walter Prins wrote:



On 1 November 2010 21:58, Chris King g.nius.ck 
http://g.nius.ck@gmail.com http://gmail.com wrote:



the first way with work for Window,  the second is for Linux or
posix systems

Sorry I can't help with PYTHONPATH on windows.



To set a PYTHONPATH in Windows, click Start, right click My 
computer, click Properties, click Advanced tab/section, click 
Environment variables button.  See if you can find an entry in 
either the User  variables or the System variables sections named 
PYTHONPATH.  If not, add a new entry to User variables by clicking 
New, and entering the name PYTHONPATH and whatever you want for 
the path.  Click OK, OK, OK and you should be back to the 
desktop.  Open the Python shell, and enter:


 import sys
 print sys.path
['C:\\Python26\\Lib\\idlelib', 
'C:\\Python26\\lib\\site-packages\\pip-0.8.1-py2.6.egg', 'C:\\Test', 
'C:\\Python26\\python26.zip', 'C:\\Python26\\DLLs', 
'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-win', 
'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 
'C:\\Python26\\lib\\site-packages']


As you can see have an entry C:\\Test due to the fact that I created 
that as the contents of my PYTHONPATH variable.


HTH,

Walter


It worked!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pythonpath

2010-11-01 Thread John
hehe. yeah, I had to go check my old PC that's collecting dust on how
to navigate the 'happy dungeon' of windows wizards...

I do prefer:

export PYTHONPATH=/my/custom/dir



On Mon, Nov 1, 2010 at 11:03 PM, Vince Spicer vi...@vinces.ca wrote:


 On Mon, Nov 1, 2010 at 4:00 PM, Vince Spicer vi...@vinces.ca wrote:


 On Mon, Nov 1, 2010 at 3:58 PM, Chris King g.nius...@gmail.com wrote:

 On 11/1/2010 5:57 PM, Vince Spicer wrote:

 On Mon, Nov 1, 2010 at 3:54 PM, Chris King g.nius...@gmail.com wrote:

 On 11/1/2010 5:47 PM, Vince Spicer wrote:

 On Mon, Nov 1, 2010 at 3:41 PM, Chris King g.nius...@gmail.com wrote:

  Dear Tutors,
    When I try to import a module, how can I make it look in certain
 directories for them easily.
 Sincerely,
    Chris
 ___
 Tutor maillist  -  tu...@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor

 Hello Chris
 You can manage you path from within your script,
 import sys
 sys.path.append(/home/user/lib)

 Or in bash you can edit your  $PYTHONPATH env variable
 echo $PYTHONPATH

 --
 Vince Spicer

 --
 Sent from Ubuntu

 So doing it in cmd windows will permanently change it?


 the first way with work for Window,  the second is for Linux or posix
 systems
 Sorry I can't help with PYTHONPATH on windows.

 --
 Vince Spicer

 --
 Sent from Ubuntu

 I want a permanent change.

 There is probably a Windows alternative to env variables and PYTHONPATH,
 Google may help.

 --
 Vince Spicer
 --
 Sent from Ubuntu


 Sorry I don't know any developers that run Windows anymore, if you find the
 solution please post it back here.
 Thanks.


 --
 Vince Spicer

 --
 Sent from Ubuntu

 ___
 Tutor maillist  -  tu...@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor





-- 
Configuration
``
Plone 2.5.3-final,
CMF-1.6.4,
Zope (Zope 2.9.7-final, python 2.4.4, linux2),
Python 2.6
PIL 1.1.6
Mailman 2.1.9
Postfix 2.4.5
Procmail v3.22 2001/09/10
Basemap: 1.0
Matplotlib: 1.0.0
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pythonpath

2010-11-01 Thread Steven D'Aprano

Chris King wrote:


it didn't work


Define it and didn't work.

What did you try? What happened when you tried it?



--
Steven


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pythonpath

2010-11-01 Thread Emile van Sebille

On 11/1/2010 2:41 PM Chris King said...

Dear Tutors,
When I try to import a module, how can I make it look in certain
directories for them easily.
Sincerely,
Chris



I'm not sure it's still the preferred way of setting sys.path, but 
site.py sets sys.path and contains info on *.pth files and other methods 
used.


Emile


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PYTHONPATH-corrected

2009-07-01 Thread Alan Gauld


Steve Willoughby st...@alchemy.com wrote


in directories for chapers. Now I am on modules, and some
are reused in later chapters. I have set up a directory for
the modules. How do I add it to my PYTHONPATH?



So, for example, in a bash/sh shell, you'd say:

export PYTHONPATH=/path/to/my/modules


And you can add multiple directories by separating them with colons:

export 
PYTHONPATH=/path/to/my/modules:/path/to/more/modules:/path/ytoyet/more


HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] PYTHONPATH

2009-06-30 Thread Bob Rea
In working my way through the book on python, i am working 
in directories for chapers. Now I am on modules, and some 
are reused in later chapters. I have set up a directory for 
the modules. How do I add it to my PYTHONPATH?
I can use sys.path.append but that only lasts for the 
session.

-- 
Bob Rea
mailto:pet...@petard.us
http://www.petard.us
http://www.petard.us/blog
http://www.petard.us/gallery
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] PYTHONPATH-corrected

2009-06-30 Thread Bob Rea
In working my way through the book on python, I am working 
in directories for chapers. Now I am on modules, and some 
are reused in later chapters. I have set up a directory for 
the modules. How do I add it to my PYTHONPATH?
I can use sys.path.append but that only lasts for the 
session.

This is on a suse linux 10 box

-- 
Bob Rea
mailto:pet...@petard.us
http://www.petard.us
http://www.petard.us/blog
http://www.petard.us/gallery
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PYTHONPATH-corrected

2009-06-30 Thread Steve Willoughby
On Tue, Jun 30, 2009 at 02:33:27PM -0400, Bob Rea wrote:
 In working my way through the book on python, I am working 
 in directories for chapers. Now I am on modules, and some 
 are reused in later chapters. I have set up a directory for 
 the modules. How do I add it to my PYTHONPATH?
 I can use sys.path.append but that only lasts for the 
 session.

You set the variable in your system's environment, which is
platform-dependent.  For Linux, you'd typically put a line
in your ~/.profile or ~/.cshrc or ~/.login or ~/.bashrc or
whatever your shell uses per your account set up.  

So, for example, in a bash/sh shell, you'd say:

export PYTHONPATH=/path/to/my/modules

or for csh:

setenv PYTHONPATH /path/to/my/modules

Then starting the next time you log in, that will be set
in your environment for you.

 This is on a suse linux 10 box
 
 -- 
 Bob Rea
 mailto:pet...@petard.us
 http://www.petard.us
 http://www.petard.us/blog
 http://www.petard.us/gallery
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

-- 
Steve Willoughby|  Using billion-dollar satellites
st...@alchemy.com   |  to hunt for Tupperware.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor