Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 2nd, 2004, 02:38 PM
DevHims DevHims is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 27 DevHims User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation how to add User defined Module? so, i can use that in other python script.

Hii Friends,

I am using Python2.3. Here, I am trying to use module filelib(developed by me) in other python script. But when i am trying to import it it gives me error that
ImportError: No module named filelib

I also copied it in Python directory. And also in python23\lib dir. Still it is not working.

Can anybody give me some guidence or reference link for this. ?

Thanks in advance.

DevHims

Reply With Quote
  #2  
Old June 2nd, 2004, 10:25 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,547 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 109876 Folding Title: Super Ultimate Folder - Level 1Folding Points: 109876 Folding Title: Super Ultimate Folder - Level 1Folding Points: 109876 Folding Title: Super Ultimate Folder - Level 1Folding Points: 109876 Folding Title: Super Ultimate Folder - Level 1Folding Points: 109876 Folding Title: Super Ultimate Folder - Level 1Folding Points: 109876 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 1 h 43 m 50 sec
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
Quote:
Originally Posted by DevHims
Hii Friends,

I am using Python2.3. Here, I am trying to use module filelib(developed by me) in other python script. But when i am trying to import it it gives me error that
ImportError: No module named filelib

I also copied it in Python directory. And also in python23\lib dir. Still it is not working.

Can anybody give me some guidence or reference link for this. ?

Thanks in advance.

DevHims


Put it in site-package - dont know if this thread is related to the recent one, but anyways.. if your answer still stands.. then like i said.. put it in site-package

Reply With Quote
  #3  
Old June 3rd, 2004, 03:26 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
Is the module in the same directory as your other script?

Does
python filelib.py
work?

Quote:
The module filename must end in .py.


The program that imports your module will first search the current working directory and then the PYTHONPATH. On my machine:
Code:
>>> import sys
>>> sys.path
['C:\\PYTHON23\\Lib\\idlelib', 'C:\\WINDOWS\\System32\\python23.zip', 'C:\\PYTHON23', 'C:\\Python23\\DLLs', 'C:\\Python23\\lib', 'C:\\Python23\\lib\\plat-win', 'C:\\Python23\\lib\\lib-tk', 'C:\\Python23\\lib\\site-packages']
>>> 


What happens when you import the module manually within the Python shell? That should work just as well.

Grim
__________________
*** Experimental Python Markup CGI V2 ***

Reply With Quote
  #4  
Old June 3rd, 2004, 09:41 AM
DevHims DevHims is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 27 DevHims User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hii Grim,

When i tried on python shell for filelib module, it did not work. It gives me same error " No module named filelib". One more thing is, filelib is developed in older version of python. Not using python 2.3. That could be reasion. I am not sure.

What do u think??

DevHims

Reply With Quote
  #5  
Old June 3rd, 2004, 10:10 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
If it is a compiled C library then it has to be recreated for that version of python.

If not then ...
Is filelib a python module text file?
Is it called filelib.py?
Is it in the same dirctory as python or in a directory of the python path?

Grim

Reply With Quote
  #6  
Old June 3rd, 2004, 11:43 AM
DevHims DevHims is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 27 DevHims User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hey Grim,

It is python text file.It is developed in python 1.2 version. I have filelib.py and also compiled filelib.pyc. I copied both files in python library and also tried with python path Directories. Still it is not working.

What do u suggest? I do not understand why it is not finding it, even though it is in Python folder? I do not have any clue further.

Do u have any other way to make it work?

DevHims

Reply With Quote
  #7  
Old June 3rd, 2004, 12:11 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
Whether you are running this in Windows or Linux:
Open a command window (or UNIX terminal) and change directory to wherever you have the filelib.py file. In the command window type python and then type

import filelib

If you are in the same directory as the file then python should find it.

(You do have permission to read the file don't you? Under Linux at least you get "No module named ..." if you don't have read permission rather than any read permission error.)

If it is a valid file this should succeed.

It will load into later versions of python without a problem. (I cannot guarantee the code will work though). A new pyc file Will be created for the current version of python if it is imported successfully.

Perhaps you should tell us a bit more about your setup.

grim

Reply With Quote
  #8  
Old June 3rd, 2004, 12:25 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 3 m 4 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Get rid of the .pyc file, Python wont (shouldn't) compile another version as long as the last modifide date for the .py file matches the .pyc file. So this will result in Python barfing since the bytecode isnt compatable. Thats the theory anyway

Good luck,

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #9  
Old June 3rd, 2004, 06:12 PM
DevHims DevHims is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 27 DevHims User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks all.

Now i trying with python 2.3.4. Let us see. I tried all possible ways and ways which you guys told. I guess i have to dig further in. I hope it work.

Still, welcome for input. I am trying.

DevHims

Reply With Quote
  #10  
Old June 4th, 2004, 04:37 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
DevHims,
If after doing all I suggest it still does not work then either my suggestions are not clear or you have a problem that is nothing to do with python.

You should not need to make any modifications to a standard install of Python to do such a basic thing as import a .py file.

If after installing the latest Python you still have a problem perhaps you should describe your equipment setup, the OS (Windows or Linux version), the directory structure of the relevant files - where is the filelib.py file where is python.

Why not post the files here or email them to me if you prefer.


Netytan,

If all you have is the pyc file from Python 2.1 then Python 2.2/2.3 will complain about the wrong magic bit as you say.

If the .py file is found in the same directory then the later version of Python will silently replace the .pyc file regardless of its date stamp.

grim

Reply With Quote
  #11  
Old June 4th, 2004, 08:42 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 3 m 4 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
A new pyc file is created when the original python file has been changed (i believe a timestamp is used to do this), and since both have the same timestamp python should simply use the pyc file. Or at least this is what happens in most situations

Mark.

Reply With Quote
  #12  
Old June 4th, 2004, 08:58 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
python 2.3 cannot use a python 2.1 or 2.2 pyc file - regardless of the timestamp. The bytecode is wrong.

You can try this yourself on a system with more than one version of python installed:

import a file using a python 2.2 console
exit the console and rename the .py file.

import the same file using a python 2.3 console (it will attempt to read in the pyc file)- it won't.

if you don't rename the file then it will work because the pyc file is re-generated.

Last edited by Grim Archon : June 4th, 2004 at 09:05 AM.

Reply With Quote
  #13  
Old June 4th, 2004, 09:01 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 3 m 4 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
LOL i know that, all i'm saying is that Python shouldnt recreate the pyc file - and an error should occure . Just get rid of the pyc file and let Python make a new one just to be sure.

Mark.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > how to add User defined Module? so, i can use that in other python script.


Thread Tools  Search this Thread