Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25844 > unrolled thread
| Started by | Lipska the Kat <lipska@lipskathekat.com> |
|---|---|
| First post | 2012-07-23 11:02 +0100 |
| Last post | 2012-07-24 03:49 -0400 |
| Articles | 9 — 5 participants |
Back to article view | Back to comp.lang.python
python package confusion Lipska the Kat <lipska@lipskathekat.com> - 2012-07-23 11:02 +0100
Re: python package confusion Dave Angel <d@davea.name> - 2012-07-23 06:19 -0400
Re: python package confusion Lipska the Kat <lipska@lipskathekat.com> - 2012-07-23 11:54 +0100
Re: python package confusion Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-07-23 06:22 -0400
Re: python package confusion Lipska the Kat <lipska@lipskathekat.com> - 2012-07-23 12:02 +0100
Re: python package confusion David <bouncingcats@gmail.com> - 2012-07-23 21:16 +1000
Re: python package confusion Lipska the Kat <lipska@lipskathekat.com> - 2012-07-23 12:43 +0100
Re: python package confusion Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-24 05:38 +0000
Re: python package confusion Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-07-24 03:49 -0400
| From | Lipska the Kat <lipska@lipskathekat.com> |
|---|---|
| Date | 2012-07-23 11:02 +0100 |
| Subject | python package confusion |
| Message-ID | <BsCdnb3NJ_bOvJDNnZ2dnUVZ7rmdnZ2d@bt.com> |
Hello again pythoners
I'm trying to understand the python package stuff
I have the following directory
/home/lipska/python/dev/mods
In this directory I have two files, both executable
----------------------
#! /usr/bin/env python3.2
# fibo.py Fibonacci numbers module
def fib(n): # write Fibonacci series up to n
a, b = 0, 1
while b < n:
print(b, end=' ')
a, b = b, a+b
print()
----------------------
#! /usr/bin/env python3.2
# test.py fibo module test program
import fibo
fibo.fib(1000)
-----------------------
The PYTHONPATH ev is set to /home/lipska/python/dev/mods:.
in .bashrc
The following interactive session works thusly
lipska@ubuntu:~/python/dev/mods$ python3.2
Python 3.2.3 (default, Jul 17 2012, 14:23:10)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import fibo
>>> fibo.fib(1000)
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
>>>
However if I try and run test.py as an executable I get the following error
lipska@ubuntu:~/python/dev/mods$ test.py
Traceback (most recent call last):
File "./test.py", line 5, in <module>
fib(1000)
NameError: name 'fib' is not defined
if I print sys.path I get the following
>>> print(sys.path)
['', '/usr/local/lib/python32.zip', '/usr/local/lib/python3.2',
'/usr/local/lib/python3.2/plat-linux2',
'/usr/local/lib/python3.2/lib-dynload',
'/home/lipska/.local/lib/python3.2/site-packages',
'/usr/local/lib/python3.2/site-packages']
The documentation states that ...
sys.path is initialized from these locations:
the directory containing the input script (or the current directory).
PYTHONPATH (a list of directory names, with the same syntax as the
shell variable PATH).
But apparently the additional locations I specify in .bashrc are not
being added to sys.path
I also have an empty file __init__.py in the mods directory
Not sure what I'm doing wrong here
Any help much appreciated.
Lipska
--
Lipska the Kat: Troll hunter, Sandbox destroyer
and Farscape dreamer of Aeryn Sun.
[toc] | [next] | [standalone]
| From | Dave Angel <d@davea.name> |
|---|---|
| Date | 2012-07-23 06:19 -0400 |
| Message-ID | <mailman.2457.1343038791.4697.python-list@python.org> |
| In reply to | #25844 |
On 07/23/2012 06:02 AM, Lipska the Kat wrote: > Hello again pythoners > > I'm trying to understand the python package stuff > > I have the following directory > > /home/lipska/python/dev/mods > > In this directory I have two files, both executable > > ---------------------- > > #! /usr/bin/env python3.2 > > # fibo.py Fibonacci numbers module > > def fib(n): # write Fibonacci series up to n > a, b = 0, 1 > while b < n: > print(b, end=' ') > a, b = b, a+b > print() > > ---------------------- > > #! /usr/bin/env python3.2 > > # test.py fibo module test program > > import fibo > > fibo.fib(1000) > > ----------------------- > > The PYTHONPATH ev is set to /home/lipska/python/dev/mods:. > in .bashrc > > The following interactive session works thusly > > lipska@ubuntu:~/python/dev/mods$ python3.2 > Python 3.2.3 (default, Jul 17 2012, 14:23:10) > [GCC 4.6.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import fibo > >>> fibo.fib(1000) > 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 > >>> > > However if I try and run test.py as an executable I get the following > error > > lipska@ubuntu:~/python/dev/mods$ test.py > Traceback (most recent call last): > File "./test.py", line 5, in <module> > fib(1000) > NameError: name 'fib' is not defined > That line isn't the way you showed it in the source. You showed us source as fibo.fib(1000), and the error message shows it as fib(1000) So you're either cutting & pasting wrong, or you have two test.py files. -- DaveA
[toc] | [prev] | [next] | [standalone]
| From | Lipska the Kat <lipska@lipskathekat.com> |
|---|---|
| Date | 2012-07-23 11:54 +0100 |
| Message-ID | <4r6dneYzruLQsJDNnZ2dnUVZ8u2dnZ2d@bt.com> |
| In reply to | #25845 |
On 23/07/12 11:19, Dave Angel wrote: > On 07/23/2012 06:02 AM, Lipska the Kat wrote: >> Hello again pythoners snip > That line isn't the way you showed it in the source. You showed us > source as fibo.fib(1000), and the error message shows it as fib(1000) > > So you're either cutting& pasting wrong, or you have two test.py files. jeez, you are right. I must be getting old. <embarrased> Apologies for wasting your time. Lipska -- Lipska the Kat: Troll hunter, Sandbox destroyer and Farscape dreamer of Aeryn Sun.
[toc] | [prev] | [next] | [standalone]
| From | Devin Jeanpierre <jeanpierreda@gmail.com> |
|---|---|
| Date | 2012-07-23 06:22 -0400 |
| Message-ID | <mailman.2458.1343039009.4697.python-list@python.org> |
| In reply to | #25844 |
On Mon, Jul 23, 2012 at 6:02 AM, Lipska the Kat <lipska@lipskathekat.com> wrote: > The PYTHONPATH ev is set to /home/lipska/python/dev/mods:. > in .bashrc Did you export it? Show us your .bashrc, or the relevant line in it exactly. (And make sure that it isn't defined multiple times). Also adding . to the import search path is probably a bad diea. > lipska@ubuntu:~/python/dev/mods$ test.py > Traceback (most recent call last): > File "./test.py", line 5, in <module> > fib(1000) > NameError: name 'fib' is not defined Neither of the files you described in your email message contain the line "fib(1000)", so you pasted the wrong files. > I also have an empty file __init__.py in the mods directory This only matters if you want to "import mods". -- Devin
[toc] | [prev] | [next] | [standalone]
| From | Lipska the Kat <lipska@lipskathekat.com> |
|---|---|
| Date | 2012-07-23 12:02 +0100 |
| Message-ID | <et6dnWSlfuqzspDNnZ2dnUVZ7sudnZ2d@bt.com> |
| In reply to | #25846 |
On 23/07/12 11:22, Devin Jeanpierre wrote: > On Mon, Jul 23, 2012 at 6:02 AM, Lipska the Kat<lipska@lipskathekat.com> wrote: >> The PYTHONPATH ev is set to /home/lipska/python/dev/mods:. >> in .bashrc > > Did you export it? Show us your .bashrc, or the relevant line in it > exactly. (And make sure that it isn't defined multiple times). forgot to export it <stupid> <stupid> <stupid> > Also adding . to the import search path is probably a bad diea. I removed it >> lipska@ubuntu:~/python/dev/mods$ test.py >> Traceback (most recent call last): >> File "./test.py", line 5, in<module> >> fib(1000) >> NameError: name 'fib' is not defined > Neither of the files you described in your email message contain the > line "fib(1000)", so you pasted the wrong files. See grovelling apology in other reply > >> I also have an empty file __init__.py in the mods directory > > This only matters if you want to "import mods". huh .. OK, I'll read again Thanks for taking the time to reply It all works now Lipska <slinks away to hide> -- Lipska the Kat: Troll hunter, Sandbox destroyer and Farscape dreamer of Aeryn Sun.
[toc] | [prev] | [next] | [standalone]
| From | David <bouncingcats@gmail.com> |
|---|---|
| Date | 2012-07-23 21:16 +1000 |
| Message-ID | <mailman.2459.1343042194.4697.python-list@python.org> |
| In reply to | #25848 |
On 23/07/2012, Lipska the Kat <lipska@lipskathekat.com> wrote: > Hello again pythoners [snip] > Any help much appreciated. Hi Lipska Glad you got it sorted. In case you are not aware of this: Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor The tutor list caters specifically for requests for basic assistance such as you made in this thread, and code review such as in your thread prior. It too is a busy list, and many of the people who have responded to your previous threads here are also present there, so you'll get the same high quality answers there too. By the way, I had a followup to my previous message to you re git, and emailed it to you directly because it would be off-topic here, but the email bounced. It seems that you are displaying an invalid email address, at least here I get: $ ping lipskathekat.com ping: unknown host lipskathekat.com So if you are interested in that, feel free to email me directly, or not as you wish.
[toc] | [prev] | [next] | [standalone]
| From | Lipska the Kat <lipska@lipskathekat.com> |
|---|---|
| Date | 2012-07-23 12:43 +0100 |
| Message-ID | <EtOdnZWjx69qpZDNnZ2dnUVZ8m-dnZ2d@bt.com> |
| In reply to | #25849 |
On 23/07/12 12:16, David wrote: > On 23/07/2012, Lipska the Kat<lipska@lipskathekat.com> wrote: > >> Hello again pythoners > [snip] > > Any help much appreciated. > > Hi Lipska > > Glad you got it sorted. > > In case you are not aware of this: > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor I'll certainly look into it, thanks. It was more a problem of trying to do too many things at once and doing none of them well. Pathetic excuse I know but it's the best I've got. :-( > So if you are interested in that, feel free to email me directly, or > not as you wish. I've sent you message Lipska -- Lipska the Kat: Troll hunter, Sandbox destroyer and Farscape dreamer of Aeryn Sun.
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2012-07-24 05:38 +0000 |
| Message-ID | <500e34c8$0$1779$c3e8da3$76491128@news.astraweb.com> |
| In reply to | #25846 |
On Mon, 23 Jul 2012 06:22:45 -0400, Devin Jeanpierre wrote: > Also adding . to the import search path is probably a bad diea. I don't know about a bad idea or not, but it is certainly redundant, because Python automatically adds '' (equivalent to '.') to the very start of the search path. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Devin Jeanpierre <jeanpierreda@gmail.com> |
|---|---|
| Date | 2012-07-24 03:49 -0400 |
| Message-ID | <mailman.2520.1343116214.4697.python-list@python.org> |
| In reply to | #25953 |
On Tue, Jul 24, 2012 at 1:38 AM, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote: > I don't know about a bad idea or not, but it is certainly redundant, > because Python automatically adds '' (equivalent to '.') to the very > start of the search path. No, it only does that if Python is reading commands from stdin, or if Python was run with the -c option, or maybe some other situations. It doesn't do it if you just run a program, as in "python myfile.py". -- Devin
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web