Modules... paths... newbie confusion

M

MrBlueSky

I wonder if someone could clarify how Python "knows" where modules are
- or at least point to some documentation that might help me? Here's
what I've been trying:

I've installed Python 2.4 Windows, and have also installed tkinter,
pmw, cx_Oracle, mssql and pytz (phew!) all under my c:\python24 folder.

But when I try to "import pytz" or "import MSSQL" in a Python shell
(via IDLE) it's not recognised - yet "import Tkinter", "import Pmw" and
"import cx_Oracle" all work.

I've experimented with "sys.path" to get the import of pytz to work,
but without success so far.

I feel as if I'm missing some key piece of information on how this all
fits together! Please, help!

John
 
L

Licheng Fang

MrBlueSky said:
I wonder if someone could clarify how Python "knows" where modules are
- or at least point to some documentation that might help me? Here's
what I've been trying:

I've installed Python 2.4 Windows, and have also installed tkinter,
pmw, cx_Oracle, mssql and pytz (phew!) all under my c:\python24 folder.

But when I try to "import pytz" or "import MSSQL" in a Python shell
(via IDLE) it's not recognised - yet "import Tkinter", "import Pmw" and
"import cx_Oracle" all work.

I've experimented with "sys.path" to get the import of pytz to work,
but without success so far.

I feel as if I'm missing some key piece of information on how this all
fits together! Please, help!

John

You may have to add the path of the module to a system environment
variable "PYTHONPATH" to make it work.
 
S

Sibylle Koczian

MrBlueSky said:
I wonder if someone could clarify how Python "knows" where modules are
- or at least point to some documentation that might help me? Here's
what I've been trying:

I've installed Python 2.4 Windows, and have also installed tkinter,
pmw, cx_Oracle, mssql and pytz (phew!) all under my c:\python24 folder.

But when I try to "import pytz" or "import MSSQL" in a Python shell
(via IDLE) it's not recognised - yet "import Tkinter", "import Pmw" and
"import cx_Oracle" all work.

Normally extensions should go into a subdirectory of
c:\python24\Lib\site-packages. Everything that comes with a windows
installer usually installs itself exactly there. In those cases no
messing about with PYTHONPATH or sys.path should be necessary.

HTH
Koczian
 
M

MrBlueSky

Thanks for the suggestions, folks..

site-packages
~~~~~~~~~~
OK, I'm been trying to get MSSQL into c:\Python24\lib\site-packages.
MSSQL comes (as a tar'd, zip'd file) with a folder hierarchy with
MSSQL.py at the top level and then bin\python2.3\mssqldb.pyd. If I
try and copy this folder hierarchy into site-packages and "import
MSSQL" then it recognises MSSQL.py but fails to import mssqldb, as
that's imported from MSSQL.py.

I've noticed a setup.py in the MSSQL folder, but it looks like it has
odd hard-coded paths in it (D:\...) and anyway when I tried to run it,
I found the Usage message less than helpful!

I really apologise if this is Bleeding Obvious to everyone else - is
there a web page that will explain all this so the lightbulb will go on
over my head?!

John
 
S

Steve Holden

MrBlueSky said:
Thanks for the suggestions, folks..

site-packages
~~~~~~~~~~
OK, I'm been trying to get MSSQL into c:\Python24\lib\site-packages.
MSSQL comes (as a tar'd, zip'd file) with a folder hierarchy with
MSSQL.py at the top level and then bin\python2.3\mssqldb.pyd. If I
try and copy this folder hierarchy into site-packages and "import
MSSQL" then it recognises MSSQL.py but fails to import mssqldb, as
that's imported from MSSQL.py.

I've noticed a setup.py in the MSSQL folder, but it looks like it has
odd hard-coded paths in it (D:\...) and anyway when I tried to run it,
I found the Usage message less than helpful!

I really apologise if this is Bleeding Obvious to everyone else - is
there a web page that will explain all this so the lightbulb will go on
over my head?!
It's usually considered acceptable to tweak the setup.py file if it has
to know where specific things like libraries exist on your machine.
Usually the file will be setup up to find them in the most obvious
places (so I don't know what D:... paths are doing in there).

In other words, it's OK to fix setup.py so it runs!

You won;t get MySQLdb to run without running the setup.py since IIRC
there's a compile step for a C library (and it's that compile step that
needs to be able to find the MySQL client libraries).

regards
Steve
 
S

Sibylle Koczian

Steve said:
You won;t get MySQLdb to run without running the setup.py since IIRC
there's a compile step for a C library (and it's that compile step that
needs to be able to find the MySQL client libraries).
But MySQLdb comes with a windows installer. No need to tweak anything.
Sometimes you've got to choose between a slightly older version without
install worries and the newest source, but not at the moment.
 
D

Dennis Lee Bieber

OK, I'm been trying to get MSSQL into c:\Python24\lib\site-packages.
MSSQL comes (as a tar'd, zip'd file) with a folder hierarchy with
MSSQL.py at the top level and then bin\python2.3\mssqldb.pyd. If I
try and copy this folder hierarchy into site-packages and "import
MSSQL" then it recognises MSSQL.py but fails to import mssqldb, as
that's imported from MSSQL.py.
Presuming a 2.3 PYD is compatible with a 2.4 interpreter...

I'd say: put the MSSQL.py somewhere in ...\Lib\site-packages...
put the mssqldb.pyd somewhere in the same location (or maybe
....\DLLs, though that is more for the built-ins of the install)
--
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/
 
D

Dennis Lee Bieber

You won;t get MySQLdb to run without running the setup.py since IIRC
there's a compile step for a C library (and it's that compile step that
needs to be able to find the MySQL client libraries).
How'd we get from MSSQL to MySQLdb?
--
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/
 
M

MrBlueSky

Well thank you all... that's all very helpful (apart from the brief
diversion into MySQL, but even that was instructive!).

Your comments about "setup.py" prompted me to read the pytz README.txt
a bit more carefully and there it says to run "python setup.py
install". And this copies stuff into site-packages. So it's all
starting to come together and make a bit more sense to me, hurrah!

There's no README.txt with MSSQL, and "python setup.py install" gave me
a compilation error:
"c:\Python24\MSSQL-0.09\mssqldb.h(16) : fatal error C1083: Cannot open
include file: 'sqlfront.h'". I suspect I'm missing some MS SQL Server
developer stuff.

Copying the files myself to site-packages didn't work either: there's
only a mssqldb.pyd file, no .py or .pyc file. And as you pointed out,
there's no 2.4 folder so I'm a bit worried about compatibility.

So I abandoned this library and decided to try another SQL Server
library instead. I tried pymssql and it came with a Windows installer
so I didn't need to run setup.py, which meant I didn't need the MS SQL
Server developer stuff. Worked First Time!

To conclude: I've got all the answers I needed and have acquired some
useful understanding... thank you very much indeed!
 

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
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top