|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 ![]() |
|
#2
|
||||
|
||||
|
Quote:
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
__________________
IE QUOTE | PHP Manual | Google | C/C++ Compiler | Linux Tutorials | General Stuff Game Dev |
|
#3
|
||||
|
||||
|
Is the module in the same directory as your other script?
Does python filelib.py work? Quote:
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 *** |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
||||
|
||||
|
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 ![]() |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
||||
|
||||
|
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 |
|
#8
|
||||
|
||||
|
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. |
|
#9
|
|||
|
|||
|
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 ![]() |
|
#10
|
||||
|
||||
|
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 ![]() |
|
#11
|
||||
|
||||
|
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. |
|
#12
|
||||
|
||||
|
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. |
|
#13
|
||||
|
||||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > how to add User defined Module? so, i can use that in other python script. |
| Thread Tools | Search this Thread |