No module named urllib

H

HMS Surprise

I edited environment varialbes and have added C:\Python25\Lib to
PYTHONPATH but get the no module message when the statement

import urllib

is executed.

Even tried copying the urllib file to my working directory.

Any suggestions?

Thanks,

jh
 
J

Jorge Godoy

HMS Surprise said:
I edited environment varialbes and have added C:\Python25\Lib to
PYTHONPATH but get the no module message when the statement

import urllib

is executed.

Even tried copying the urllib file to my working directory.

Any suggestions?

No messages is good! :)

If you got any error messages then you'd have a problem.
 
H

HMS Surprise

No messages is good! :)

If you got any error messages then you'd have a problem.

Perhaps I should have put qoutes in my sentence.

I get the "no module message named urllib".
 
J

Jorge Godoy

HMS Surprise said:
Perhaps I should have put qoutes in my sentence.

Or I should have read it slowly. ;-)
I get the "no module message named urllib".

Can you please

import sys
print sys.path

and put the answer here on the newsgroup?
 
J

John Machin

I edited environment varialbes and have added C:\Python25\Lib to
PYTHONPATH but get the no module message when the statement

That directory should already be in sys.path after a normal Python
install. Likewise the PYTHONPATH environment variable should be
undefined:

DOS_prompt> set PYTHONPATH
Environment variable PYTHONPATH not defined

What was already in PYTHONPATH before you added something?
Why did you think you needed to change things?
 
H

HMS Surprise

Or I should have read it slowly. ;-)


Can you please

import sys
print sys.path

and put the answer here on the newsgroup?

Thanks for posting.

Ah, there is the problem. Now how to fix it? I am running my program
from maxq which generates jython scripts. It is not looking at my
PYTHONPATH as

sys.path = ['.', 'C:\\maxq\\lib\\Lib', 'C:\\maxq\\jython']

However I copied the urllib file to the directory with the scripts so
thought it should pick it up there.

jh
 
H

HMS Surprise

That directory should already be in sys.path after a normal Python
install. Likewise the PYTHONPATH environment variable should be
undefined:

DOS_prompt> set PYTHONPATH
Environment variable PYTHONPATH not defined

What was already in PYTHONPATH before you added something?
Why did you think you needed to change things?

Only what I added before:
..; c:\maxq\bin\testScripts; c:\maxq\bin;c:\maxq\jython
 
H

HMS Surprise

Since sys.path = ['.', 'C:\\maxq\\lib\\Lib', 'C:\\maxq\\jython'] I
copied urllib to c:\maxq\lib\Lib.

Now I get the error -

Traceback (innermost last):
File "<string>", line 5, in ?
File "C:\maxq\lib\Lib\urllib.py", line 1148
_hextochr = dict(('%02x' % i, chr(i)) for i in range(256))
^
SyntaxError: invalid syntax
 
J

Jorge Godoy

HMS Surprise said:
Since sys.path = ['.', 'C:\\maxq\\lib\\Lib', 'C:\\maxq\\jython'] I
copied urllib to c:\maxq\lib\Lib.

Now I get the error -

Traceback (innermost last):
File "<string>", line 5, in ?
File "C:\maxq\lib\Lib\urllib.py", line 1148
_hextochr = dict(('%02x' % i, chr(i)) for i in range(256))
^
SyntaxError: invalid syntax
Traceback (most recent call last):
 
J

John Machin

Only what I added before:
.; c:\maxq\bin\testScripts; c:\maxq\bin;c:\maxq\jython

