Page 1 of 1

[Python] module

Posted: 08.07.2014 5:26
by Roni2
Hi,

I dont know why, but i cant import a library that is in the same directory of my script.
Example:

my script is in StealthDir\Script
and the library is located in the same directory.

StealthDir\Script\testLib.py
StealthDir\Script\test.py

test.py:
import testLib

The Error:
ImportError: No module named testLib

I know it work, because a friend mine runs the same instruction and worked fine, seems to be a configuration problem on my pc.

anyone got this problem?

thanks

Re: [Python] module

Posted: 08.07.2014 19:25
by Vizit0r
i can't help - i dont use Py.

Python user invited in thread :)

Re: [Python] module

Posted: 09.07.2014 9:30
by Boydon
This is strange, maybe it is related to Python version.
With Python 3.x the import logic has been changed, try with

Code: Select all

import .testLib.py #notice the dot before

Re: [Python] module

Posted: 09.07.2014 20:14
by Roni2
I`m using version 2.7.8.
Using windows 8.1 64bit, can be a problem too

Re: [Python] module

Posted: 10.07.2014 1:48
by Boydon
Then, long story short, you can (one of the following):
  • add StealthDir\Script to your PYTHONPATH (search google on how to)
  • add the following snippet at the very beginning of your test.py (before importing testLib)

    Code: Select all

    import os
    import sys
    sys.path.append(os.path.dirname(__file__))
    
    import testLib #after you modified system.path
    

Re: [Python] module

Posted: 11.07.2014 13:18
by Roni2
The pythonpath tip worked fine...
Thanks a lot