You have somehow managed to *REPLACE* the whole of sys.path with those
4 directories. Have you fiddled with PYTHONHOME as well? [You
shouldn't].

Go to a DOS-prompt and type
set PYTHONPATH
set PYTHONHOME
and tell us what you see.
 
H

HMS Surprise

HMS Surprise said:
Since sys.path = ['.', 'C:\\maxq\\lib\\Lib', 'C:\\maxq\\jython'] I
copied urllib to c:\maxq\lib\Lib.
Now I get the error -
Traceback (innermost last):
File "<string>", line 5, in ?
File "C:\maxq\lib\Lib\urllib.py", line 1148
_hextochr = dict(('%02x' % i, chr(i)) for i in range(256))
^
SyntaxError: invalid syntax

Traceback (most recent call last):
{'a': 1}

Using the 18.5.2 Examples and a few lines added in

from CompactTest import CompactTest
import sys
print sys.path
import urllib

class login(CompactTest):
# Recorded test actions.
def runTest(self):
self.msg('Test started')

opener = urllib.FancyURLopener({})
f = opener.open("http://www.python.org/")
f.read()


# Code to load and run the test
if __name__ == 'main':
login('login').Run()
 
C

Carsten Haese

Since sys.path = ['.', 'C:\\maxq\\lib\\Lib', 'C:\\maxq\\jython'] I
copied urllib to c:\maxq\lib\Lib.

Now I get the error -

Traceback (innermost last):
File "<string>", line 5, in ?
File "C:\maxq\lib\Lib\urllib.py", line 1148
_hextochr = dict(('%02x' % i, chr(i)) for i in range(256))
^
SyntaxError: invalid syntax

The urllib.py you're using is not compatible with the Python you're
using. The snippet above uses Python 2.4+ syntax, and Jython's syntax is
at 2.1 (stable) or 2.2 (beta).
 
H

HMS Surprise

Since sys.path = ['.', 'C:\\maxq\\lib\\Lib', 'C:\\maxq\\jython'] I
copied urllib to c:\maxq\lib\Lib.
Now I get the error -
Traceback (innermost last):
File "<string>", line 5, in ?
File "C:\maxq\lib\Lib\urllib.py", line 1148
_hextochr = dict(('%02x' % i, chr(i)) for i in range(256))
^
SyntaxError: invalid syntax

The urllib.py you're using is not compatible with the Python you're
using. The snippet above uses Python 2.4+ syntax, and Jython's syntax is
at 2.1 (stable) or 2.2 (beta).

Thanks for posting. How does one ensure (or even detect) that their
libraries are compatible?

I loaded this library as part of Python 2.5.

Thanks,

jh
 
C

Carsten Haese

Thanks for posting. How does one ensure (or even detect) that their
libraries are compatible?

You ensure that by taking the library from the version of Python that
you're running.
I loaded this library as part of Python 2.5.

That's too new. Since you're using Jython, you're running either 2.1 or
2.2 depending on whether you've installed the stable version or the beta
version. Go grab a Python distribution of the correct version and get
the modules you need from there. Note this, though:

http://www.jython.org/Project/installation.html#can-t-access-standard-python-modules :
"Not all the modules form CPython is available in Jython. Some modules
require a C language dynamic link library that doesn't exists in java.
Other modules are missing from Jython just because nobody have had a
need for it before and no-one have tested the CPython module with
Jython. If you discover that you are missing a module, try to copy
the .py file from a CPython distribution to a directory on your Jython
sys.path. If that works you are set. If it doesn't work, try asking on
jython-users mailing list."

To summarize, you could be looking at a rather deep rabbit hole of
possibly unsatisfiable dependencies.

To summarize the summary, are you sure you need to use Jython instead of
standard CPython?

Good luck,
 
H

HMS Surprise

To summarize the summary, are you sure you need to use Jython instead of
standard CPython?

Thanks for all your help Carsten, you have been more than patient with
me.

To answer your question I must admit I do not know. I am trying to use
a tool called maxq (maxq.tigris.org) that has limited documentation,
or limited in the depth needed by a python/jython neophyte such as me.
Maxq acts an http proxy and generates jython scripts for playback
testing of web apps. So far I have gained a lot of ground referring to
python documentation and even testing code snippets in python shells.
So lacking the knowledge of what is jython/maxq/python and being of at
best moderate intellect I find myself easily overwhelmed and
generally not sure what must be used where. Maxq does not have a tool
for parsing the web pages, therefore I wanted to add some library
calls to pick off some timestamps I must have. Perhaps I should start
looking for another tool, such as twill maybe.

I will fetch an older python and see if that helps.

Thanks again,

jh
 
H

HMS Surprise

Thanks for all your help Carsten, you have been more than patient with
me.

To answer your question I must admit I do not know. I am trying to use
a tool called maxq (maxq.tigris.org) that has limited documentation,
or limited in the depth needed by a python/jython neophyte such as me.
Maxq acts an http proxy and generates jython scripts for playback
testing of web apps. So far I have gained a lot of ground referring to
python documentation and even testing code snippets in python shells.
So lacking the knowledge of what is jython/maxq/python and being of at
best moderate intellect I find myself easily overwhelmed and
generally not sure what must be used where. Maxq does not have a tool
for parsing the web pages, therefore I wanted to add some library
calls to pick off some timestamps I must have. Perhaps I should start
looking for another tool, such as twill maybe.

I will fetch an older python and see if that helps.

Thanks again,

jh

Thanks again, Carsten. Using v2.2.3 got me past the urllib error.

jh
 
D

Dennis Lee Bieber

So lacking the knowledge of what is jython/maxq/python and being of at
best moderate intellect I find myself easily overwhelmed and
generally not sure what must be used where. Maxq does not have a tool
for parsing the web pages, therefore I wanted to add some library

Note that, since you are using Jython, you may have access to all
the Java libraries (I've not used Jython, so I'm not sure -- the Jython
home page states "... can be used to interact with Java packages"). If
so, there may be something in the Java standard class libraries that
does what you need. Find a copy of the Java Nutshell (and maybe the Java
Foundation Classes) and skim them for the functionality you are trying
to implement.

In one respect, you have to learn the libraries of TWO languages --
a four-updates old Python, and Java; while learning the syntax of that
old Python.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top